Compare commits

...

4 Commits

Author SHA1 Message Date
241182ed2e 1.0.40 2019-04-22 22:04:53 +02:00
3d82038ec3 fix(core): update 2019-04-22 22:04:52 +02:00
300d62ed12 1.0.39 2019-04-22 13:06:02 +02:00
a5e849aa17 fix(core): update 2019-04-22 13:06:01 +02:00
6 changed files with 57 additions and 25 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.38",
"version": "1.0.40",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.38",
"version": "1.0.40",
"private": false,
"description": "messaging service for your micro services",
"main": "dist/index.js",

View File

@ -11,7 +11,7 @@ let testClientChannel: smartuniverse.ClientUniverseChannel;
const testChannelData = {
channelName: 'awesomeTestChannel',
channelPass: 'awesomeChannelPAss'
}
};
tap.test('first test', async () => {
testUniverse = new smartuniverse.Universe({
@ -43,9 +43,7 @@ tap.test('should get a observable correctly', async () => {
tap.test('should send a message correctly', async () => {
await testUniverseClient.sendMessage({
messageText: 'hello',
passphrase: 'wowza',
targetChannelName: 'channel1',
targetChannelName: 'channel1'
});
});

View File

@ -31,11 +31,43 @@ export class ClientUniverse {
this.options = optionsArg;
}
/**
* adds a channel to the channelcache
* TODO: verify channel before adding it to the channel cache
*/
public async addChannel (channelNameArg: string, passphraseArg: string) {
const existingChannel = this.getChannel(channelNameArg);
if (existingChannel) {
throw new Error('channel exists');
}
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
this,
channelNameArg,
passphraseArg
);
this.channelCache.add(clientUniverseChannel);
}
/**
* gets a channel from the channelcache
* @param channelName
* @param passphraseArg
*/
public async getChannel(channelName: string): Promise<ClientUniverseChannel> {
await this.checkConnection();
const clientUniverseChannel = this.channelCache.find(channel => {
return channel.name === channelName;
})
return clientUniverseChannel;
}
public async sendMessage(messageArg: interfaces.IMessageCreator) {
const requestBody: interfaces.IUniverseMessage = {
id: plugins.smartunique.shortId(),
timestamp: Date.now(),
passphrase: (await this.getChannel(messageArg.targetChannelName)).,
passphrase: (await this.getChannel(messageArg.targetChannelName)).passphrase,
...messageArg,
};
@ -46,21 +78,15 @@ export class ClientUniverse {
});
}
public async getChannel(channelName: string, passphraseArg?: string): Promise<ClientUniverseChannel> {
await this.checkConnection();
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
this,
channelName
);
this.channelCache.add(clientUniverseChannel);
return clientUniverseChannel;
}
public close() {
this.socketClient.disconnect();
}
private async checkConnection() {
/**
* checks the connection towards a universe server
* since password validation is done through other means, a connection should always be possible
*/
private async checkConnection(): Promise<void> {
if (!this.socketClient && !this.observableIntake) {
const parsedURL = url.parse(this.options.serverAddress);
this.socketClient = new SmartsocketClient({

View File

@ -13,7 +13,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
passphraseArg: string
): Promise<ClientUniverseChannel> {
const clientChannel = new ClientUniverseChannel(clientUniverseArg, passphraseArg);
await clientChannel.transmitSubscription();
await clientChannel.subscribe();
return clientChannel;
}
@ -21,18 +21,24 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
// INSTANCE
// ========
public clientUniverse: ClientUniverse;
// properties
public name: string;
public passphrase: string;
constructor(clientUniverseArg: ClientUniverse, passphraseArg: string) {
// refs
public clientUniverse: ClientUniverse;
constructor(clientUniverseArg: ClientUniverse, nameArg: string, passphraseArg: string) {
this.clientUniverse = clientUniverseArg;
this.passphrase = passphraseArg
this.name = nameArg;
this.passphrase = passphraseArg;
}
/**
* subscribes to a channel
* tells the universe about this instances interest into a channel
*/
public async transmitSubscription() {
public async subscribe() {
this.clientUniverse.socketClient;
}
}

View File

@ -101,7 +101,9 @@ export class Universe {
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
allowedRoles: [ClientRole],
funcName: 'channelSubscription',
funcDef: () => {} // TODO: implement an action upon connection of clients
funcDef: () => {
console.log('a client connected');
} // TODO: implement an action upon connection of clients
});
// add smartsocket to the running smartexpress app