@@ -104,6 +104,7 @@ export class Listener {
104104 this . webSocket . onerror = ( err ) => {
105105 console . log ( 'WebSocket Error ' ) ;
106106 console . log ( err ) ;
107+ reject ( err ) ;
107108 } ;
108109 this . webSocket . onmessage = ( msg ) => {
109110 const message = JSON . parse ( msg . data as string ) ;
@@ -155,6 +156,17 @@ export class Listener {
155156 } ) ;
156157 }
157158
159+ /**
160+ * returns a boolean that repressents the open state
161+ * @returns a boolean
162+ */
163+ public isOpen ( ) : boolean {
164+ if ( this . webSocket ) {
165+ return this . webSocket . readyState === WebSocket . OPEN ;
166+ }
167+ return false ;
168+ }
169+
158170 /**
159171 * Close web socket connection.
160172 * @returns void
@@ -189,7 +201,7 @@ export class Listener {
189201 share ( ) ,
190202 filter ( ( _ ) => _ . channelName === ListenerChannelName . block ) ,
191203 filter ( ( _ ) => _ . message instanceof BlockInfo ) ,
192- map ( ( _ ) => _ . message as BlockInfo ) , ) ;
204+ map ( ( _ ) => _ . message as BlockInfo ) ) ;
193205 }
194206
195207 /**
@@ -206,7 +218,7 @@ export class Listener {
206218 filter ( ( _ ) => _ . channelName === ListenerChannelName . confirmedAdded ) ,
207219 filter ( ( _ ) => _ . message instanceof Transaction ) ,
208220 map ( ( _ ) => _ . message as Transaction ) ,
209- filter ( ( _ ) => this . transactionFromAddress ( _ , address ) ) , ) ;
221+ filter ( ( _ ) => this . transactionFromAddress ( _ , address ) ) ) ;
210222 }
211223
212224 /**
@@ -223,7 +235,7 @@ export class Listener {
223235 filter ( ( _ ) => _ . channelName === ListenerChannelName . unconfirmedAdded ) ,
224236 filter ( ( _ ) => _ . message instanceof Transaction ) ,
225237 map ( ( _ ) => _ . message as Transaction ) ,
226- filter ( ( _ ) => this . transactionFromAddress ( _ , address ) ) , ) ;
238+ filter ( ( _ ) => this . transactionFromAddress ( _ , address ) ) ) ;
227239 }
228240
229241 /**
@@ -239,7 +251,7 @@ export class Listener {
239251 return this . messageSubject . asObservable ( ) . pipe (
240252 filter ( ( _ ) => _ . channelName === ListenerChannelName . unconfirmedRemoved ) ,
241253 filter ( ( _ ) => typeof _ . message === 'string' ) ,
242- map ( ( _ ) => _ . message as string ) , ) ;
254+ map ( ( _ ) => _ . message as string ) ) ;
243255 }
244256
245257 /**
@@ -256,7 +268,7 @@ export class Listener {
256268 filter ( ( _ ) => _ . channelName === ListenerChannelName . aggregateBondedAdded ) ,
257269 filter ( ( _ ) => _ . message instanceof AggregateTransaction ) ,
258270 map ( ( _ ) => _ . message as AggregateTransaction ) ,
259- filter ( ( _ ) => this . transactionFromAddress ( _ , address ) ) , ) ;
271+ filter ( ( _ ) => this . transactionFromAddress ( _ , address ) ) ) ;
260272 }
261273
262274 /**
@@ -272,7 +284,7 @@ export class Listener {
272284 return this . messageSubject . asObservable ( ) . pipe (
273285 filter ( ( _ ) => _ . channelName === ListenerChannelName . aggregateBondedRemoved ) ,
274286 filter ( ( _ ) => typeof _ . message === 'string' ) ,
275- map ( ( _ ) => _ . message as string ) , ) ;
287+ map ( ( _ ) => _ . message as string ) ) ;
276288 }
277289
278290 /**
@@ -288,7 +300,7 @@ export class Listener {
288300 return this . messageSubject . asObservable ( ) . pipe (
289301 filter ( ( _ ) => _ . channelName === ListenerChannelName . status ) ,
290302 filter ( ( _ ) => _ . message instanceof TransactionStatusError ) ,
291- map ( ( _ ) => _ . message as TransactionStatusError ) , ) ;
303+ map ( ( _ ) => _ . message as TransactionStatusError ) ) ;
292304 }
293305
294306 /**
@@ -304,7 +316,7 @@ export class Listener {
304316 return this . messageSubject . asObservable ( ) . pipe (
305317 filter ( ( _ ) => _ . channelName === ListenerChannelName . cosignature ) ,
306318 filter ( ( _ ) => _ . message instanceof CosignatureSignedTransaction ) ,
307- map ( ( _ ) => _ . message as CosignatureSignedTransaction ) , ) ;
319+ map ( ( _ ) => _ . message as CosignatureSignedTransaction ) ) ;
308320 }
309321
310322 /**
@@ -320,6 +332,18 @@ export class Listener {
320332 this . webSocket . send ( JSON . stringify ( subscriptionMessage ) ) ;
321333 }
322334
335+ /**
336+ * @internal
337+ * @param channel - Channel to unsubscribe
338+ */
339+ private unsubscribeTo ( channel : string ) {
340+ const unsubscribeMessage = {
341+ uid : this . uid ,
342+ unsubscribe : channel ,
343+ } ;
344+ this . webSocket . send ( JSON . stringify ( unsubscribeMessage ) ) ;
345+ }
346+
323347 /**
324348 * @internal
325349 * Filters if a transaction has been initiated or signed by an address
0 commit comments