@@ -57,12 +57,17 @@ class PeerComms extends SocketComms {
5757 try {
5858
5959 let response = null
60- const request = await this . decrypt ( { data : message } , this . remoteIdentity )
60+ let request = await this . decrypt ( { data : message } , this . remoteIdentity )
6161 debug ( 'handleHostCall' , request )
6262
6363 let inputValidated
6464
6565 if ( this . state === PeerComms . STATES . AUTHED ) {
66+
67+ if ( typeof request != 'object' ) {
68+ request = JSON . parse ( request )
69+ }
70+
6671 debug ( 'handling authed call' )
6772 inputValidated = HostProtocolScheme . ANY_OP . validate ( request )
6873 } else if ( this . state === PeerComms . STATES . AUTH_REQUIRED ) {
@@ -167,7 +172,7 @@ class PeerComms extends SocketComms {
167172 await this . socketInit ( )
168173 }
169174
170- this . socket . on ( 'close' , this . close . bind ( this ) )
175+ this . socket . on ( 'close' , this . stop . bind ( this ) )
171176
172177 if ( this . host ) {
173178 debug ( 'host mode comms' )
@@ -192,7 +197,7 @@ class PeerComms extends SocketComms {
192197 }
193198
194199 async close ( ) {
195- debug ( 'close' )
200+ debug ( 'close' , this . uuid )
196201
197202 if ( this . party . topics ) {
198203 await this . party . topics . destroyNode ( this )
@@ -211,6 +216,8 @@ class PeerComms extends SocketComms {
211216
212217 debug ( 'Here state : ' , this . state )
213218
219+ console . log ( op . input )
220+
214221 if ( op . op === 'auth' && this . state === PeerComms . STATES . AUTH_REQUIRED ) {
215222
216223 debug ( 'handling auth op' )
@@ -223,25 +230,25 @@ class PeerComms extends SocketComms {
223230 } else if ( op . op === 'advertise' && this . state === PeerComms . STATES . AUTHED ) {
224231
225232 if ( this . party . topics ) {
226- await this . party . topics . advertise ( this , op . topic )
233+ await this . party . topics . advertise ( this , op . input . topic )
227234 }
228235
229236 } else if ( op . op === 'subscribe' && this . state === PeerComms . STATES . AUTHED ) {
230237
231238 if ( this . party . topics ) {
232- await this . party . topics . subscribe ( this , op . topic )
239+ await this . party . topics . subscribe . bind ( this . party . topics ) ( this , op . input . topic )
233240 }
234241
235242 } else if ( op . op === 'unsubscribe' && this . state === PeerComms . STATES . AUTHED ) {
236243
237244 if ( this . party . topics ) {
238- await this . party . topics . unsubscribe ( this , op . topic )
245+ await this . party . topics . unsubscribe ( this , op . input . topic )
239246 }
240247
241248 } else if ( op . op === 'publish' && this . state === PeerComms . STATES . AUTHED ) {
242249
243250 if ( this . party . topics ) {
244- await this . party . topics . publish ( this , op . topic , op . msg )
251+ await this . party . topics . publish ( this , op . input . topic , op . input . msg )
245252 }
246253
247254 } else {
0 commit comments