@edge-base/react-native 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
- import { HttpClient, GeneratedDbApi, IDatabaseLiveSubscriber, ContextManager, StorageClient, FunctionsClient, DbRef, ContextValue } from '@edge-base/core';
1
+ import { HttpClient, GeneratedDbApi, IDatabaseLiveSubscriber, ContextManager, Subscription, StorageClient, FunctionsClient, DbRef, ContextValue } from '@edge-base/core';
2
+ export { Subscription } from '@edge-base/core';
2
3
  import React from 'react';
3
4
 
4
5
  /**
@@ -405,8 +406,8 @@ declare class DatabaseLiveClient implements IDatabaseLiveSubscriber {
405
406
  private unsubAuthState;
406
407
  private options;
407
408
  constructor(baseUrl: string, tokenManager: TokenManager, options?: DatabaseLiveOptions, contextManager?: ContextManager);
408
- onSnapshot<T>(channel: string, callback: (change: DbChange<T>) => void, clientFilters?: unknown, serverFilters?: unknown, serverOrFilters?: unknown): () => void;
409
- onError(handler: ErrorHandler$1): () => void;
409
+ onSnapshot<T>(channel: string, callback: (change: DbChange<T>) => void, clientFilters?: unknown, serverFilters?: unknown, serverOrFilters?: unknown): Subscription;
410
+ onError(handler: ErrorHandler$1): Subscription;
410
411
  connect(channel: string): Promise<void>;
411
412
  reconnect(): void;
412
413
  disconnect(): void;
@@ -547,9 +548,7 @@ interface RoomOptions {
547
548
  /** Timeout for WebSocket connection establishment in ms (default: 15000) */
548
549
  connectionTimeout?: number;
549
550
  }
550
- interface Subscription {
551
- unsubscribe(): void;
552
- }
551
+
553
552
  type SharedStateHandler = (state: Record<string, unknown>, changes: Record<string, unknown>) => void;
554
553
  type PlayerStateHandler = (state: Record<string, unknown>, changes: Record<string, unknown>) => void;
555
554
  type MessageHandler = (data: unknown) => void;
