fix(core): update

This commit is contained in:
2019-04-28 12:42:08 +02:00
parent 2f528d1812
commit 8157f2a56b
7 changed files with 231 additions and 102 deletions

View File

@ -6,4 +6,8 @@ export type IServerCallActions = 'subscribe' | 'sendmessage' | 'unsubscribe';
export interface IServerCallSubscribeActionPayload {
name: string;
passphrase: string;
}
}
export interface IServerUnsubscribeActionPayload {
name: string;
}

View File

@ -8,6 +8,9 @@ import * as url from 'url';
import * as interfaces from './interfaces';
import { ClientUniverseChannel, UniverseMessage } from './';
import {
ClientUniverseCache
} from './smartuniverse.classes.clientuniversecache';
export interface IClientOptions {
serverAddress: string;
@ -22,7 +25,8 @@ export class ClientUniverse {
public smartsocketClient: plugins.smartsocket.SmartsocketClient;
public observableIntake: plugins.smartrx.ObservableIntake<UniverseMessage>;
public channelCache = new Objectmap<ClientUniverseChannel>();
public channelStore = new Objectmap<ClientUniverseChannel>();
public clientUniverseCache = new ClientUniverseCache();
constructor(optionsArg: IClientOptions) {
this.options = optionsArg;
@ -50,12 +54,27 @@ export class ClientUniverse {
*/
public async getChannel(channelName: string): Promise<ClientUniverseChannel> {
await this.checkConnection();
const clientUniverseChannel = this.channelCache.find(channel => {
const clientUniverseChannel = this.channelStore.find(channel => {
return channel.name === channelName;
});
return clientUniverseChannel;
}
/**
* remove a a achannel
* @param messageArg
*/
public removeChannel(channelNameArg, notifyServer = true) {
const clientUniverseChannel = this.channelStore.findOneAndRemove(channelItemArg => {
return channelItemArg.name === channelNameArg;
});
}
/**
* sends a message towards the server
* @param messageArg
*/
public async sendMessage(messageArg: interfaces.IMessageCreator) {
await this.checkConnection();
const requestBody: interfaces.IUniverseMessage = {
@ -103,7 +122,9 @@ export class ClientUniverse {
const unsubscribe = new plugins.smartsocket.SocketFunction({
funcName: 'unsubscribe',
allowedRoles: [],
funcDef: async () => {},
funcDef: async (data: interfaces.IServerUnsubscribeActionPayload) => {
},
});
/**

View File

@ -0,0 +1,8 @@
import * as plugins from './smartuniverse.plugins';
/**
* a cache for clients
*/
export class ClientUniverseCache {
}

View File

@ -23,7 +23,7 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel {
channelNameArg,
passphraseArg
);
clientUniverseArg.channelCache.add(clientChannel);
clientUniverseArg.channelStore.add(clientChannel);
await clientChannel.subscribe();
return clientChannel;
}