diff --git a/ts/interfaces/socketfunctionrequests.ts b/ts/interfaces/socketfunctionrequests.ts index ece7bc2..86963a6 100644 --- a/ts/interfaces/socketfunctionrequests.ts +++ b/ts/interfaces/socketfunctionrequests.ts @@ -15,6 +15,6 @@ export interface ISocketRequest_ProcessMessage { method: 'processMessage'; request: interfaces.IUniverseMessage; response: { - messageStatus: 'ok' + messageStatus: 'ok' | 'channel not found' }; } \ No newline at end of file diff --git a/ts/smartuniverse.classes.clientuniverse.ts b/ts/smartuniverse.classes.clientuniverse.ts index 3c414ab..38f2d3d 100644 --- a/ts/smartuniverse.classes.clientuniverse.ts +++ b/ts/smartuniverse.classes.clientuniverse.ts @@ -113,17 +113,30 @@ export class ClientUniverse { /** * handles message reception */ - const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction({ + const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction< + interfaces.ISocketRequest_ProcessMessage + >({ funcName: 'processMessage', allowedRoles: [], - funcDef: async (messageDescriptorArg) => { + funcDef: async messageDescriptorArg => { plugins.smartlog.defaultLogger.log('info', 'Got message from server'); - this.observableIntake.push( - ClientUniverseMessage.createMessageFromMessageDescriptor(messageDescriptorArg) + const clientUniverseMessage = ClientUniverseMessage.createMessageFromMessageDescriptor( + messageDescriptorArg ); - return { - messageStatus: 'ok' - }; + this.observableIntake.push(clientUniverseMessage); + + // lets find the corresponding channel + const targetChannel = this.getChannel(clientUniverseMessage.targetChannelName); + if (targetChannel) { + await targetChannel.emitMessageLocally(clientUniverseMessage); + return { + messageStatus: 'ok' + }; + } else { + return { + messageStatus: 'channel not found' + }; + } } }); diff --git a/ts/smartuniverse.classes.clientuniversechannel.ts b/ts/smartuniverse.classes.clientuniversechannel.ts index ee3fd10..b788c15 100644 --- a/ts/smartuniverse.classes.clientuniversechannel.ts +++ b/ts/smartuniverse.classes.clientuniversechannel.ts @@ -2,6 +2,7 @@ import * as plugins from './smartuniverse.plugins'; import * as interfaces from './interfaces'; import { ClientUniverse } from './'; +import { ClientUniverseMessage } from './smartuniverse.classes.clientuniversemessage'; export class ClientUniverseChannel implements interfaces.IUniverseChannel { // ====== @@ -35,6 +36,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel { public name: string; public passphrase: string; public status: 'subscribed' | 'unsubscribed' = 'unsubscribed'; + private subject = new plugins.smartrx.rxjs.Subject(); // refs public clientUniverseRef: ClientUniverse; @@ -49,7 +51,8 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel { * subscribes to a channel * tells the universe about this instances interest into a channel */ - public async subscribe() { + public async subscribe(observerArg?: plugins.smartrx.rxjs.Observer) { + // lets make sure the channel is connected if (this.status === 'unsubscribed') { const response = await this.clientUniverseRef.smartsocketClient.serverCall( 'subscribeChannel', @@ -60,6 +63,15 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel { ); this.status = response.subscriptionStatus; } + + if (observerArg) { + return this.subject.subscribe(observerArg); + } + + } + + public async emitMessageLocally(messageArg: ClientUniverseMessage) { + } /** diff --git a/ts/smartuniverse.classes.reactionrequest.ts b/ts/smartuniverse.classes.reactionrequest.ts index 273776b..b45823a 100644 --- a/ts/smartuniverse.classes.reactionrequest.ts +++ b/ts/smartuniverse.classes.reactionrequest.ts @@ -1,3 +1,5 @@ import * as plugins from './smartuniverse.plugins'; -export class ReactionRequest {} \ No newline at end of file +export class ReactionRequest { + +}