@@ -841,14 +840,14 @@ declare class RoomClient {
841
840
  * Subscribe to shared state changes.
842
841
  * Called on full sync and on each shared_delta.
843
842
  *
844
- * @returns Subscription with unsubscribe()
843
+ * @returns Subscription (callable & .unsubscribe())
845
844
  */
846
845
  onSharedState(handler: SharedStateHandler): Subscription;
847
846
  /**
848
847
  * Subscribe to player state changes.
849
848
  * Called on full sync and on each player_delta.
850
849
  *
851
- * @returns Subscription with unsubscribe()
850
+ * @returns Subscription (callable & .unsubscribe())
852
851
  */
853
852
  onPlayerState(handler: PlayerStateHandler): Subscription;
854
853
  /**
@@ -857,13 +856,13 @@ declare class RoomClient {
857
856
  * @example
858
857
  * room.onMessage('game_over', (data) => { console.log(data.winner); });
859
858
  *
860
- * @returns Subscription with unsubscribe()
859
+ * @returns Subscription (callable & .unsubscribe())
861
860
  */
862
861
  onMessage(messageType: string, handler: MessageHandler): Subscription;
863
862
  /**
864
863
  * Subscribe to ALL messages regardless of type.
865
864
  *
866
- * @returns Subscription with unsubscribe()
865
+ * @returns Subscription (callable & .unsubscribe())
867
866
  */
868
867
  onAnyMessage(handler: (messageType: string, data: unknown) => void): Subscription;
869
868
  /** Subscribe to errors */
@@ -1411,4 +1410,4 @@ declare function useTurnstile({ baseUrl, action, }: UseTurnstileOptions): UseTur
1411
1410
  */
1412
1411
  declare function isPlatformWeb(): boolean;
1413
1412
 
1414
- export { type AppStateAdapter, type AsyncStorageAdapter, AuthClient, type AuthResult, type AuthStateChangeHandler, ClientAnalytics, ClientEdgeBase, DatabaseLiveClient, type DatabaseLiveClientAdapter, type DatabaseLiveOptions, type FilterEntry, type FilterOperator, type JuneClientOptions, LifecycleManager, type LinkingAdapter, type PasskeysAuthOptions, PushClient, type PushMessage, type PushMessageHandler, type PushPermissionProvider, type PushPermissionStatus, type PushPlatform, type PushTokenProvider, RoomClient, type RoomCloudflareRealtimeKitCreateSessionRequest, type RoomCloudflareRealtimeKitCreateSessionResponse, type RoomCloudflareRealtimeKitTransportFactoryOptions, type RoomConnectionState, type RoomMediaDeviceChange, type RoomMediaKind, type RoomMediaMember, type RoomMediaRemoteTrackEvent, type RoomMediaTrack, type RoomMediaTransport, type RoomMediaTransportConnectPayload, type RoomMediaTransportOptions, type RoomMediaTransportProvider, type RoomMember, type RoomMemberLeaveReason, type RoomMemberMediaKindState, type RoomMemberMediaState, type RoomOptions, type RoomP2PTransportFactoryOptions, type RoomReconnectInfo, type RoomSignalMeta, type Session, type SignInOptions, type SignUpOptions, type Subscription, TokenManager, type TokenPair, type TokenUser, TurnstileWebView, type TurnstileWebViewProps, type UpdateProfileOptions, type UseLifecycleOptions, type UseTurnstileOptions, type UseTurnstileResult, createClient, isPlatformWeb, matchesFilter, useLifecycle, useTurnstile };
1413
+ export { type AppStateAdapter, type AsyncStorageAdapter, AuthClient, type AuthResult, type AuthStateChangeHandler, ClientAnalytics, ClientEdgeBase, DatabaseLiveClient, type DatabaseLiveClientAdapter, type DatabaseLiveOptions, type FilterEntry, type FilterOperator, type JuneClientOptions, LifecycleManager, type LinkingAdapter, type PasskeysAuthOptions, PushClient, type PushMessage, type PushMessageHandler, type PushPermissionProvider, type PushPermissionStatus, type PushPlatform, type PushTokenProvider, RoomClient, type RoomCloudflareRealtimeKitCreateSessionRequest, type RoomCloudflareRealtimeKitCreateSessionResponse, type RoomCloudflareRealtimeKitTransportFactoryOptions, type RoomConnectionState, type RoomMediaDeviceChange, type RoomMediaKind, type RoomMediaMember, type RoomMediaRemoteTrackEvent, type RoomMediaTrack, type RoomMediaTransport, type RoomMediaTransportConnectPayload, type RoomMediaTransportOptions, type RoomMediaTransportProvider, type RoomMember, type RoomMemberLeaveReason, type RoomMemberMediaKindState, type RoomMemberMediaState, type RoomOptions, type RoomP2PTransportFactoryOptions, type RoomReconnectInfo, type RoomSignalMeta, type Session, type SignInOptions, type SignUpOptions, TokenManager, type TokenPair, type TokenUser, TurnstileWebView, type TurnstileWebViewProps, type UpdateProfileOptions, type UseLifecycleOptions, type UseTurnstileOptions, type UseTurnstileResult, createClient, isPlatformWeb, matchesFilter, useLifecycle, useTurnstile };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { HttpClient, GeneratedDbApi, IDatabaseLiveSubscriber, ContextManager, StorageClient, FunctionsClient, DbRef, ContextValue } from '@edge-base/core';
1
+ import { HttpClient, GeneratedDbApi, IDatabaseLiveSubscriber, ContextManager, Subscription, StorageClient, FunctionsClient, DbRef, ContextValue } from '@edge-base/core';
2
+ export { Subscription } from '@edge-base/core';
2
3
  import React from 'react';
3
4
 
4
5
  /**
@@ -405,8 +406,8 @@ declare class DatabaseLiveClient implements IDatabaseLiveSubscriber {
405
406
  private unsubAuthState;
406
407
  private options;
407
408
  constructor(baseUrl: string, tokenManager: TokenManager, options?: DatabaseLiveOptions, contextManager?: ContextManager);
408
- onSnapshot<T>(channel: string, callback: (change: DbChange<T>) => void, clientFilters?: unknown, serverFilters?: unknown, serverOrFilters?: unknown): () => void;
409
- onError(handler: ErrorHandler$1): () => void;
409
+ onSnapshot<T>(channel: string, callback: (change: DbChange<T>) => void, clientFilters?: unknown, serverFilters?: unknown, serverOrFilters?: unknown): Subscription;
410
+ onError(handler: ErrorHandler$1): Subscription;
410
411
  connect(channel: string): Promise<void>;
411
412
  reconnect(): void;
412
413
  disconnect(): void;
@@ -547,9 +548,7 @@ interface RoomOptions {
547
548
  /** Timeout for WebSocket connection establishment in ms (default: 15000) */
548
549
  connectionTimeout?: number;
549
550
  }
