From be38e91548cf9feb90213707512cccdb40b32155 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Thu, 28 Jan 2021 01:31:42 +0000 Subject: [PATCH] fix(core): update --- package.json | 2 +- test/test.ts | 12 +++++++----- ts/interfaces/tag.ts | 4 ++-- ts/smartsocket.classes.smartsocketclient.ts | 13 ++++++++----- ts/smartsocket.classes.socketconnection.ts | 8 ++++---- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 725e303..2538757 100644 --- a/package.json +++ b/package.json @@ -61,4 +61,4 @@ "browserslist": [ "last 1 chrome versions" ] -} +} \ No newline at end of file diff --git a/test/test.ts b/test/test.ts index 87579ec..bc00e91 100644 --- a/test/test.ts +++ b/test/test.ts @@ -93,13 +93,15 @@ tap.test('should react to a new websocket connection from client', async () => { tap.test('should be able to tag a connection', async (tools) => { await testSmartsocketClient.addTag({ id: 'awesome', - payload: 'yes' + payload: 'yes', }); - const tagOnServerSide = await testSmartsocket.socketConnections.find((socketConnection) => { - return true; - }).getTagById('awesome'); + const tagOnServerSide = await testSmartsocket.socketConnections + .find((socketConnection) => { + return true; + }) + .getTagById('awesome'); expect(tagOnServerSide.payload).to.equal('yes'); -}) +}); tap.test('2 clients should connect in parallel', async () => { // TODO: implement parallel test diff --git a/ts/interfaces/tag.ts b/ts/interfaces/tag.ts index ccde7c3..63bf4e0 100644 --- a/ts/interfaces/tag.ts +++ b/ts/interfaces/tag.ts @@ -1,6 +1,6 @@ -export interface ITag { +export interface ITag { id: string; payload: T; } -export type TTagStore = {[key: string]: ITag}; \ No newline at end of file +export type TTagStore = { [key: string]: ITag }; diff --git a/ts/smartsocket.classes.smartsocketclient.ts b/ts/smartsocket.classes.smartsocketclient.ts index 6346503..31f65af 100644 --- a/ts/smartsocket.classes.smartsocketclient.ts +++ b/ts/smartsocket.classes.smartsocketclient.ts @@ -46,7 +46,7 @@ export class SmartsocketClient { public socketRoles = new plugins.lik.ObjectMap(); // tagStore - private tagStore: {[key: string]: interfaces.ITag} = {}; + private tagStore: { [key: string]: interfaces.ITag } = {}; private tagStoreSubscription: plugins.smartrx.rxjs.Subscription; /** @@ -66,7 +66,7 @@ export class SmartsocketClient { */ public async getTagById(tagIdArg: interfaces.ITag['id']) { return this.tagStore[tagIdArg]; - }; + } /** * removes a tag from a connection @@ -164,12 +164,15 @@ export class SmartsocketClient { // handle connection this.socketConnection.socket.on('connect', async () => { this.tagStoreSubscription?.unsubscribe(); - this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe(tagStoreArg => { - this.tagStore = tagStoreArg - }); for (const keyArg of Object.keys(this.tagStore)) { this.socketConnection.addTag(this.tagStore[keyArg]); } + this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe( + (tagStoreArg) => { + this.tagStore = tagStoreArg; + } + ); + this.updateStatus('connected'); }); diff --git a/ts/smartsocket.classes.socketconnection.ts b/ts/smartsocket.classes.socketconnection.ts index deb7040..aa35a93 100644 --- a/ts/smartsocket.classes.socketconnection.ts +++ b/ts/smartsocket.classes.socketconnection.ts @@ -95,12 +95,12 @@ export class SocketConnection { this.tagStoreObservable.next(this.tagStore); const remoteSubscription = this.remoteTagStoreObservable.subscribe((remoteTagStore) => { const localTagString = plugins.smartjson.stringify(tagArg); - const remoteTagString = plugins.smartjson.stringify(remoteTagStore[tagArg.id]) + const remoteTagString = plugins.smartjson.stringify(remoteTagStore[tagArg.id]); if (localTagString === remoteTagString) { remoteSubscription.unsubscribe(); done.resolve(); } - }) + }); this.socket.emit('updateTagStore', this.tagStore); await done.promise; } @@ -111,7 +111,7 @@ export class SocketConnection { */ public async getTagById(tagIdArg: interfaces.ITag['id']) { return this.tagStore[tagIdArg]; - }; + } /** * removes a tag from a connection @@ -202,7 +202,7 @@ export class SocketConnection { this.tagStoreObservable.next(this.tagStore); } this.remoteTagStoreObservable.next(tagStoreArg); - }) + }); logger.log('info', `now listening to function requests for ${this.alias}`); done.resolve(this);