diff --git a/ts/interfaces/index.ts b/ts/interfaces/index.ts index 345ff0d..ff388d2 100644 --- a/ts/interfaces/index.ts +++ b/ts/interfaces/index.ts @@ -1,3 +1,4 @@ export * from './http.interfaces'; export * from './universechannel.interfaces'; export * from './universemessage.interfaces'; +export * from './universeactions.interfaces'; diff --git a/ts/interfaces/universeactions.interfaces.ts b/ts/interfaces/universeactions.interfaces.ts new file mode 100644 index 0000000..df5226f --- /dev/null +++ b/ts/interfaces/universeactions.interfaces.ts @@ -0,0 +1,9 @@ +export type IServerCallActions = 'subscribe' | 'sendmessage' | 'unsubscribe'; + +/** + * the interface for a subscription + */ +export interface IServerCallSubscribeActionPayload { + name: string; + passphrase: string; +} \ No newline at end of file diff --git a/ts/smartuniverse.classes.clientuniverse.ts b/ts/smartuniverse.classes.clientuniverse.ts index cb83354..1c4d6f6 100644 --- a/ts/smartuniverse.classes.clientuniverse.ts +++ b/ts/smartuniverse.classes.clientuniverse.ts @@ -19,7 +19,7 @@ export interface IClientOptions { */ export class ClientUniverse { public options; - public socketClient: plugins.smartsocket.SmartsocketClient; + public smartsocketClient: plugins.smartsocket.SmartsocketClient; public observableIntake: plugins.smartrx.ObservableIntake; public channelCache = new Objectmap(); @@ -74,7 +74,7 @@ export class ClientUniverse { } public close() { - this.socketClient.disconnect(); + this.smartsocketClient.disconnect(); } /** @@ -82,7 +82,7 @@ export class ClientUniverse { * since password validation is done through other means, a connection should always be possible */ private async checkConnection(): Promise { - if (!this.socketClient && !this.observableIntake) { + if (!this.smartsocketClient && !this.observableIntake) { const parsedURL = url.parse(this.options.serverAddress); const socketConfig: plugins.smartsocket.ISmartsocketClientOptions = { alias: process.env.SOCKET_ALIAS || 'someclient', @@ -92,9 +92,30 @@ export class ClientUniverse { url: parsedURL.protocol + '//' + parsedURL.hostname }; console.log(socketConfig); - this.socketClient = new SmartsocketClient(socketConfig); + this.smartsocketClient = new SmartsocketClient(socketConfig); this.observableIntake = new plugins.smartrx.ObservableIntake(); - await this.socketClient.connect(); + + // lets define some basic actions + + /** + * should handle a forced unsubscription by the server + */ + const unsubscribe = new plugins.smartsocket.SocketFunction({ + funcName: 'unsubscribe', + allowedRoles: [], + funcDef: async () => {}, + }); + + /** + * should handle a message reception + */ + const receiveMessage = async () => { + + }; + + + + await this.smartsocketClient.connect(); } } } diff --git a/ts/smartuniverse.classes.clientuniversechannel.ts b/ts/smartuniverse.classes.clientuniversechannel.ts index 3e136af..5bebae7 100644 --- a/ts/smartuniverse.classes.clientuniversechannel.ts +++ b/ts/smartuniverse.classes.clientuniversechannel.ts @@ -50,6 +50,11 @@ export class ClientUniverseChannel implements interfaces.IUniverseChannel { * tells the universe about this instances interest into a channel */ public async subscribe() { - this.clientUniverse.socketClient; + const serverCallActionName: interfaces.IServerCallActions = 'subscribe'; + const serverCallActionPayload: interfaces.IServerCallSubscribeActionPayload = { + name: this.name, + passphrase: this.passphrase + }; + this.clientUniverse.smartsocketClient.serverCall(serverCallActionName, serverCallActionPayload); } } diff --git a/ts/smartuniverse.classes.clientuniversemessage.ts b/ts/smartuniverse.classes.clientuniversemessage.ts index 110cc12..f8916f6 100644 --- a/ts/smartuniverse.classes.clientuniversemessage.ts +++ b/ts/smartuniverse.classes.clientuniversemessage.ts @@ -1,6 +1,7 @@ import * as plugins from './smartuniverse.plugins'; import * as interfaces from './interfaces'; +import { IUniverseMessage } from './interfaces'; export class ClientUniverseMessage implements interfaces.IUniverseMessage { // ====== @@ -12,17 +13,22 @@ export class ClientUniverseMessage implements interfaces.IUniverseMessage { // INSTANCE // ======== + // properties public id: string; public timestamp: number; public smartTimestamp: plugins.smarttime.TimeStamp; - public messageText: string; public passphrase: string; public payload: any; public payloadStringType; public targetChannelName: string; - constructor(messageArg, payloadArg) {} - getAsJsonForPayload() {} + constructor(messageArg: IUniverseMessage, payloadArg) { + for (const key of Object.keys(messageArg)) { + this[key] = messageArg[key]; + } + } + + getAsJsonForPayload() {}; }