550
- interface Subscription {
551
- unsubscribe(): void;
552
- }
551
+
553
552
  type SharedStateHandler = (state: Record<string, unknown>, changes: Record<string, unknown>) => void;
554
553
  type PlayerStateHandler = (state: Record<string, unknown>, changes: Record<string, unknown>) => void;
555
554
  type MessageHandler = (data: unknown) => void;
@@ -841,14 +840,14 @@ declare class RoomClient {
841
840
  * Subscribe to shared state changes.
842
841
  * Called on full sync and on each shared_delta.
843
842
  *
844
- * @returns Subscription with unsubscribe()
843
+ * @returns Subscription (callable & .unsubscribe())
845
844
  */
846
845
  onSharedState(handler: SharedStateHandler): Subscription;
847
846
  /**
848
847
  * Subscribe to player state changes.
849
848
  * Called on full sync and on each player_delta.
850
849
  *
851
- * @returns Subscription with unsubscribe()
850
+ * @returns Subscription (callable & .unsubscribe())
852
851
  */
853
852
  onPlayerState(handler: PlayerStateHandler): Subscription;
854
853
  /**
@@ -857,13 +856,13 @@ declare class RoomClient {
857
856
  * @example
858
857
  * room.onMessage('game_over', (data) => { console.log(data.winner); });
859
858
  *
860
- * @returns Subscription with unsubscribe()
859
+ * @returns Subscription (callable & .unsubscribe())
861
860
  */
862
861
  onMessage(messageType: string, handler: MessageHandler): Subscription;
863
862
  /**
864
863
  * Subscribe to ALL messages regardless of type.
865
864
  *
866
- * @returns Subscription with unsubscribe()
865
+ * @returns Subscription (callable & .unsubscribe())
867
866
  */
868
867
  onAnyMessage(handler: (messageType: string, data: unknown) => void): Subscription;
869
868
  /** Subscribe to errors */
@@ -1411,4 +1410,4 @@ declare function useTurnstile({ baseUrl, action, }: UseTurnstileOptions): UseTur
1411
1410
  */
1412
1411
  declare function isPlatformWeb(): boolean;
1413
1412
 
1414
- export { type AppStateAdapter, type AsyncStorageAdapter, AuthClient, type AuthResult, type AuthStateChangeHandler, ClientAnalytics, ClientEdgeBase, DatabaseLiveClient, type DatabaseLiveClientAdapter, type DatabaseLiveOptions, type FilterEntry, type FilterOperator, type JuneClientOptions, LifecycleManager, type LinkingAdapter, type PasskeysAuthOptions, PushClient, type PushMessage, type PushMessageHandler, type PushPermissionProvider, type PushPermissionStatus, type PushPlatform, type PushTokenProvider, RoomClient, type RoomCloudflareRealtimeKitCreateSessionRequest, type RoomCloudflareRealtimeKitCreateSessionResponse, type RoomCloudflareRealtimeKitTransportFactoryOptions, type RoomConnectionState, type RoomMediaDeviceChange, type RoomMediaKind, type RoomMediaMember, type RoomMediaRemoteTrackEvent, type RoomMediaTrack, type RoomMediaTransport, type RoomMediaTransportConnectPayload, type RoomMediaTransportOptions, type RoomMediaTransportProvider, type RoomMember, type RoomMemberLeaveReason, type RoomMemberMediaKindState, type RoomMemberMediaState, type RoomOptions, type RoomP2PTransportFactoryOptions, type RoomReconnectInfo, type RoomSignalMeta, type Session, type SignInOptions, type SignUpOptions, type Subscription, TokenManager, type TokenPair, type TokenUser, TurnstileWebView, type TurnstileWebViewProps, type UpdateProfileOptions, type UseLifecycleOptions, type UseTurnstileOptions, type UseTurnstileResult, createClient, isPlatformWeb, matchesFilter, useLifecycle, useTurnstile };
1413
+ export { type AppStateAdapter, type AsyncStorageAdapter, AuthClient, type AuthResult, type AuthStateChangeHandler, ClientAnalytics, ClientEdgeBase, DatabaseLiveClient, type DatabaseLiveClientAdapter, type DatabaseLiveOptions, type FilterEntry, type FilterOperator, type JuneClientOptions, LifecycleManager, type LinkingAdapter, type PasskeysAuthOptions, PushClient, type PushMessage, type PushMessageHandler, type PushPermissionProvider, type PushPermissionStatus, type PushPlatform, type PushTokenProvider, RoomClient, type RoomCloudflareRealtimeKitCreateSessionRequest, type RoomCloudflareRealtimeKitCreateSessionResponse, type RoomCloudflareRealtimeKitTransportFactoryOptions, type RoomConnectionState, type RoomMediaDeviceChange, type RoomMediaKind, type RoomMediaMember, type RoomMediaRemoteTrackEvent, type RoomMediaTrack, type RoomMediaTransport, type RoomMediaTransportConnectPayload, type RoomMediaTransportOptions, type RoomMediaTransportProvider, type RoomMember, type RoomMemberLeaveReason, type RoomMemberMediaKindState, type RoomMemberMediaState, type RoomOptions, type RoomP2PTransportFactoryOptions, type RoomReconnectInfo, type RoomSignalMeta, type Session, type SignInOptions, type SignUpOptions, TokenManager, type TokenPair, type TokenUser, TurnstileWebView, type TurnstileWebViewProps, type UpdateProfileOptions, type UseLifecycleOptions, type UseTurnstileOptions, type UseTurnstileResult, createClient, isPlatformWeb, matchesFilter, useLifecycle, useTurnstile };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { EdgeBaseError, ApiPaths, ContextManager, HttpClient, DefaultDbApi, HttpClientAdapter, PublicHttpClientAdapter, StorageClient, FunctionsClient, DbRef } from '@edge-base/core';
1
+ import { EdgeBaseError, createSubscription, ApiPaths, ContextManager, HttpClient, DefaultDbApi, HttpClientAdapter, PublicHttpClientAdapter, StorageClient, FunctionsClient, DbRef } from '@edge-base/core';
2
2
  import React, { useCallback, useState, useEffect } from 'react';
3
3
 
4
4
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
@@ -646,7 +646,7 @@ var DatabaseLiveClient = class {
646
646
  }
647
647
  this.connect(channel).catch(() => {
648
648
  });
649
- return () => {
649
+ return createSubscription(() => {
650
650
  const subs = this.subscriptions.get(channel);
651
651
  if (!subs) return;
652
652
  const idx = subs.indexOf(sub);
@@ -657,14 +657,14 @@ var DatabaseLiveClient = class {
657
657
  this.channelOrFilters.delete(channel);
658
658
  this.sendUnsubscribe(channel);
659
659
  }
660
- };
660
+ });
661
661
  }
