fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-10 01:19:10 +02:00
parent f3e13292d8
commit 64c4b91678
4 changed files with 37 additions and 10 deletions

View File

@ -15,6 +15,6 @@ export interface ISocketRequest_ProcessMessage {
method: 'processMessage';
request: interfaces.IUniverseMessage;
response: {
messageStatus: 'ok'
messageStatus: 'ok' | 'channel not found'
};
}

View File

@ -113,17 +113,30 @@ export class ClientUniverse {
/**
* handles message reception
*/
const socketFunctionProcessMessage = new plugins.smartsocket.SocketFunction<interfaces.ISocketRequest_ProcessMessage>({
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'
};
}
}
});

View File

@ -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<any>) {
// lets make sure the channel is connected
if (this.status === 'unsubscribed') {
const response = await this.clientUniverseRef.smartsocketClient.serverCall<interfaces.ISocketRequest_SubscribeChannel>(
'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) {
}
/**

View File

@ -1,3 +1,5 @@
import * as plugins from './smartuniverse.plugins';
export class ReactionRequest {}
export class ReactionRequest {
}