fix(core): update
This commit is contained in:
		
							
								
								
									
										10
									
								
								test/test.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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) => { | tap.test('should be able to tag a connection', async (tools) => { | ||||||
|   await testSmartsocketClient.addTag({ |   await testSmartsocketClient.addTag({ | ||||||
|     id: 'awesome', |     id: 'awesome', | ||||||
|     payload: 'yes' |     payload: 'yes', | ||||||
|   }); |   }); | ||||||
|   const tagOnServerSide = await testSmartsocket.socketConnections.find((socketConnection) => { |   const tagOnServerSide = await testSmartsocket.socketConnections | ||||||
|  |     .find((socketConnection) => { | ||||||
|       return true; |       return true; | ||||||
|   }).getTagById('awesome'); |     }) | ||||||
|  |     .getTagById('awesome'); | ||||||
|   expect(tagOnServerSide.payload).to.equal('yes'); |   expect(tagOnServerSide.payload).to.equal('yes'); | ||||||
| }) | }); | ||||||
|  |  | ||||||
| tap.test('2 clients should connect in parallel', async () => { | tap.test('2 clients should connect in parallel', async () => { | ||||||
|   // TODO: implement parallel test |   // TODO: implement parallel test | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| export interface ITag <T = any> { | export interface ITag<T = any> { | ||||||
|   id: string; |   id: string; | ||||||
|   payload: T; |   payload: T; | ||||||
| } | } | ||||||
|  |  | ||||||
| export type TTagStore = {[key: string]: ITag}; | export type TTagStore = { [key: string]: ITag }; | ||||||
|   | |||||||
| @@ -46,7 +46,7 @@ export class SmartsocketClient { | |||||||
|   public socketRoles = new plugins.lik.ObjectMap<SocketRole>(); |   public socketRoles = new plugins.lik.ObjectMap<SocketRole>(); | ||||||
|  |  | ||||||
|   // tagStore |   // tagStore | ||||||
|   private tagStore: {[key: string]: interfaces.ITag} = {}; |   private tagStore: { [key: string]: interfaces.ITag } = {}; | ||||||
|   private tagStoreSubscription: plugins.smartrx.rxjs.Subscription; |   private tagStoreSubscription: plugins.smartrx.rxjs.Subscription; | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -66,7 +66,7 @@ export class SmartsocketClient { | |||||||
|    */ |    */ | ||||||
|   public async getTagById(tagIdArg: interfaces.ITag['id']) { |   public async getTagById(tagIdArg: interfaces.ITag['id']) { | ||||||
|     return this.tagStore[tagIdArg]; |     return this.tagStore[tagIdArg]; | ||||||
|   }; |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * removes a tag from a connection |    * removes a tag from a connection | ||||||
| @@ -164,12 +164,15 @@ export class SmartsocketClient { | |||||||
|     // handle connection |     // handle connection | ||||||
|     this.socketConnection.socket.on('connect', async () => { |     this.socketConnection.socket.on('connect', async () => { | ||||||
|       this.tagStoreSubscription?.unsubscribe(); |       this.tagStoreSubscription?.unsubscribe(); | ||||||
|       this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe(tagStoreArg => { |  | ||||||
|         this.tagStore = tagStoreArg |  | ||||||
|       }); |  | ||||||
|       for (const keyArg of Object.keys(this.tagStore)) { |       for (const keyArg of Object.keys(this.tagStore)) { | ||||||
|         this.socketConnection.addTag(this.tagStore[keyArg]); |         this.socketConnection.addTag(this.tagStore[keyArg]); | ||||||
|       } |       } | ||||||
|  |       this.tagStoreSubscription = this.socketConnection.tagStoreObservable.subscribe( | ||||||
|  |         (tagStoreArg) => { | ||||||
|  |           this.tagStore = tagStoreArg; | ||||||
|  |         } | ||||||
|  |       ); | ||||||
|  |        | ||||||
|       this.updateStatus('connected'); |       this.updateStatus('connected'); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -95,12 +95,12 @@ export class SocketConnection { | |||||||
|     this.tagStoreObservable.next(this.tagStore); |     this.tagStoreObservable.next(this.tagStore); | ||||||
|     const remoteSubscription = this.remoteTagStoreObservable.subscribe((remoteTagStore) => { |     const remoteSubscription = this.remoteTagStoreObservable.subscribe((remoteTagStore) => { | ||||||
|       const localTagString = plugins.smartjson.stringify(tagArg); |       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) { |       if (localTagString === remoteTagString) { | ||||||
|         remoteSubscription.unsubscribe(); |         remoteSubscription.unsubscribe(); | ||||||
|         done.resolve(); |         done.resolve(); | ||||||
|       } |       } | ||||||
|     }) |     }); | ||||||
|     this.socket.emit('updateTagStore', this.tagStore); |     this.socket.emit('updateTagStore', this.tagStore); | ||||||
|     await done.promise; |     await done.promise; | ||||||
|   } |   } | ||||||
| @@ -111,7 +111,7 @@ export class SocketConnection { | |||||||
|    */ |    */ | ||||||
|   public async getTagById(tagIdArg: interfaces.ITag['id']) { |   public async getTagById(tagIdArg: interfaces.ITag['id']) { | ||||||
|     return this.tagStore[tagIdArg]; |     return this.tagStore[tagIdArg]; | ||||||
|   }; |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * removes a tag from a connection |    * removes a tag from a connection | ||||||
| @@ -202,7 +202,7 @@ export class SocketConnection { | |||||||
|           this.tagStoreObservable.next(this.tagStore); |           this.tagStoreObservable.next(this.tagStore); | ||||||
|         } |         } | ||||||
|         this.remoteTagStoreObservable.next(tagStoreArg); |         this.remoteTagStoreObservable.next(tagStoreArg); | ||||||
|       }) |       }); | ||||||
|  |  | ||||||
|       logger.log('info', `now listening to function requests for ${this.alias}`); |       logger.log('info', `now listening to function requests for ${this.alias}`); | ||||||
|       done.resolve(this); |       done.resolve(this); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user