@@ -8,10 +8,12 @@ import { IConnection, CloudMessage } from '../connection/IConnection';
88import { ICloudClient , CloudOptions , OnMessageCallback , CloudMessageValue } from './ICloudClient' ;
99
1010const NOOP = ( ) => null ;
11+ type PropertyCallbacks = { cb : OnMessageCallback < any > [ ] ; propertyName : string ; thingId } ;
1112export class CloudClient implements ICloudClient {
1213 private connection : IConnection ;
1314 private subscriptions : { [ key : string ] : Subscription [ ] } = { } ;
1415 private callbacks : { [ key : string ] : OnMessageCallback < any > [ ] } = { } ;
16+ private propertyCallbacks : { [ key : string ] : PropertyCallbacks } = { } ;
1517
1618 private options : CloudOptions = {
1719 ssl : false ,
@@ -71,6 +73,7 @@ export class CloudClient implements ICloudClient {
7173 Object . values ( this . subscriptions ) . forEach ( ( subs , topic ) => {
7274 subs . forEach ( ( sub ) => sub . unsubscribe ( ) ) ;
7375 delete this . callbacks [ topic ] ;
76+ delete this . propertyCallbacks [ topic ] ;
7477 delete this . subscriptions [ topic ] ;
7578 } ) ;
7679
@@ -97,8 +100,12 @@ export class CloudClient implements ICloudClient {
97100 delete this . subscriptions [ topic ] ;
98101
99102 const callbacks = [ ...this . callbacks [ topic ] ] ;
103+ const { thingId, propertyName, ...others } = this . propertyCallbacks [ topic ] || { cb : [ ] } ;
104+ const propertiesCallbacks = [ ...others . cb ] ;
100105 delete this . callbacks [ topic ] ;
106+ delete this . propertyCallbacks [ topic ] ;
101107 callbacks . forEach ( ( cb ) => this . subscribe ( topic , cb ) ) ;
108+ propertiesCallbacks . forEach ( ( cb ) => this . onPropertyValue ( thingId , propertyName , cb ) ) ;
102109 } ) ;
103110
104111 const { onConnected = NOOP } = this . options ;
@@ -166,10 +173,10 @@ export class CloudClient implements ICloudClient {
166173
167174 const topic = `/a/t/${ thingId } /e/o` ;
168175
169- this . callbacks [ topic ] = this . callbacks [ topic ] = [ ] ;
176+ this . propertyCallbacks [ topic ] = this . propertyCallbacks [ topic ] = { thingId , propertyName : name , cb : [ ] } ;
170177 this . subscriptions [ topic ] = this . subscriptions [ topic ] = [ ] ;
171178
172- this . callbacks [ topic ] . push ( cb ) ;
179+ this . propertyCallbacks [ topic ] . cb . push ( cb ) ;
173180 this . subscriptions [ topic ] . push (
174181 this . messagesFrom ( topic )
175182 . pipe ( filter ( ( v ) => v . propertyName === name ) )
0 commit comments