Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit a726e66

Browse files
authored
fix: move back to an array solution (#467)
1 parent 64c42b8 commit a726e66

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/RealtimeClient.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const WORKER_SCRIPT = `
9191
export 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
/**

test/channel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ describe('leave', () => {
11131113
})
11141114

11151115
test("closes channel on 'ok' from server", () => {
1116-
const anotherChannel = socket.channel('another', { three: 'four' })
1116+
const anotherChannel = socket.channel('another')
11171117
assert.equal(socket.getChannels().length, 2)
11181118

11191119
channel.unsubscribe()

0 commit comments

Comments
 (0)