@100mslive/react-native-hms 1.1.0 → 1.2.0

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.
Files changed (101) hide show
  1. package/README.md +145 -340
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt +205 -75
  4. package/android/src/main/java/com/reactnativehmssdk/HMSHelper.kt +127 -127
  5. package/android/src/main/java/com/reactnativehmssdk/HMSManager.kt +153 -115
  6. package/android/src/main/java/com/reactnativehmssdk/HMSRNSDK.kt +147 -17
  7. package/android/src/main/java/com/reactnativehmssdk/HMSSDKViewManager.kt +7 -7
  8. package/ios/HMSDecoder.swift +205 -129
  9. package/ios/HMSHelper.swift +3 -3
  10. package/ios/HMSManager.m +3 -0
  11. package/ios/HMSManager.swift +22 -1
  12. package/ios/HMSRNSDK.swift +228 -79
  13. package/ios/HMSView.m +2 -0
  14. package/ios/HMSView.swift +35 -3
  15. package/ios/Hmssdk.xcodeproj/project.xcworkspace/xcuserdata/yogesh.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  16. package/lib/commonjs/classes/HMSBrowserRecordingState.js.map +1 -1
  17. package/lib/commonjs/classes/HMSChangeTrackStateRequest.js.map +1 -1
  18. package/lib/commonjs/classes/HMSEncoder.js +133 -84
  19. package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
  20. package/lib/commonjs/classes/HMSHLSStreamingState.js.map +1 -1
  21. package/lib/commonjs/classes/HMSLocalVideoTrack.js +0 -2
  22. package/lib/commonjs/classes/HMSLocalVideoTrack.js.map +1 -1
  23. package/lib/commonjs/classes/HMSMessageRecipient.js +1 -1
  24. package/lib/commonjs/classes/HMSMessageRecipient.js.map +1 -1
  25. package/lib/commonjs/classes/HMSNativeEventEmitter.js +106 -0
  26. package/lib/commonjs/classes/HMSNativeEventEmitter.js.map +1 -0
  27. package/lib/commonjs/classes/HMSPeer.js +4 -0
  28. package/lib/commonjs/classes/HMSPeer.js.map +1 -1
  29. package/lib/commonjs/classes/HMSPublishSettings.js +0 -6
  30. package/lib/commonjs/classes/HMSPublishSettings.js.map +1 -1
  31. package/lib/commonjs/classes/HMSRole.js +0 -6
  32. package/lib/commonjs/classes/HMSRole.js.map +1 -1
  33. package/lib/commonjs/classes/HMSRoleChangeRequest.js +3 -1
  34. package/lib/commonjs/classes/HMSRoleChangeRequest.js.map +1 -1
  35. package/lib/commonjs/classes/HMSRtmpStreamingState.js.map +1 -1
  36. package/lib/commonjs/classes/HMSSDK.js +465 -137
  37. package/lib/commonjs/classes/HMSSDK.js.map +1 -1
  38. package/lib/commonjs/classes/HMSServerRecordingState.js.map +1 -1
  39. package/lib/commonjs/classes/HMSSubscribeSettings.js +0 -2
  40. package/lib/commonjs/classes/HMSSubscribeSettings.js.map +1 -1
  41. package/lib/commonjs/index.js.map +1 -1
  42. package/lib/module/classes/HMSBrowserRecordingState.js.map +1 -1
  43. package/lib/module/classes/HMSChangeTrackStateRequest.js.map +1 -1
  44. package/lib/module/classes/HMSEncoder.js +133 -84
  45. package/lib/module/classes/HMSEncoder.js.map +1 -1
  46. package/lib/module/classes/HMSHLSStreamingState.js.map +1 -1
  47. package/lib/module/classes/HMSLocalVideoTrack.js +0 -2
  48. package/lib/module/classes/HMSLocalVideoTrack.js.map +1 -1
  49. package/lib/module/classes/HMSMessageRecipient.js +1 -1
  50. package/lib/module/classes/HMSMessageRecipient.js.map +1 -1
  51. package/lib/module/classes/HMSNativeEventEmitter.js +99 -0
  52. package/lib/module/classes/HMSNativeEventEmitter.js.map +1 -0
  53. package/lib/module/classes/HMSPeer.js +4 -0
  54. package/lib/module/classes/HMSPeer.js.map +1 -1
  55. package/lib/module/classes/HMSPublishSettings.js +0 -6
  56. package/lib/module/classes/HMSPublishSettings.js.map +1 -1
  57. package/lib/module/classes/HMSRole.js +0 -6
  58. package/lib/module/classes/HMSRole.js.map +1 -1
  59. package/lib/module/classes/HMSRoleChangeRequest.js +3 -1
  60. package/lib/module/classes/HMSRoleChangeRequest.js.map +1 -1
  61. package/lib/module/classes/HMSRtmpStreamingState.js.map +1 -1
  62. package/lib/module/classes/HMSSDK.js +466 -138
  63. package/lib/module/classes/HMSSDK.js.map +1 -1
  64. package/lib/module/classes/HMSServerRecordingState.js.map +1 -1
  65. package/lib/module/classes/HMSSubscribeSettings.js +0 -2
  66. package/lib/module/classes/HMSSubscribeSettings.js.map +1 -1
  67. package/lib/module/index.js.map +1 -1
  68. package/lib/typescript/classes/HMSBrowserRecordingState.d.ts +4 -4
  69. package/lib/typescript/classes/HMSChangeTrackStateRequest.d.ts +2 -2
  70. package/lib/typescript/classes/HMSEncoder.d.ts +3 -0
  71. package/lib/typescript/classes/HMSHLSStreamingState.d.ts +2 -2
  72. package/lib/typescript/classes/HMSLocalVideoTrack.d.ts +0 -2
  73. package/lib/typescript/classes/HMSMessageRecipient.d.ts +2 -2
  74. package/lib/typescript/classes/HMSNativeEventEmitter.d.ts +13 -0
  75. package/lib/typescript/classes/HMSPublishSettings.d.ts +8 -15
  76. package/lib/typescript/classes/HMSRole.d.ts +0 -6
  77. package/lib/typescript/classes/HMSRoleChangeRequest.d.ts +2 -2
  78. package/lib/typescript/classes/HMSRtmpStreamingState.d.ts +4 -4
  79. package/lib/typescript/classes/HMSSDK.d.ts +2 -12
  80. package/lib/typescript/classes/HMSServerRecordingState.d.ts +2 -2
  81. package/lib/typescript/classes/HMSSubscribeSettings.d.ts +0 -2
  82. package/lib/typescript/index.d.ts +1 -0
  83. package/package.json +6 -4
  84. package/react-native-hms.podspec +1 -1
  85. package/sdk-versions.json +5 -0
  86. package/src/classes/HMSBrowserRecordingState.ts +4 -4
  87. package/src/classes/HMSChangeTrackStateRequest.ts +2 -2
  88. package/src/classes/HMSEncoder.ts +186 -99
  89. package/src/classes/HMSHLSStreamingState.ts +2 -2
  90. package/src/classes/HMSLocalVideoTrack.ts +0 -2
  91. package/src/classes/HMSMessageRecipient.ts +3 -3
  92. package/src/classes/HMSNativeEventEmitter.ts +86 -0
  93. package/src/classes/HMSPeer.ts +4 -0
  94. package/src/classes/HMSPublishSettings.ts +8 -18
  95. package/src/classes/HMSRole.ts +0 -9
  96. package/src/classes/HMSRoleChangeRequest.ts +5 -3
  97. package/src/classes/HMSRtmpStreamingState.ts +4 -4
  98. package/src/classes/HMSSDK.tsx +629 -269
  99. package/src/classes/HMSServerRecordingState.ts +2 -2
  100. package/src/classes/HMSSubscribeSettings.ts +1 -7
  101. package/src/index.ts +1 -0