662
662
  onError(handler) {
663
663
  this.errorHandlers.push(handler);
664
- return () => {
664
+ return createSubscription(() => {
665
665
  const idx = this.errorHandlers.indexOf(handler);
666
666
  if (idx >= 0) this.errorHandlers.splice(idx, 1);
667
- };
667
+ });
668
668
  }
669
669
  async connect(channel) {
670
670
  this.connectedChannels.add(channel);
@@ -752,7 +752,7 @@ var DatabaseLiveClient = class {
752
752
  (refreshToken) => refreshAccessToken(this.baseUrl, refreshToken)
753
753
  );
754
754
  if (!token) throw new EdgeBaseError(401, "No access token available. Sign in first.");
755
- this.sendRaw({ type: "auth", token, sdkVersion: "0.2.0" });
755
+ this.sendRaw({ type: "auth", token, sdkVersion: "0.2.2" });
756
756
  return new Promise((resolve, reject) => {
757
757
  const timeout = setTimeout(() => reject(new EdgeBaseError(401, "Auth timeout")), 1e4);
758
758
  const original = this.ws?.onmessage;
@@ -872,7 +872,7 @@ var DatabaseLiveClient = class {
872
872
  refreshAuth() {
873
873
  const token = this.tokenManager.currentAccessToken;
874
874
  if (!token || !this.ws || !this.connected) return;
875
- this.sendRaw({ type: "auth", token, sdkVersion: "0.2.0" });
875
+ this.sendRaw({ type: "auth", token, sdkVersion: "0.2.2" });
876
876
  }
877
877
  handleAuthStateChange(user) {
878
878
  if (user) {
@@ -1219,14 +1219,12 @@ var RoomCloudflareMediaTransport = class {
1219
1219
  }
1220
1220
  onRemoteTrack(handler) {
1221
1221
  this.remoteTrackHandlers.push(handler);
1222
- return {
1223
- unsubscribe: () => {
1224
- const index = this.remoteTrackHandlers.indexOf(handler);
1225
- if (index >= 0) {
1226
- this.remoteTrackHandlers.splice(index, 1);
1227
- }
1222
+ return createSubscription(() => {
1223
+ const index = this.remoteTrackHandlers.indexOf(handler);
1224
+ if (index >= 0) {
1225
+ this.remoteTrackHandlers.splice(index, 1);
1228
1226
  }
1229
- };
1227
+ });
1230
1228
  }
1231
1229
  destroy() {
1232
1230
  this.lifecycleVersion += 1;
@@ -1627,14 +1625,12 @@ var RoomP2PMediaTransport = class {
1627
1625
  }
1628
1626
  onRemoteTrack(handler) {
1629
1627
  this.remoteTrackHandlers.push(handler);
1630
- return {
1631
- unsubscribe: () => {
1632
- const index = this.remoteTrackHandlers.indexOf(handler);
1633
- if (index >= 0) {
1634
- this.remoteTrackHandlers.splice(index, 1);
1635
- }
1628
+ return createSubscription(() => {
1629
+ const index = this.remoteTrackHandlers.indexOf(handler);
1630
+ if (index >= 0) {
1631
+ this.remoteTrackHandlers.splice(index, 1);
1636
1632
  }
1637
- };
1633
+ });
1638
1634
  }
1639
1635
  destroy() {
1640
1636
  this.connected = false;
@@ -2501,31 +2497,27 @@ var RoomClient = class _RoomClient {
2501
2497
  * Subscribe to shared state changes.
2502
2498
  * Called on full sync and on each shared_delta.
2503
2499
  *
2504
- * @returns Subscription with unsubscribe()
2500
+ * @returns Subscription (callable & .unsubscribe())
2505
2501
  */
2506
2502
  onSharedState(handler) {
2507
2503
  this.sharedStateHandlers.push(handler);
2508
- return {
2509
- unsubscribe: () => {
2510
- const idx = this.sharedStateHandlers.indexOf(handler);
2511
- if (idx >= 0) this.sharedStateHandlers.splice(idx, 1);
2512
- }
2513
- };
2504
+ return createSubscription(() => {
2505
+ const idx = this.sharedStateHandlers.indexOf(handler);
2506
+ if (idx >= 0) this.sharedStateHandlers.splice(idx, 1);
2507
+ });
2514
2508
  }
2515
2509
  /**
2516
2510
  * Subscribe to player state changes.
2517
2511
  * Called on full sync and on each player_delta.
2518
2512
  *
2519
- * @returns Subscription with unsubscribe()
2513
+ * @returns Subscription (callable & .unsubscribe())
2520
2514
  */
2521
2515
  onPlayerState(handler) {
2522
2516
  this.playerStateHandlers.push(handler);
2523
- return {
2524
- unsubscribe: () => {
2525
- const idx = this.playerStateHandlers.indexOf(handler);
2526
- if (idx >= 0) this.playerStateHandlers.splice(idx, 1);
2527
- }
2528
- };
2517
+ return createSubscription(() => {
2518
+ const idx = this.playerStateHandlers.indexOf(handler);
2519
+ if (idx >= 0) this.playerStateHandlers.splice(idx, 1);
2520
+ });
2529
2521
  }
2530
2522
  /**
2531
2523
  * Subscribe to messages of a specific type sent by room.sendMessage().
@@ -2533,169 +2525,137 @@ var RoomClient = class _RoomClient {
2533
2525
  * @example
2534
2526
  * room.onMessage('game_over', (data) => { console.log(data.winner); });
2535
2527
  *
2536
- * @returns Subscription with unsubscribe()
2528
+ * @returns Subscription (callable & .unsubscribe())
2537
2529
  */
2538
2530
  onMessage(messageType, handler) {
2539
2531
  if (!this.messageHandlers.has(messageType)) {
2540
2532
  this.messageHandlers.set(messageType, []);
2541
2533
  }
2542
2534
  this.messageHandlers.get(messageType).push(handler);
2543
- return {
2544
- unsubscribe: () => {
2545
- const handlers = this.messageHandlers.get(messageType);
2546
- if (handlers) {
2547
- const idx = handlers.indexOf(handler);
2548
- if (idx >= 0) handlers.splice(idx, 1);
2549
- }
2535
+ return createSubscription(() => {
2536
+ const handlers = this.messageHandlers.get(messageType);
2537
+ if (handlers) {
2538
+ const idx = handlers.indexOf(handler);
2539
+ if (idx >= 0) handlers.splice(idx, 1);
2550
2540
  }
2551
- };
2541
+ });
2552
2542
  }
2553
2543
  /**
2554
2544
  * Subscribe to ALL messages regardless of type.
2555
2545
  *
2556
- * @returns Subscription with unsubscribe()
2546
+ * @returns Subscription (callable & .unsubscribe())
2557
2547
  */
2558
2548
  onAnyMessage(handler) {
2559
2549
  this.allMessageHandlers.push(handler);
2560
- return {
2561
- unsubscribe: () => {
2562
- const idx = this.allMessageHandlers.indexOf(handler);
2563
- if (idx >= 0) this.allMessageHandlers.splice(idx, 1);
2564
- }
2565
- };
2550
+ return createSubscription(() => {
2551
+ const idx = this.allMessageHandlers.indexOf(handler);
2552
+ if (idx >= 0) this.allMessageHandlers.splice(idx, 1);
2553
+ });
2566
2554
  }
2567
2555
  /** Subscribe to errors */
2568
2556
  onError(handler) {
2569
2557
  this.errorHandlers.push(handler);
2570
- return {
2571
- unsubscribe: () => {
2572
- const idx = this.errorHandlers.indexOf(handler);
2573
- if (idx >= 0) this.errorHandlers.splice(idx, 1);
2574
- }
2575
- };
2558
+ return createSubscription(() => {
2559
+ const idx = this.errorHandlers.indexOf(handler);
2560
+ if (idx >= 0) this.errorHandlers.splice(idx, 1);
2561
+ });
2576
2562
  }
2577
2563
  /** Subscribe to kick events */
2578
2564
  onKicked(handler) {
2579
2565
  this.kickedHandlers.push(handler);
2580
- return {
2581
- unsubscribe: () => {
2582
- const idx = this.kickedHandlers.indexOf(handler);
2583
- if (idx >= 0) this.kickedHandlers.splice(idx, 1);
2584
- }
2585
- };
2566
+ return createSubscription(() => {
2567
+ const idx = this.kickedHandlers.indexOf(handler);
2568
+ if (idx >= 0) this.kickedHandlers.splice(idx, 1);
2569
+ });
2586
2570
  }
2587
2571
  onSignal(event, handler) {
2588
2572
  if (!this.signalHandlers.has(event)) {
2589
2573
  this.signalHandlers.set(event, []);
2590
2574
  }
2591
2575
  this.signalHandlers.get(event).push(handler);
2592
- return {
2593
- unsubscribe: () => {
2594
- const handlers = this.signalHandlers.get(event);
2595
- if (!handlers) return;
2596
- const index = handlers.indexOf(handler);
2597
- if (index >= 0) handlers.splice(index, 1);
2598
- }
2599
- };
2576
+ return createSubscription(() => {
2577
+ const handlers = this.signalHandlers.get(event);
2578
+ if (!handlers) return;
2579
+ const index = handlers.indexOf(handler);
2580
+ if (index >= 0) handlers.splice(index, 1);
2581
+ });
2600
2582
  }
2601
2583
  onAnySignal(handler) {
2602
2584
  this.anySignalHandlers.push(handler);
2603
- return {
2604
- unsubscribe: () => {
2605
- const index = this.anySignalHandlers.indexOf(handler);
2606
- if (index >= 0) this.anySignalHandlers.splice(index, 1);
2607
- }
2608
- };
2585
+ return createSubscription(() => {
2586
+ const index = this.anySignalHandlers.indexOf(handler);
2587
+ if (index >= 0) this.anySignalHandlers.splice(index, 1);
2588
+ });
2609
2589
  }
2610
2590
  onMembersSync(handler) {
2611
2591
  this.memberSyncHandlers.push(handler);
2612
- return {
2613
- unsubscribe: () => {
2614
- const index = this.memberSyncHandlers.indexOf(handler);
2615
- if (index >= 0) this.memberSyncHandlers.splice(index, 1);
2616
- }
2617
- };
2592
+ return createSubscription(() => {
2593
+ const index = this.memberSyncHandlers.indexOf(handler);
2594
+ if (index >= 0) this.memberSyncHandlers.splice(index, 1);
2595
+ });
2618
2596
  }
2619
2597
  onMemberJoin(handler) {
2620
2598
  this.memberJoinHandlers.push(handler);
2621
- return {
2622
- unsubscribe: () => {
2623
- const index = this.memberJoinHandlers.indexOf(handler);
2624
- if (index >= 0) this.memberJoinHandlers.splice(index, 1);
2625
- }
2626
- };
2599
+ return createSubscription(() => {
2600
+ const index = this.memberJoinHandlers.indexOf(handler);
2601
+ if (index >= 0) this.memberJoinHandlers.splice(index, 1);
2602
+ });
2627
2603
  }
2628
2604
  onMemberLeave(handler) {
2629
2605
  this.memberLeaveHandlers.push(handler);
2630
- return {
2631
- unsubscribe: () => {
2632
- const index = this.memberLeaveHandlers.indexOf(handler);
2633
- if (index >= 0) this.memberLeaveHandlers.splice(index, 1);
2634
- }
2635
- };
2606
+ return createSubscription(() => {
2607
+ const index = this.memberLeaveHandlers.indexOf(handler);
2608
+ if (index >= 0) this.memberLeaveHandlers.splice(index, 1);
2609
+ });
2636
2610
  }
2637
2611
  onMemberStateChange(handler) {
2638
2612
  this.memberStateHandlers.push(handler);
2639
- return {
2640
- unsubscribe: () => {
2641
- const index = this.memberStateHandlers.indexOf(handler);
2642
- if (index >= 0) this.memberStateHandlers.splice(index, 1);
2643
- }
2644
- };
2613
+ return createSubscription(() => {
2614
+ const index = this.memberStateHandlers.indexOf(handler);
2615
+ if (index >= 0) this.memberStateHandlers.splice(index, 1);
2616
+ });
2645
2617
  }
2646
2618
  onReconnect(handler) {
2647
2619
  this.reconnectHandlers.push(handler);
2648
- return {
2649
- unsubscribe: () => {
2650
- const index = this.reconnectHandlers.indexOf(handler);
2651
- if (index >= 0) this.reconnectHandlers.splice(index, 1);
2652
- }
2653
- };
2620
+ return createSubscription(() => {
2621
+ const index = this.reconnectHandlers.indexOf(handler);
2622
+ if (index >= 0) this.reconnectHandlers.splice(index, 1);
2623
+ });
2654
2624
  }
2655
2625
  onConnectionStateChange(handler) {
2656
2626
  this.connectionStateHandlers.push(handler);
2657
- return {
2658
- unsubscribe: () => {
2659
- const index = this.connectionStateHandlers.indexOf(handler);
2660
- if (index >= 0) this.connectionStateHandlers.splice(index, 1);
2661
- }
2662
- };
2627
+ return createSubscription(() => {
2628
+ const index = this.connectionStateHandlers.indexOf(handler);
2629
+ if (index >= 0) this.connectionStateHandlers.splice(index, 1);
2630
+ });
2663
2631
  }
2664
2632
  onMediaTrack(handler) {
2665
2633
  this.mediaTrackHandlers.push(handler);
2666
- return {
2667
- unsubscribe: () => {
2668
- const index = this.mediaTrackHandlers.indexOf(handler);
2669
- if (index >= 0) this.mediaTrackHandlers.splice(index, 1);
2670
- }
2671
- };
2634
+ return createSubscription(() => {
2635
+ const index = this.mediaTrackHandlers.indexOf(handler);
2636
+ if (index >= 0) this.mediaTrackHandlers.splice(index, 1);
2637
+ });
2672
2638
  }
2673
2639
  onMediaTrackRemoved(handler) {
2674
2640
  this.mediaTrackRemovedHandlers.push(handler);
2675
- return {
2676
- unsubscribe: () => {
2677
- const index = this.mediaTrackRemovedHandlers.indexOf(handler);
2678
- if (index >= 0) this.mediaTrackRemovedHandlers.splice(index, 1);
2679
- }
2680
- };
2641
+ return createSubscription(() => {
2642
+ const index = this.mediaTrackRemovedHandlers.indexOf(handler);
2643
+ if (index >= 0) this.mediaTrackRemovedHandlers.splice(index, 1);
2644
+ });
2681
2645
  }
2682
2646
  onMediaStateChange(handler) {
2683
2647
  this.mediaStateHandlers.push(handler);
2684
- return {
2685
- unsubscribe: () => {
2686
- const index = this.mediaStateHandlers.indexOf(handler);
2687
- if (index >= 0) this.mediaStateHandlers.splice(index, 1);
2688
- }
2689
- };
2648
+ return createSubscription(() => {
2649
+ const index = this.mediaStateHandlers.indexOf(handler);
2650
+ if (index >= 0) this.mediaStateHandlers.splice(index, 1);
2651
+ });
2690
2652
  }
2691
2653
  onMediaDeviceChange(handler) {
2692
2654
  this.mediaDeviceHandlers.push(handler);
2693
- return {
2694
- unsubscribe: () => {
2695
- const index = this.mediaDeviceHandlers.indexOf(handler);
2696
- if (index >= 0) this.mediaDeviceHandlers.splice(index, 1);
2697
- }
2698
- };
2655
+ return createSubscription(() => {
2656
+ const index = this.mediaDeviceHandlers.indexOf(handler);
2657
+ if (index >= 0) this.mediaDeviceHandlers.splice(index, 1);
2658
+ });
2699
2659
  }
2700
2660
  async sendSignal(event, payload, options) {
2701
2661
  if (!this.ws || !this.connected || !this.authenticated) {