@@ -91,7 +91,7 @@ const WORKER_SCRIPT = `
9191export default class RealtimeClient {
9292 accessTokenValue : string | null = null
9393 apiKey : string | null = null
94- channels : Set < RealtimeChannel > = new Set ( )
94+ channels : RealtimeChannel [ ] = new Array ( )
9595 endPoint : string = ''
9696 httpEndpoint : string = ''
9797 headers ?: { [ key : string ] : string } = DEFAULT_HEADERS
@@ -262,7 +262,7 @@ export default class RealtimeClient {
262262 * Returns all created channels
263263 */
264264 getChannels ( ) : RealtimeChannel [ ] {
265- return Array . from ( this . channels )
265+ return this . channels
266266 }
267267
268268 /**
@@ -273,9 +273,11 @@ export default class RealtimeClient {
273273 channel : RealtimeChannel
274274 ) : Promise < RealtimeRemoveChannelResponse > {
275275 const status = await channel . unsubscribe ( )
276- if ( this . channels . size === 0 ) {
276+ this . channels = this . channels . filter ( ( c ) => c . _joinRef !== channel . _joinRef )
277+ if ( this . channels . length === 0 ) {
277278 this . disconnect ( )
278279 }
280+
279281 return status
280282 }
281283
@@ -284,13 +286,10 @@ export default class RealtimeClient {
284286 */
285287 async removeAllChannels ( ) : Promise < RealtimeRemoveChannelResponse [ ] > {
286288 const values_1 = await Promise . all (
287- Array . from ( this . channels ) . map ( ( channel ) => {
288- this . channels . delete ( channel )
289- return channel . unsubscribe ( )
290- } )
289+ this . channels . map ( ( channel ) => channel . unsubscribe ( ) )
291290 )
292291 this . disconnect ( )
293-
292+ this . channels = [ ]
294293 return values_1
295294 }
296295
@@ -337,7 +336,8 @@ export default class RealtimeClient {
337336
338337 if ( ! exists ) {
339338 const chan = new RealtimeChannel ( `realtime:${ topic } ` , params , this )
340- this . channels . add ( chan )
339+ this . channels . push ( chan )
340+
341341 return chan
342342 } else {
343343 return exists
@@ -480,7 +480,7 @@ export default class RealtimeClient {
480480 * @internal
481481 */
482482 _leaveOpenTopic ( topic : string ) : void {
483- let dupChannel = Array . from ( this . channels ) . find (
483+ let dupChannel = this . channels . find (
484484 ( c ) => c . topic === topic && ( c . _isJoined ( ) || c . _isJoining ( ) )
485485 )
486486 if ( dupChannel ) {
@@ -497,7 +497,7 @@ export default class RealtimeClient {
497497 * @internal
498498 */
499499 _remove ( channel : RealtimeChannel ) {
500- this . channels . delete ( channel )
500+ this . channels = this . channels . filter ( ( c ) => c . topic !== channel . topic )
501501 }
502502
503503 /**
0 commit comments