Compare commits

...

8 Commits

Author SHA1 Message Date
9c1504ef02 1.0.64 2019-08-13 18:43:33 +02:00
e8f2e04d1c fix(core): update 2019-08-13 18:43:33 +02:00
e12aa7e961 1.0.63 2019-08-13 18:41:28 +02:00
857b7cd010 fix(core): update 2019-08-13 18:41:27 +02:00
e100dea160 1.0.62 2019-08-13 18:16:17 +02:00
e8e87fcdba fix(core): update 2019-08-13 18:16:16 +02:00
0d18b11721 1.0.61 2019-08-13 18:06:14 +02:00
eaaefddbe3 fix(core): update 2019-08-13 18:06:13 +02:00
8 changed files with 27 additions and 18 deletions

2
package-lock.json generated
View File

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

View File

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

View File

@ -37,11 +37,11 @@ tap.test('create smartuniverse client', async () => {
});
tap.test('should add a channel to the universe', async () => {
await testUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
testUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
});
tap.test('should add the same channel to the client universe in the same way', async () => {
await testClientUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
testClientUniverse.addChannel(testChannelData.channelName, testChannelData.channelPass);
});
tap.test('should start the ClientUniverse', async () => {
@ -49,12 +49,12 @@ tap.test('should start the ClientUniverse', async () => {
})
tap.test('should get a observable correctly', async () => {
testClientChannel = await testClientUniverse.getChannel(testChannelData.channelName);
testClientChannel = testClientUniverse.getChannel(testChannelData.channelName);
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
});
tap.test('should send a message correctly', async () => {
await (await testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({
await (testClientUniverse.getChannel(testChannelData.channelName)).sendMessage({
messageText: 'hello'
});
});

View File

@ -1,6 +1,7 @@
// Client classes
export * from './smartuniverse.classes.clientuniverse';
export * from './smartuniverse.classes.clientuniversechannel';
export * from './smartuniverse.classes.clientuniversemessage';
// Server classes
export * from './smartuniverse.classes.universe';

View File

@ -7,7 +7,7 @@ import * as url from 'url';
import * as interfaces from './interfaces';
import { ClientUniverseChannel, UniverseMessage } from './';
import { ClientUniverseChannel, ClientUniverseMessage } from './';
import { ClientUniverseCache } from './smartuniverse.classes.clientuniversecache';
export interface IClientOptions {
@ -21,7 +21,7 @@ export interface IClientOptions {
export class ClientUniverse {
public options;
public smartsocketClient: plugins.smartsocket.SmartsocketClient;
public observableIntake: plugins.smartrx.ObservableIntake<UniverseMessage>;
public observableIntake: plugins.smartrx.ObservableIntake<ClientUniverseMessage>;
public clientUniverseCache = new ClientUniverseCache();
constructor(optionsArg: IClientOptions) {
@ -32,15 +32,16 @@ export class ClientUniverse {
* 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 = await this.getChannel(channelNameArg);
public addChannel(channelNameArg: string, passphraseArg: string) {
const existingChannel = this.getChannel(channelNameArg);
if (existingChannel) {
throw new Error('channel exists');
}
// lets create the channel
await ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
const clientUniverseChannel = ClientUniverseChannel.createClientUniverseChannel(this, channelNameArg, passphraseArg);
return clientUniverseChannel;
}
/**
@ -48,7 +49,7 @@ export class ClientUniverse {
* @param channelName
* @param passphraseArg
*/
public async getChannel(channelName: string): Promise<ClientUniverseChannel> {
public getChannel(channelName: string): ClientUniverseChannel {
const clientUniverseChannel = this.clientUniverseCache.channelMap.find(channel => {
return channel.name === channelName;
});
@ -109,8 +110,9 @@ export class ClientUniverse {
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction({
funcName: 'processMessage',
allowedRoles: [],
funcDef: async (data: interfaces.IServerUnsubscribeActionPayload) => {
funcDef: async (messageDescriptorArg: interfaces.IUniverseMessage) => {
plugins.smartlog.defaultLogger.log('info', 'Got message from server');
this.observableIntake.push(ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg));
}
});

View File

@ -13,11 +13,11 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
* @param channelNameArg
* @param passphraseArg
*/
public static async createClientUniverseChannel(
public static createClientUniverseChannel(
clientUniverseArg: ClientUniverse,
channelNameArg: string,
passphraseArg: string
): Promise<ClientUniverseChannel> {
): ClientUniverseChannel {
const clientChannel = new ClientUniverseChannel(
clientUniverseArg,
channelNameArg,

View File

@ -6,7 +6,10 @@ export class ClientUniverseMessage implements interfaces.IUniverseMessage {
// ======
// STATIC
// ======
public static createMessageFromPayload(messageDescriptor: interfaces.IUniverseMessage) {}
public static createMessageFromMessageDescriptor(messageDescriptor: interfaces.IUniverseMessage) {
const clientuniverseMessage = new ClientUniverseMessage(messageDescriptor);
return clientuniverseMessage;
}
// ========
// INSTANCE
@ -23,11 +26,14 @@ export class ClientUniverseMessage implements interfaces.IUniverseMessage {
public payloadStringType;
public targetChannelName: string;
constructor(messageArg: interfaces.IUniverseMessage, payloadArg) {
constructor(messageArg: interfaces.IUniverseMessage) {
for (const key of Object.keys(messageArg)) {
this[key] = messageArg[key];
}
}
/**
* gets json for payload
*/
getAsJsonForPayload() {}
}

View File

@ -59,7 +59,7 @@ export class Universe {
/**
* adds a channel to the Universe
*/
public async addChannel(nameArg: string, passphraseArg: string) {
public addChannel(nameArg: string, passphraseArg: string) {
const newChannel = UniverseChannel.createChannel(this, nameArg, passphraseArg);
}