@@ -2,7 +2,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
2
2
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
3
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
4
  import React from 'react';
5
- import { AppState, NativeEventEmitter, NativeModules, Platform } from 'react-native';
5
+ import { AppState, NativeModules, Platform } from 'react-native';
6
6
  import { HMSEncoder } from './HMSEncoder';
7
7
  import { HMSHelper } from './HMSHelper';
8
8
  import { HMSLocalAudioStats } from './HMSLocalAudioStats';
@@ -15,6 +15,7 @@ import { HMSUpdateListenerActions } from './HMSUpdateListenerActions';
15
15
  import { HmsViewComponent } from './HmsView';
16
16
  import { HMSMessageType } from './HMSMessageType';
17
17
  import { HMSPIPListenerActions } from './HMSPIPListenerActions';
18
+ import { HMSNativeEventEmitter } from './HMSNativeEventEmitter';
18
19
  const {
19
20
  /**
20
21
  * @ignore
@@ -22,7 +23,7 @@ const {
22
23
  HMSManager
23
24
  } = NativeModules;
24
25
  const ReactNativeVersion = require('react-native/Libraries/Core/ReactNativeVersion');
25
- const HmsEventEmitter = new NativeEventEmitter(HMSManager);
26
+ const HmsEventEmitter = new HMSNativeEventEmitter(HMSManager);
26
27
  let HmsSdk;
27
28
  export class HMSSDK {
28
29
  constructor(id) {
@@ -50,6 +51,7 @@ export class HMSSDK {
50
51
  _defineProperty(this, "onRemoteVideoStatsDelegate", void 0);
51
52
  _defineProperty(this, "onAudioDeviceChangedDelegate", void 0);
52
53
  _defineProperty(this, "onPIPRoomLeaveDelegate", void 0);
54
+ _defineProperty(this, "emitterSubscriptions", {});
53
55
  _defineProperty(this, "setLogger", hmsLogger => {
54
56
  setLogger(this.id, hmsLogger);
55
57
  });
@@ -57,59 +59,11 @@ export class HMSSDK {
57
59
  logger === null || logger === void 0 ? void 0 : logger.verbose('#Function destroy', {
58
60
  id: this.id
59
61
  });
60
- this.removeListeners();
62
+ this.removeAllListeners();
61
63
  return await HMSManager.destroy({
62
64
  id: this.id
63
65
  });
64
66
  });
65
- _defineProperty(this, "attachListeners", () => {
66
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_PREVIEW, this.onPreviewListener);
67
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_JOIN, this.onJoinListener);
68
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_ROOM_UPDATE, this.onRoomListener);
69
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_PEER_UPDATE, this.onPeerListener);
70
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_TRACK_UPDATE, this.onTrackListener);
71
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_ERROR, this.onErrorListener);
72
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_MESSAGE, this.onMessageListener);
73
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_SPEAKER, this.onSpeakerListener);
74
- HmsEventEmitter.addListener(HMSUpdateListenerActions.RECONNECTING, this.reconnectingListener);
75
- HmsEventEmitter.addListener(HMSUpdateListenerActions.RECONNECTED, this.reconnectedListener);
76
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST, this.onRoleChangeRequestListener);
77
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST, this.onChangeTrackStateRequestListener);
78
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM, this.onRemovedFromRoomListener);
79
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_RTC_STATS, this.RTCStatsListener);
80
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS, this.onLocalAudioStatsListener);
81
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS, this.onLocalVideoStatsListener);
82
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS, this.onRemoteAudioStatsListener);
83
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS, this.onRemoteVideoStatsListener);
84
- HmsEventEmitter.addListener(HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED, this.onAudioDeviceChangedListener);
85
- if (Platform.OS === 'android') {
86
- HmsEventEmitter.addListener(HMSPIPListenerActions.ON_PIP_ROOM_LEAVE, this.onPIPRoomLeaveListener);
87
- }
88
- });
89
- _defineProperty(this, "removeListeners", () => {
90
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_JOIN, this.onJoinListener);
91
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_PREVIEW, this.onPreviewListener);
92
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_ROOM_UPDATE, this.onRoomListener);
93
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_PEER_UPDATE, this.onPeerListener);
94
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_TRACK_UPDATE, this.onTrackListener);
95
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_ERROR, this.onErrorListener);
96
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_MESSAGE, this.onMessageListener);
97
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_SPEAKER, this.onSpeakerListener);
98
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.RECONNECTING, this.reconnectingListener);
99
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.RECONNECTED, this.reconnectedListener);
100
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST, this.onRoleChangeRequestListener);
101
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST, this.onChangeTrackStateRequestListener);
102
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM, this.onRemovedFromRoomListener);
103
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_RTC_STATS, this.RTCStatsListener);
104
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS, this.onLocalAudioStatsListener);
105
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS, this.onLocalVideoStatsListener);
106
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS, this.onRemoteAudioStatsListener);
107
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS, this.onRemoteVideoStatsListener);
108
- HmsEventEmitter.removeListener(HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED, this.onAudioDeviceChangedListener);
109
- if (Platform.OS === 'android') {
110
- HmsEventEmitter.removeListener(HMSPIPListenerActions.ON_PIP_ROOM_LEAVE, this.onPIPRoomLeaveListener);
111
- }
112
- });
113
67
  _defineProperty(this, "join", async config => {
114
68
  logger === null || logger === void 0 ? void 0 : logger.verbose('#Function join', {
115
69
  config,
@@ -164,8 +118,13 @@ export class HMSSDK {
164
118
  id: this.id
165
119
  });
166
120
  }));
167
- _defineProperty(this, "leave", async () => {
121
+ _defineProperty(this, "roomLeaveCleanup", () => {
168
122
  var _this$appStateSubscri;
123
+ this.muteStatus = undefined;
124
+ this === null || this === void 0 ? void 0 : (_this$appStateSubscri = this.appStateSubscription) === null || _this$appStateSubscri === void 0 ? void 0 : _this$appStateSubscri.remove();
125
+ HMSEncoder.clearData(); // Clearing cached data in encoder
126
+ });
127
+ _defineProperty(this, "leave", async () => {
169
128
  logger === null || logger === void 0 ? void 0 : logger.verbose('#Function leave', {
170
129
  id: this.id
171
130
  });
@@ -173,8 +132,7 @@ export class HMSSDK {
173
132
  id: this.id
174
133
  };
175
134
  const op = await HMSManager.leave(data);
176
- this.muteStatus = undefined;
177
- this === null || this === void 0 ? void 0 : (_this$appStateSubscri = this.appStateSubscription) === null || _this$appStateSubscri === void 0 ? void 0 : _this$appStateSubscri.remove();
135
+ this.roomLeaveCleanup();
178
136
  return op;
179
137
  });
180
138
  _defineProperty(this, "sendBroadcastMessage", async function (message) {
@@ -684,65 +642,247 @@ export class HMSSDK {
684
642
  });
685
643
  switch (action) {
686
644
  case HMSUpdateListenerActions.ON_PREVIEW:
687
- this.onPreviewDelegate = callback;
688
- break;
645
+ {
646
+ // Checking if we already have ON_PREVIEW subscription
647
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_PREVIEW]) {
648
+ // Adding ON_PREVIEW native listener
649
+ const previewSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_PREVIEW, this.onPreviewListener);
650
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_PREVIEW] = previewSubscription;
651
+ }
652
+ // Adding App Delegate listener
653
+ this.onPreviewDelegate = callback;
654
+ break;
655
+ }
689
656
  case HMSUpdateListenerActions.ON_JOIN:
690
- this.onJoinDelegate = callback;
691
- break;
657
+ {
658
+ // Checking if we already have ON_JOIN subscription
659
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_JOIN]) {
660
+ // Adding ON_JOIN native listener
661
+ const joinSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_JOIN, this.onJoinListener);
662
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_JOIN] = joinSubscription;
663
+ }
664
+ // Adding App Delegate listener
665
+ this.onJoinDelegate = callback;
666
+ break;
667
+ }
692
668
  case HMSUpdateListenerActions.ON_ROOM_UPDATE:
693
- this.onRoomDelegate = callback;
694
- break;
669
+ {
670
+ // Checking if we already have ON_ROOM_UPDATE subscription
671
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROOM_UPDATE]) {
672
+ // Adding ON_ROOM_UPDATE native listener
673
+ const roomSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_ROOM_UPDATE, this.onRoomListener);
674
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROOM_UPDATE] = roomSubscription;
675
+ }
676
+ // Adding App Delegate listener
677
+ this.onRoomDelegate = callback;
678
+ break;
679
+ }
695
680
  case HMSUpdateListenerActions.ON_PEER_UPDATE:
696
- this.onPeerDelegate = callback;
697
- break;
681
+ {
682
+ // Checking if we already have ON_PEER_UPDATE subscription
683
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_PEER_UPDATE]) {
684
+ // Adding ON_PEER_UPDATE native listener
685
+ const peerSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_PEER_UPDATE, this.onPeerListener);
686
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_PEER_UPDATE] = peerSubscription;
687
+ }
688
+ // Adding App Delegate listener
689
+ this.onPeerDelegate = callback;
690
+ break;
691
+ }
698
692
  case HMSUpdateListenerActions.ON_TRACK_UPDATE:
699
- this.onTrackDelegate = callback;
700
- break;
693
+ {
694
+ // Checking if we already have ON_TRACK_UPDATE subscription
695
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_TRACK_UPDATE]) {
696
+ // Adding ON_TRACK_UPDATE native listener
697
+ const trackSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_TRACK_UPDATE, this.onTrackListener);
698
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_TRACK_UPDATE] = trackSubscription;
699
+ }
700
+ // Adding App Delegate listener
701
+ this.onTrackDelegate = callback;
702
+ break;
703
+ }
701
704
  case HMSUpdateListenerActions.ON_ERROR:
702
- this.onErrorDelegate = callback;
703
- break;
705
+ {
706
+ // Checking if we already have ON_ERROR subscription
707
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_ERROR]) {
708
+ // Adding ON_ERROR native listener
709
+ const errorSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_ERROR, this.onErrorListener);
710
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_ERROR] = errorSubscription;
711
+ }
712
+ // Adding App Delegate listener
713
+ this.onErrorDelegate = callback;
714
+ break;
715
+ }
704
716
  case HMSUpdateListenerActions.ON_MESSAGE:
705
- this.onMessageDelegate = callback;
706
- break;
717
+ {
718
+ // Checking if we already have ON_MESSAGE subscription
719
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_MESSAGE]) {
720
+ // Adding ON_MESSAGE native listener
721
+ const messageSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_MESSAGE, this.onMessageListener);
722
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_MESSAGE] = messageSubscription;
723
+ }
724
+ // Adding App Delegate listener
725
+ this.onMessageDelegate = callback;
726
+ break;
727
+ }
707
728
  case HMSUpdateListenerActions.ON_SPEAKER:
708
- this.onSpeakerDelegate = callback;
709
- break;
729
+ {
730
+ // Checking if we already have ON_SPEAKER subscription
731
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_SPEAKER]) {
732
+ // Adding ON_SPEAKER native listener
733
+ const speakerSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_SPEAKER, this.onSpeakerListener);
734
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_SPEAKER] = speakerSubscription;
735
+ }
736
+ // Adding App Delegate listener
737
+ this.onSpeakerDelegate = callback;
738
+ break;
739
+ }
710
740
  case HMSUpdateListenerActions.RECONNECTING:
711
- this.onReconnectingDelegate = callback;
712
- break;
741
+ {
742
+ // Checking if we already have RECONNECTING subscription
743
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTING]) {
744
+ // Adding RECONNECTING native listener
745
+ const reconnectingSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.RECONNECTING, this.reconnectingListener);
746
+ this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTING] = reconnectingSubscription;
747
+ }
748
+ // Adding App Delegate listener
749
+ this.onReconnectingDelegate = callback;
750
+ break;
751
+ }
713
752
  case HMSUpdateListenerActions.RECONNECTED:
714
- this.onReconnectedDelegate = callback;
715
- break;
753
+ {
754
+ // Checking if we already have RECONNECTED subscription
755
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTED]) {
756
+ // Adding RECONNECTED native listener
757
+ const reconnectedSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.RECONNECTED, this.reconnectedListener);
758
+ this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTED] = reconnectedSubscription;
759
+ }
760
+ // Adding App Delegate listener
761
+ this.onReconnectedDelegate = callback;
762
+ break;
763
+ }
716
764
  case HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST:
717
- this.onRoleChangeRequestDelegate = callback;
718
- break;
765
+ {
766
+ // Checking if we already have ON_ROLE_CHANGE_REQUEST subscription
767
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST]) {
768
+ // Adding ON_ROLE_CHANGE_REQUEST native listener
769
+ const roleChangeReqSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST, this.onRoleChangeRequestListener);
770
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST] = roleChangeReqSubscription;
771
+ }
772
+ // Adding App Delegate listener
773
+ this.onRoleChangeRequestDelegate = callback;
774
+ break;
775
+ }
719
776
  case HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST:
720
- this.onChangeTrackStateRequestDelegate = callback;
721
- break;
777
+ {
778
+ // Checking if we already have ON_CHANGE_TRACK_STATE_REQUEST subscription
779
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST]) {
780
+ // Adding ON_CHANGE_TRACK_STATE_REQUEST native listener
781
+ const changeTrackReqSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST, this.onChangeTrackStateRequestListener);
782
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST] = changeTrackReqSubscription;
783
+ }
784
+ // Adding App Delegate listener
785
+ this.onChangeTrackStateRequestDelegate = callback;
786
+ break;
787
+ }
722
788
  case HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM:
723
- this.onRemovedFromRoomDelegate = callback;
724
- break;
789
+ {
790
+ // Checking if we already have ON_REMOVED_FROM_ROOM subscription
791
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM]) {
792
+ // Adding ON_REMOVED_FROM_ROOM native listener
793
+ const removedFromRoomSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM, this.onRemovedFromRoomListener);
794
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM] = removedFromRoomSubscription;
795
+ }
796
+ // Adding App Delegate listener
797
+ this.onRemovedFromRoomDelegate = callback;
798
+ break;
799
+ }
725
800
  case HMSUpdateListenerActions.ON_RTC_STATS:
726
- this.onRtcStatsDelegate = callback;
727
- break;
801
+ {
802
+ // Checking if we already have ON_RTC_STATS subscription
803
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_RTC_STATS]) {
804
+ // Adding ON_RTC_STATS native listener
805
+ const rtcStatsSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_RTC_STATS, this.RTCStatsListener);
806
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_RTC_STATS] = rtcStatsSubscription;
807
+ }
808
+ // Adding App Delegate listener
809
+ this.onRtcStatsDelegate = callback;
810
+ break;
811
+ }
728
812
  case HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS:
729
- this.onLocalAudioStatsDelegate = callback;
730
- break;
813
+ {
814
+ // Checking if we already have ON_LOCAL_AUDIO_STATS subscription
815
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS]) {
816
+ // Adding ON_LOCAL_AUDIO_STATS native listener
817
+ const lclAudioStatsSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS, this.onLocalAudioStatsListener);
818
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS] = lclAudioStatsSubscription;
819
+ }
820
+ // Adding App Delegate listener
821
+ this.onLocalAudioStatsDelegate = callback;
822
+ break;
823
+ }
731
824
  case HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS:
732
- this.onLocalVideoStatsDelegate = callback;
733
- break;
825
+ {
826
+ // Checking if we already have ON_LOCAL_VIDEO_STATS subscription
827
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS]) {
828
+ // Adding ON_LOCAL_VIDEO_STATS native listener
829
+ const lclVideoStatsSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS, this.onLocalVideoStatsListener);
830
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS] = lclVideoStatsSubscription;
831
+ }
832
+ // Adding App Delegate listener
833
+ this.onLocalVideoStatsDelegate = callback;
834
+ break;
835
+ }
734
836
  case HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS:
735
- this.onRemoteAudioStatsDelegate = callback;
736
- break;
837
+ {
838
+ // Checking if we already have ON_REMOTE_AUDIO_STATS subscription
839
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS]) {
840
+ // Adding ON_REMOTE_AUDIO_STATS native listener
841
+ const rmAudioStatsSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS, this.onRemoteAudioStatsListener);
842
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS] = rmAudioStatsSubscription;
843
+ }
844
+ // Adding App Delegate listener
845
+ this.onRemoteAudioStatsDelegate = callback;
846
+ break;
847
+ }
737
848
  case HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS:
738
- this.onRemoteVideoStatsDelegate = callback;
739
- break;
849
+ {
850
+ // Checking if we already have ON_REMOTE_VIDEO_STATS subscription
851
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS]) {
852
+ // Adding ON_REMOTE_VIDEO_STATS native listener
853
+ const rmVideoStatsSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS, this.onRemoteVideoStatsListener);
854
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS] = rmVideoStatsSubscription;
855
+ }
856
+ // Adding App Delegate listener
857
+ this.onRemoteVideoStatsDelegate = callback;
858
+ break;
859
+ }
740
860
  case HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED:
741
- this.onAudioDeviceChangedDelegate = callback;
742
- break;
861
+ {
862
+ // Checking if we already have ON_AUDIO_DEVICE_CHANGED subscription
863
+ if (!this.emitterSubscriptions[HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED]) {
864
+ // Adding ON_AUDIO_DEVICE_CHANGED native listener
865
+ const audDeviceChgSubscription = HmsEventEmitter.addListener(this.id, HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED, this.onAudioDeviceChangedListener);
866
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED] = audDeviceChgSubscription;
867
+ }
868
+ // Adding App Delegate listener
869
+ this.onAudioDeviceChangedDelegate = callback;
870
+ break;
871
+ }
743
872
  case HMSPIPListenerActions.ON_PIP_ROOM_LEAVE:
744
- this.onPIPRoomLeaveDelegate = callback;
745
- break;
873
+ {
874
+ if (Platform.OS === 'android') {
875
+ // Checking if we already have ON_PIP_ROOM_LEAVE subscription
876
+ if (!this.emitterSubscriptions[HMSPIPListenerActions.ON_PIP_ROOM_LEAVE]) {
877
+ // Adding ON_PIP_ROOM_LEAVE native listener
878
+ const pipRoomLeaveSubscription = HmsEventEmitter.addListener(this.id, HMSPIPListenerActions.ON_PIP_ROOM_LEAVE, this.onPIPRoomLeaveListener);
879
+ this.emitterSubscriptions[HMSPIPListenerActions.ON_PIP_ROOM_LEAVE] = pipRoomLeaveSubscription;
880
+ }
881
+ // Adding App Delegate listener
882
+ this.onPIPRoomLeaveDelegate = callback;
883
+ }
884
+ break;
885
+ }
746
886
  default:
747
887
  }
748
888
  });
@@ -753,65 +893,247 @@ export class HMSSDK {
753
893
  });
754
894
  switch (action) {
755
895
  case HMSUpdateListenerActions.ON_PREVIEW:
756
- this.onPreviewDelegate = null;
757
- break;
896
+ {
897
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_PREVIEW];
898
+ // Removing ON_PREVIEW native listener
899
+ if (subscription) {
900
+ subscription.remove();
901
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_PREVIEW] = undefined;
902
+ }
903
+ // Removing App Delegate listener
904
+ this.onPreviewDelegate = null;
905
+ break;
906
+ }
758
907
  case HMSUpdateListenerActions.ON_JOIN:
759
- this.onJoinDelegate = null;
760
- break;
908
+ {
909
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_JOIN];
910
+ // Removing ON_JOIN native listener
911
+ if (subscription) {
912
+ subscription.remove();
913
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_JOIN] = undefined;
914
+ }
915
+ // Removing App Delegate listener
916
+ this.onJoinDelegate = null;
917
+ break;
918
+ }
761
919
  case HMSUpdateListenerActions.ON_ROOM_UPDATE:
762
- this.onRoomDelegate = null;
763
- break;
920
+ {
921
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROOM_UPDATE];
922
+ // Removing ON_ROOM_UPDATE native listener
923
+ if (subscription) {
924
+ subscription.remove();
925
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROOM_UPDATE] = undefined;
926
+ }
927
+ // Removing App Delegate listener
928
+ this.onRoomDelegate = null;
929
+ break;
930
+ }
764
931
  case HMSUpdateListenerActions.ON_PEER_UPDATE:
765
- this.onPeerDelegate = null;
766
- break;
932
+ {
933
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_PEER_UPDATE];
934
+ // Removing ON_PEER_UPDATE native listener
935
+ if (subscription) {
936
+ subscription.remove();
937
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_PEER_UPDATE] = undefined;
938
+ }
939
+ // Removing App Delegate listener
940
+ this.onPeerDelegate = null;
941
+ break;
942
+ }
767
943
  case HMSUpdateListenerActions.ON_TRACK_UPDATE:
768
- this.onTrackDelegate = null;
769
- break;
944
+ {
945
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_TRACK_UPDATE];
946
+ // Removing ON_TRACK_UPDATE native listener
947
+ if (subscription) {
948
+ subscription.remove();
949
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_TRACK_UPDATE] = undefined;
950
+ }
951
+ // Removing App Delegate listener
952
+ this.onTrackDelegate = null;
953
+ break;
954
+ }
770
955
  case HMSUpdateListenerActions.ON_ERROR:
771
- this.onErrorDelegate = null;
772
- break;
956
+ {
957
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_ERROR];
958
+ // Removing ON_ERROR native listener
959
+ if (subscription) {
960
+ subscription.remove();
961
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_ERROR] = undefined;
962
+ }
963
+ // Removing App Delegate listener
964
+ this.onErrorDelegate = null;
965
+ break;
966
+ }
773
967
  case HMSUpdateListenerActions.ON_MESSAGE:
774
- this.onMessageDelegate = null;
775
- break;
968
+ {
969
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_MESSAGE];
970
+ // Removing ON_MESSAGE native listener
971
+ if (subscription) {
972
+ subscription.remove();
973
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_MESSAGE] = undefined;
974
+ }
975
+ // Removing App Delegate listener
976
+ this.onMessageDelegate = null;
977
+ break;
978
+ }
776
979
  case HMSUpdateListenerActions.ON_SPEAKER:
777
- this.onSpeakerDelegate = null;
778
- break;
980
+ {
981
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_SPEAKER];
982
+ // Removing ON_SPEAKER native listener
983
+ if (subscription) {
984
+ subscription.remove();
985
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_SPEAKER] = undefined;
986
+ }
987
+ // Removing App Delegate listener
988
+ this.onSpeakerDelegate = null;
989
+ break;
990
+ }
779
991
  case HMSUpdateListenerActions.RECONNECTING:
780
- this.onReconnectingDelegate = null;
781
- break;
992
+ {
993
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTING];
994
+ // Removing RECONNECTING native listener
995
+ if (subscription) {
996
+ subscription.remove();
997
+ this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTING] = undefined;
998
+ }
999
+ // Removing App Delegate listener
1000
+ this.onReconnectingDelegate = null;
1001
+ break;
1002
+ }
782
1003
  case HMSUpdateListenerActions.RECONNECTED:
783
- this.onReconnectedDelegate = null;
784
- break;
1004
+ {
1005
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTED];
1006
+ // Removing RECONNECTED native listener
1007
+ if (subscription) {
1008
+ subscription.remove();
1009
+ this.emitterSubscriptions[HMSUpdateListenerActions.RECONNECTED] = undefined;
1010
+ }
1011
+ // Removing App Delegate listener
1012
+ this.onReconnectedDelegate = null;
1013
+ break;
1014
+ }
785
1015
  case HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST:
786
- this.onRoleChangeRequestDelegate = null;
787
- break;
1016
+ {
1017
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST];
1018
+ // Removing ON_ROLE_CHANGE_REQUEST native listener
1019
+ if (subscription) {
1020
+ subscription.remove();
1021
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST] = undefined;
1022
+ }
1023
+ // Removing App Delegate listener
1024
+ this.onRoleChangeRequestDelegate = null;
1025
+ break;
1026
+ }
788
1027
  case HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST:
789
- this.onChangeTrackStateRequestDelegate = null;
790
- break;
1028
+ {
1029
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST];
1030
+ // Removing ON_CHANGE_TRACK_STATE_REQUEST native listener
1031
+ if (subscription) {
1032
+ subscription.remove();
1033
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST] = undefined;
1034
+ }
1035
+ // Removing App Delegate listener
1036
+ this.onChangeTrackStateRequestDelegate = null;
1037
+ break;
1038
+ }
791
1039
  case HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM:
792
- this.onRemovedFromRoomDelegate = null;
793
- break;
1040
+ {
1041
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM];
1042
+ // Removing ON_REMOVED_FROM_ROOM native listener
1043
+ if (subscription) {
1044
+ subscription.remove();
1045
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM] = undefined;
1046
+ }
1047
+ // Removing App Delegate listener
1048
+ this.onRemovedFromRoomDelegate = null;
1049
+ break;
1050
+ }
794
1051
  case HMSUpdateListenerActions.ON_RTC_STATS:
795
- this.onRtcStatsDelegate = null;
796
- break;
1052
+ {
1053
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_RTC_STATS];
1054
+ // Removing ON_RTC_STATS native listener
1055
+ if (subscription) {
1056
+ subscription.remove();
1057
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_RTC_STATS] = undefined;
1058
+ }
1059
+ // Removing App Delegate listener
1060
+ this.onRtcStatsDelegate = null;
1061
+ break;
1062
+ }
797
1063
  case HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS:
798
- this.onLocalAudioStatsDelegate = null;
799
- break;
1064
+ {
1065
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS];
1066
+ // Removing ON_LOCAL_AUDIO_STATS native listener
1067
+ if (subscription) {
1068
+ subscription.remove();
1069
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS] = undefined;
1070
+ }
1071
+ // Removing App Delegate listener
1072
+ this.onLocalAudioStatsDelegate = null;
1073
+ break;
1074
+ }
800
1075
  case HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS:
801
- this.onLocalVideoStatsDelegate = null;
802
- break;
1076
+ {
1077
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS];
1078
+ // Removing ON_LOCAL_VIDEO_STATS native listener
1079
+ if (subscription) {
1080
+ subscription.remove();
1081
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS] = undefined;
1082
+ }
1083
+ // Removing App Delegate listener
1084
+ this.onLocalVideoStatsDelegate = null;
1085
+ break;
1086
+ }
803
1087
  case HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS:
804
- this.onRemoteAudioStatsDelegate = null;
805
- break;
1088
+ {
1089
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS];
1090
+ // Removing ON_REMOTE_AUDIO_STATS native listener
1091
+ if (subscription) {
1092
+ subscription.remove();
1093
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS] = undefined;
1094
+ }
1095
+ // Removing App Delegate listener
1096
+ this.onRemoteAudioStatsDelegate = null;
1097
+ break;
1098
+ }
806
1099
  case HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS:
807
- this.onRemoteVideoStatsDelegate = null;
808
- break;
1100
+ {
1101
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS];
1102
+ // Removing ON_REMOTE_VIDEO_STATS native listener
1103
+ if (subscription) {
1104
+ subscription.remove();
1105
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS] = undefined;
1106
+ }
1107
+ // Removing App Delegate listener
1108
+ this.onRemoteVideoStatsDelegate = null;
1109
+ break;
1110
+ }
809
1111
  case HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED:
810
- this.onAudioDeviceChangedDelegate = null;
811
- break;
1112
+ {
1113
+ const subscription = this.emitterSubscriptions[HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED];
1114
+ // Removing ON_AUDIO_DEVICE_CHANGED native listener
1115
+ if (subscription) {
1116
+ subscription.remove();
1117
+ this.emitterSubscriptions[HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED] = undefined;
1118
+ }
1119
+ // Removing App Delegate listener
1120
+ this.onAudioDeviceChangedDelegate = null;
1121
+ break;
1122
+ }
812
1123
  case HMSPIPListenerActions.ON_PIP_ROOM_LEAVE:
813
- this.onPIPRoomLeaveDelegate = null;
814
- break;
1124
+ {
1125
+ if (Platform.OS === 'android') {
1126
+ const subscription = this.emitterSubscriptions[HMSPIPListenerActions.ON_PIP_ROOM_LEAVE];
1127
+ // Removing ON_PIP_ROOM_LEAVE native listener
1128
+ if (subscription) {
1129
+ subscription.remove();
1130
+ this.emitterSubscriptions[HMSPIPListenerActions.ON_PIP_ROOM_LEAVE] = undefined;
1131
+ }
1132
+ // Removing App Delegate listener
1133
+ this.onPIPRoomLeaveDelegate = null;
1134
+ }
1135
+ break;
1136
+ }
815
1137
  default:
816
1138
  }
817
1139
  });
@@ -830,6 +1152,14 @@ export class HMSSDK {
830
1152
  this.onChangeTrackStateRequestDelegate = null;
831
1153
  this.onRemovedFromRoomDelegate = null;
832
1154
  this.onPIPRoomLeaveDelegate = null;
1155
+
1156
+ // Getting list of all available `emitterSubscription` objects
1157
+ Object.values(this.emitterSubscriptions).filter(Boolean).forEach(emitterSubscription => {
1158
+ emitterSubscription.remove();
1159
+ });
1160
+
1161
+ // clearing reference of all `emitterSubscription` objects
1162
+ this.emitterSubscriptions = {};
833
1163
  logger === null || logger === void 0 ? void 0 : logger.verbose('#Function REMOVE_ALL_LISTENER', {
834
1164
  id: this.id
835
1165
  });
@@ -975,6 +1305,7 @@ export class HMSSDK {
975
1305
  if (data.id !== this.id) {
976
1306
  return;
977
1307
  }
1308
+ this.roomLeaveCleanup();
978
1309
  if (this.onRemovedFromRoomDelegate) {
979
1310
  let requestedBy = null;
980
1311
  if (data.requestedBy) {
@@ -1127,12 +1458,10 @@ export class HMSSDK {
1127
1458
  }
1128
1459
  });
1129
1460
  _defineProperty(this, "onPIPRoomLeaveListener", data => {
1130
- var _this$appStateSubscri2;
1131
1461
  if (data.id !== this.id) {
1132
1462
  return;
1133
1463
  }
1134
- this.muteStatus = undefined;
1135
- this === null || this === void 0 ? void 0 : (_this$appStateSubscri2 = this.appStateSubscription) === null || _this$appStateSubscri2 === void 0 ? void 0 : _this$appStateSubscri2.remove();
1464
+ this.roomLeaveCleanup();
1136
1465
  if (this.onPIPRoomLeaveDelegate) {
1137
1466
  logger === null || logger === void 0 ? void 0 : logger.verbose('#Listener onPIPRoomLeave_CALL', data);
1138
1467
  this.onPIPRoomLeaveDelegate({
@@ -1182,7 +1511,6 @@ export class HMSSDK {
1182
1511
  logSettings: params === null || params === void 0 ? void 0 : params.logSettings
1183
1512
  });
1184
1513
  HmsSdk = new HMSSDK(id);
1185
- HmsSdk.attachListeners();
1186
1514
  return HmsSdk;
1187
1515
  }
1188
1516