@100mslive/react-native-hms 1.1.1 → 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 +1 -1
  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 +5 -4
  84. package/react-native-hms.podspec +1 -1
  85. package/sdk-versions.json +3 -2
  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
@@ -18,6 +18,7 @@ var _HMSUpdateListenerActions = require("./HMSUpdateListenerActions");
18
18
  var _HmsView = require("./HmsView");
19
19
  var _HMSMessageType = require("./HMSMessageType");
20
20
  var _HMSPIPListenerActions = require("./HMSPIPListenerActions");
21
+ var _HMSNativeEventEmitter = require("./HMSNativeEventEmitter");
21
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
23
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
24
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
@@ -29,7 +30,7 @@ const {
29
30
  HMSManager
30
31
  } = _reactNative.NativeModules;
31
32
  const ReactNativeVersion = require('react-native/Libraries/Core/ReactNativeVersion');
32
- const HmsEventEmitter = new _reactNative.NativeEventEmitter(HMSManager);
33
+ const HmsEventEmitter = new _HMSNativeEventEmitter.HMSNativeEventEmitter(HMSManager);
33
34
  let HmsSdk;
34
35
  class HMSSDK {
35
36
  constructor(id) {
@@ -57,6 +58,7 @@ class HMSSDK {
57
58
  _defineProperty(this, "onRemoteVideoStatsDelegate", void 0);
58
59
  _defineProperty(this, "onAudioDeviceChangedDelegate", void 0);
59
60
  _defineProperty(this, "onPIPRoomLeaveDelegate", void 0);
61
+ _defineProperty(this, "emitterSubscriptions", {});
60
62
  _defineProperty(this, "setLogger", hmsLogger => {
61
63
  (0, _HMSLogger.setLogger)(this.id, hmsLogger);
62
64
  });
@@ -64,59 +66,11 @@ class HMSSDK {
64
66
  _HMSLogger.logger === null || _HMSLogger.logger === void 0 ? void 0 : _HMSLogger.logger.verbose('#Function destroy', {
65
67
  id: this.id
66
68
  });
67
- this.removeListeners();
69
+ this.removeAllListeners();
68
70
  return await HMSManager.destroy({
69
71
  id: this.id
70
72
  });
71
73
  });
72
- _defineProperty(this, "attachListeners", () => {
73
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW, this.onPreviewListener);
74
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN, this.onJoinListener);
75
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE, this.onRoomListener);
76
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE, this.onPeerListener);
77
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE, this.onTrackListener);
78
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR, this.onErrorListener);
79
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE, this.onMessageListener);
80
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER, this.onSpeakerListener);
81
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING, this.reconnectingListener);
82
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED, this.reconnectedListener);
83
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST, this.onRoleChangeRequestListener);
84
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST, this.onChangeTrackStateRequestListener);
85
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM, this.onRemovedFromRoomListener);
86
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS, this.RTCStatsListener);
87
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS, this.onLocalAudioStatsListener);
88
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS, this.onLocalVideoStatsListener);
89
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS, this.onRemoteAudioStatsListener);
90
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS, this.onRemoteVideoStatsListener);
91
- HmsEventEmitter.addListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED, this.onAudioDeviceChangedListener);
92
- if (_reactNative.Platform.OS === 'android') {
93
- HmsEventEmitter.addListener(_HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE, this.onPIPRoomLeaveListener);
94
- }
95
- });
96
- _defineProperty(this, "removeListeners", () => {
97
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN, this.onJoinListener);
98
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW, this.onPreviewListener);
99
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE, this.onRoomListener);
100
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE, this.onPeerListener);
101
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE, this.onTrackListener);
102
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR, this.onErrorListener);
103
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE, this.onMessageListener);
104
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER, this.onSpeakerListener);
105
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING, this.reconnectingListener);
106
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED, this.reconnectedListener);
107
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST, this.onRoleChangeRequestListener);
108
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST, this.onChangeTrackStateRequestListener);
109
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM, this.onRemovedFromRoomListener);
110
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS, this.RTCStatsListener);
111
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS, this.onLocalAudioStatsListener);
112
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS, this.onLocalVideoStatsListener);
113
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS, this.onRemoteAudioStatsListener);
114
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS, this.onRemoteVideoStatsListener);
115
- HmsEventEmitter.removeListener(_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED, this.onAudioDeviceChangedListener);
116
- if (_reactNative.Platform.OS === 'android') {
117
- HmsEventEmitter.removeListener(_HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE, this.onPIPRoomLeaveListener);
118
- }
119
- });
120
74
  _defineProperty(this, "join", async config => {
121
75
  _HMSLogger.logger === null || _HMSLogger.logger === void 0 ? void 0 : _HMSLogger.logger.verbose('#Function join', {
122
76
  config,
@@ -171,8 +125,13 @@ class HMSSDK {
171
125
  id: this.id
172
126
  });
173
127
  }));
174
- _defineProperty(this, "leave", async () => {
128
+ _defineProperty(this, "roomLeaveCleanup", () => {
175
129
  var _this$appStateSubscri;
130
+ this.muteStatus = undefined;
131
+ this === null || this === void 0 ? void 0 : (_this$appStateSubscri = this.appStateSubscription) === null || _this$appStateSubscri === void 0 ? void 0 : _this$appStateSubscri.remove();
132
+ _HMSEncoder.HMSEncoder.clearData(); // Clearing cached data in encoder
133
+ });
134
+ _defineProperty(this, "leave", async () => {
176
135
  _HMSLogger.logger === null || _HMSLogger.logger === void 0 ? void 0 : _HMSLogger.logger.verbose('#Function leave', {
177
136
  id: this.id
178
137
  });
@@ -180,8 +139,7 @@ class HMSSDK {
180
139
  id: this.id
181
140
  };
182
141
  const op = await HMSManager.leave(data);
183
- this.muteStatus = undefined;
184
- this === null || this === void 0 ? void 0 : (_this$appStateSubscri = this.appStateSubscription) === null || _this$appStateSubscri === void 0 ? void 0 : _this$appStateSubscri.remove();
142
+ this.roomLeaveCleanup();
185
143
  return op;
186
144
  });
187
145
  _defineProperty(this, "sendBroadcastMessage", async function (message) {
@@ -691,65 +649,247 @@ class HMSSDK {
691
649
  });
692
650
  switch (action) {
693
651
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW:
694
- this.onPreviewDelegate = callback;
695
- break;
652
+ {
653
+ // Checking if we already have ON_PREVIEW subscription
654
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW]) {
655
+ // Adding ON_PREVIEW native listener
656
+ const previewSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW, this.onPreviewListener);
657
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW] = previewSubscription;
658
+ }
659
+ // Adding App Delegate listener
660
+ this.onPreviewDelegate = callback;
661
+ break;
662
+ }
696
663
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN:
697
- this.onJoinDelegate = callback;
698
- break;
664
+ {
665
+ // Checking if we already have ON_JOIN subscription
666
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN]) {
667
+ // Adding ON_JOIN native listener
668
+ const joinSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN, this.onJoinListener);
669
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN] = joinSubscription;
670
+ }
671
+ // Adding App Delegate listener
672
+ this.onJoinDelegate = callback;
673
+ break;
674
+ }
699
675
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE:
700
- this.onRoomDelegate = callback;
701
- break;
676
+ {
677
+ // Checking if we already have ON_ROOM_UPDATE subscription
678
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE]) {
679
+ // Adding ON_ROOM_UPDATE native listener
680
+ const roomSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE, this.onRoomListener);
681
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE] = roomSubscription;
682
+ }
683
+ // Adding App Delegate listener
684
+ this.onRoomDelegate = callback;
685
+ break;
686
+ }
702
687
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE:
703
- this.onPeerDelegate = callback;
704
- break;
688
+ {
689
+ // Checking if we already have ON_PEER_UPDATE subscription
690
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE]) {
691
+ // Adding ON_PEER_UPDATE native listener
692
+ const peerSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE, this.onPeerListener);
693
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE] = peerSubscription;
694
+ }
695
+ // Adding App Delegate listener
696
+ this.onPeerDelegate = callback;
697
+ break;
698
+ }
705
699
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE:
706
- this.onTrackDelegate = callback;
707
- break;
700
+ {
701
+ // Checking if we already have ON_TRACK_UPDATE subscription
702
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE]) {
703
+ // Adding ON_TRACK_UPDATE native listener
704
+ const trackSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE, this.onTrackListener);
705
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE] = trackSubscription;
706
+ }
707
+ // Adding App Delegate listener
708
+ this.onTrackDelegate = callback;
709
+ break;
710
+ }
708
711
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR:
709
- this.onErrorDelegate = callback;
710
- break;
712
+ {
713
+ // Checking if we already have ON_ERROR subscription
714
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR]) {
715
+ // Adding ON_ERROR native listener
716
+ const errorSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR, this.onErrorListener);
717
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR] = errorSubscription;
718
+ }
719
+ // Adding App Delegate listener
720
+ this.onErrorDelegate = callback;
721
+ break;
722
+ }
711
723
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE:
712
- this.onMessageDelegate = callback;
713
- break;
724
+ {
725
+ // Checking if we already have ON_MESSAGE subscription
726
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE]) {
727
+ // Adding ON_MESSAGE native listener
728
+ const messageSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE, this.onMessageListener);
729
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE] = messageSubscription;
730
+ }
731
+ // Adding App Delegate listener
732
+ this.onMessageDelegate = callback;
733
+ break;
734
+ }
714
735
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER:
715
- this.onSpeakerDelegate = callback;
716
- break;
736
+ {
737
+ // Checking if we already have ON_SPEAKER subscription
738
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER]) {
739
+ // Adding ON_SPEAKER native listener
740
+ const speakerSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER, this.onSpeakerListener);
741
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER] = speakerSubscription;
742
+ }
743
+ // Adding App Delegate listener
744
+ this.onSpeakerDelegate = callback;
745
+ break;
746
+ }
717
747
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING:
718
- this.onReconnectingDelegate = callback;
719
- break;
748
+ {
749
+ // Checking if we already have RECONNECTING subscription
750
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING]) {
751
+ // Adding RECONNECTING native listener
752
+ const reconnectingSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING, this.reconnectingListener);
753
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING] = reconnectingSubscription;
754
+ }
755
+ // Adding App Delegate listener
756
+ this.onReconnectingDelegate = callback;
757
+ break;
758
+ }
720
759
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED:
721
- this.onReconnectedDelegate = callback;
722
- break;
760
+ {
761
+ // Checking if we already have RECONNECTED subscription
762
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED]) {
763
+ // Adding RECONNECTED native listener
764
+ const reconnectedSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED, this.reconnectedListener);
765
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED] = reconnectedSubscription;
766
+ }
767
+ // Adding App Delegate listener
768
+ this.onReconnectedDelegate = callback;
769
+ break;
770
+ }
723
771
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST:
724
- this.onRoleChangeRequestDelegate = callback;
725
- break;
772
+ {
773
+ // Checking if we already have ON_ROLE_CHANGE_REQUEST subscription
774
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST]) {
775
+ // Adding ON_ROLE_CHANGE_REQUEST native listener
776
+ const roleChangeReqSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST, this.onRoleChangeRequestListener);
777
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST] = roleChangeReqSubscription;
778
+ }
779
+ // Adding App Delegate listener
780
+ this.onRoleChangeRequestDelegate = callback;
781
+ break;
782
+ }
726
783
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST:
727
- this.onChangeTrackStateRequestDelegate = callback;
728
- break;
784
+ {
785
+ // Checking if we already have ON_CHANGE_TRACK_STATE_REQUEST subscription
786
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST]) {
787
+ // Adding ON_CHANGE_TRACK_STATE_REQUEST native listener
788
+ const changeTrackReqSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST, this.onChangeTrackStateRequestListener);
789
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST] = changeTrackReqSubscription;
790
+ }
791
+ // Adding App Delegate listener
792
+ this.onChangeTrackStateRequestDelegate = callback;
793
+ break;
794
+ }
729
795
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM:
730
- this.onRemovedFromRoomDelegate = callback;
731
- break;
796
+ {
797
+ // Checking if we already have ON_REMOVED_FROM_ROOM subscription
798
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM]) {
799
+ // Adding ON_REMOVED_FROM_ROOM native listener
800
+ const removedFromRoomSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM, this.onRemovedFromRoomListener);
801
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM] = removedFromRoomSubscription;
802
+ }
803
+ // Adding App Delegate listener
804
+ this.onRemovedFromRoomDelegate = callback;
805
+ break;
806
+ }
732
807
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS:
733
- this.onRtcStatsDelegate = callback;
734
- break;
808
+ {
809
+ // Checking if we already have ON_RTC_STATS subscription
810
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS]) {
811
+ // Adding ON_RTC_STATS native listener
812
+ const rtcStatsSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS, this.RTCStatsListener);
813
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS] = rtcStatsSubscription;
814
+ }
815
+ // Adding App Delegate listener
816
+ this.onRtcStatsDelegate = callback;
817
+ break;
818
+ }
735
819
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS:
736
- this.onLocalAudioStatsDelegate = callback;
737
- break;
820
+ {
821
+ // Checking if we already have ON_LOCAL_AUDIO_STATS subscription
822
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS]) {
823
+ // Adding ON_LOCAL_AUDIO_STATS native listener
824
+ const lclAudioStatsSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS, this.onLocalAudioStatsListener);
825
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS] = lclAudioStatsSubscription;
826
+ }
827
+ // Adding App Delegate listener
828
+ this.onLocalAudioStatsDelegate = callback;
829
+ break;
830
+ }
738
831
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS:
739
- this.onLocalVideoStatsDelegate = callback;
740
- break;
832
+ {
833
+ // Checking if we already have ON_LOCAL_VIDEO_STATS subscription
834
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS]) {
835
+ // Adding ON_LOCAL_VIDEO_STATS native listener
836
+ const lclVideoStatsSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS, this.onLocalVideoStatsListener);
837
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS] = lclVideoStatsSubscription;
838
+ }
839
+ // Adding App Delegate listener
840
+ this.onLocalVideoStatsDelegate = callback;
841
+ break;
842
+ }
741
843
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS:
742
- this.onRemoteAudioStatsDelegate = callback;
743
- break;
844
+ {
845
+ // Checking if we already have ON_REMOTE_AUDIO_STATS subscription
846
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS]) {
847
+ // Adding ON_REMOTE_AUDIO_STATS native listener
848
+ const rmAudioStatsSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS, this.onRemoteAudioStatsListener);
849
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS] = rmAudioStatsSubscription;
850
+ }
851
+ // Adding App Delegate listener
852
+ this.onRemoteAudioStatsDelegate = callback;
853
+ break;
854
+ }
744
855
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS:
745
- this.onRemoteVideoStatsDelegate = callback;
746
- break;
856
+ {
857
+ // Checking if we already have ON_REMOTE_VIDEO_STATS subscription
858
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS]) {
859
+ // Adding ON_REMOTE_VIDEO_STATS native listener
860
+ const rmVideoStatsSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS, this.onRemoteVideoStatsListener);
861
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS] = rmVideoStatsSubscription;
862
+ }
863
+ // Adding App Delegate listener
864
+ this.onRemoteVideoStatsDelegate = callback;
865
+ break;
866
+ }
747
867
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED:
748
- this.onAudioDeviceChangedDelegate = callback;
749
- break;
868
+ {
869
+ // Checking if we already have ON_AUDIO_DEVICE_CHANGED subscription
870
+ if (!this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED]) {
871
+ // Adding ON_AUDIO_DEVICE_CHANGED native listener
872
+ const audDeviceChgSubscription = HmsEventEmitter.addListener(this.id, _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED, this.onAudioDeviceChangedListener);
873
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED] = audDeviceChgSubscription;
874
+ }
875
+ // Adding App Delegate listener
876
+ this.onAudioDeviceChangedDelegate = callback;
877
+ break;
878
+ }
750
879
  case _HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE:
751
- this.onPIPRoomLeaveDelegate = callback;
752
- break;
880
+ {
881
+ if (_reactNative.Platform.OS === 'android') {
882
+ // Checking if we already have ON_PIP_ROOM_LEAVE subscription
883
+ if (!this.emitterSubscriptions[_HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE]) {
884
+ // Adding ON_PIP_ROOM_LEAVE native listener
885
+ const pipRoomLeaveSubscription = HmsEventEmitter.addListener(this.id, _HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE, this.onPIPRoomLeaveListener);
886
+ this.emitterSubscriptions[_HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE] = pipRoomLeaveSubscription;
887
+ }
888
+ // Adding App Delegate listener
889
+ this.onPIPRoomLeaveDelegate = callback;
890
+ }
891
+ break;
892
+ }
753
893
  default:
754
894
  }
755
895
  });
@@ -760,65 +900,247 @@ class HMSSDK {
760
900
  });
761
901
  switch (action) {
762
902
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW:
763
- this.onPreviewDelegate = null;
764
- break;
903
+ {
904
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW];
905
+ // Removing ON_PREVIEW native listener
906
+ if (subscription) {
907
+ subscription.remove();
908
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PREVIEW] = undefined;
909
+ }
910
+ // Removing App Delegate listener
911
+ this.onPreviewDelegate = null;
912
+ break;
913
+ }
765
914
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN:
766
- this.onJoinDelegate = null;
767
- break;
915
+ {
916
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN];
917
+ // Removing ON_JOIN native listener
918
+ if (subscription) {
919
+ subscription.remove();
920
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_JOIN] = undefined;
921
+ }
922
+ // Removing App Delegate listener
923
+ this.onJoinDelegate = null;
924
+ break;
925
+ }
768
926
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE:
769
- this.onRoomDelegate = null;
770
- break;
927
+ {
928
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE];
929
+ // Removing ON_ROOM_UPDATE native listener
930
+ if (subscription) {
931
+ subscription.remove();
932
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROOM_UPDATE] = undefined;
933
+ }
934
+ // Removing App Delegate listener
935
+ this.onRoomDelegate = null;
936
+ break;
937
+ }
771
938
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE:
772
- this.onPeerDelegate = null;
773
- break;
939
+ {
940
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE];
941
+ // Removing ON_PEER_UPDATE native listener
942
+ if (subscription) {
943
+ subscription.remove();
944
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_PEER_UPDATE] = undefined;
945
+ }
946
+ // Removing App Delegate listener
947
+ this.onPeerDelegate = null;
948
+ break;
949
+ }
774
950
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE:
775
- this.onTrackDelegate = null;
776
- break;
951
+ {
952
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE];
953
+ // Removing ON_TRACK_UPDATE native listener
954
+ if (subscription) {
955
+ subscription.remove();
956
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_TRACK_UPDATE] = undefined;
957
+ }
958
+ // Removing App Delegate listener
959
+ this.onTrackDelegate = null;
960
+ break;
961
+ }
777
962
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR:
778
- this.onErrorDelegate = null;
779
- break;
963
+ {
964
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR];
965
+ // Removing ON_ERROR native listener
966
+ if (subscription) {
967
+ subscription.remove();
968
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ERROR] = undefined;
969
+ }
970
+ // Removing App Delegate listener
971
+ this.onErrorDelegate = null;
972
+ break;
973
+ }
780
974
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE:
781
- this.onMessageDelegate = null;
782
- break;
975
+ {
976
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE];
977
+ // Removing ON_MESSAGE native listener
978
+ if (subscription) {
979
+ subscription.remove();
980
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_MESSAGE] = undefined;
981
+ }
982
+ // Removing App Delegate listener
983
+ this.onMessageDelegate = null;
984
+ break;
985
+ }
783
986
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER:
784
- this.onSpeakerDelegate = null;
785
- break;
987
+ {
988
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER];
989
+ // Removing ON_SPEAKER native listener
990
+ if (subscription) {
991
+ subscription.remove();
992
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_SPEAKER] = undefined;
993
+ }
994
+ // Removing App Delegate listener
995
+ this.onSpeakerDelegate = null;
996
+ break;
997
+ }
786
998
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING:
787
- this.onReconnectingDelegate = null;
788
- break;
999
+ {
1000
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING];
1001
+ // Removing RECONNECTING native listener
1002
+ if (subscription) {
1003
+ subscription.remove();
1004
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTING] = undefined;
1005
+ }
1006
+ // Removing App Delegate listener
1007
+ this.onReconnectingDelegate = null;
1008
+ break;
1009
+ }
789
1010
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED:
790
- this.onReconnectedDelegate = null;
791
- break;
1011
+ {
1012
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED];
1013
+ // Removing RECONNECTED native listener
1014
+ if (subscription) {
1015
+ subscription.remove();
1016
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.RECONNECTED] = undefined;
1017
+ }
1018
+ // Removing App Delegate listener
1019
+ this.onReconnectedDelegate = null;
1020
+ break;
1021
+ }
792
1022
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST:
793
- this.onRoleChangeRequestDelegate = null;
794
- break;
1023
+ {
1024
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST];
1025
+ // Removing ON_ROLE_CHANGE_REQUEST native listener
1026
+ if (subscription) {
1027
+ subscription.remove();
1028
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_ROLE_CHANGE_REQUEST] = undefined;
1029
+ }
1030
+ // Removing App Delegate listener
1031
+ this.onRoleChangeRequestDelegate = null;
1032
+ break;
1033
+ }
795
1034
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST:
796
- this.onChangeTrackStateRequestDelegate = null;
797
- break;
1035
+ {
1036
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST];
1037
+ // Removing ON_CHANGE_TRACK_STATE_REQUEST native listener
1038
+ if (subscription) {
1039
+ subscription.remove();
1040
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_CHANGE_TRACK_STATE_REQUEST] = undefined;
1041
+ }
1042
+ // Removing App Delegate listener
1043
+ this.onChangeTrackStateRequestDelegate = null;
1044
+ break;
1045
+ }
798
1046
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM:
799
- this.onRemovedFromRoomDelegate = null;
800
- break;
1047
+ {
1048
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM];
1049
+ // Removing ON_REMOVED_FROM_ROOM native listener
1050
+ if (subscription) {
1051
+ subscription.remove();
1052
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM] = undefined;
1053
+ }
1054
+ // Removing App Delegate listener
1055
+ this.onRemovedFromRoomDelegate = null;
1056
+ break;
1057
+ }
801
1058
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS:
802
- this.onRtcStatsDelegate = null;
803
- break;
1059
+ {
1060
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS];
1061
+ // Removing ON_RTC_STATS native listener
1062
+ if (subscription) {
1063
+ subscription.remove();
1064
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_RTC_STATS] = undefined;
1065
+ }
1066
+ // Removing App Delegate listener
1067
+ this.onRtcStatsDelegate = null;
1068
+ break;
1069
+ }
804
1070
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS:
805
- this.onLocalAudioStatsDelegate = null;
806
- break;
1071
+ {
1072
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS];
1073
+ // Removing ON_LOCAL_AUDIO_STATS native listener
1074
+ if (subscription) {
1075
+ subscription.remove();
1076
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_AUDIO_STATS] = undefined;
1077
+ }
1078
+ // Removing App Delegate listener
1079
+ this.onLocalAudioStatsDelegate = null;
1080
+ break;
1081
+ }
807
1082
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS:
808
- this.onLocalVideoStatsDelegate = null;
809
- break;
1083
+ {
1084
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS];
1085
+ // Removing ON_LOCAL_VIDEO_STATS native listener
1086
+ if (subscription) {
1087
+ subscription.remove();
1088
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_LOCAL_VIDEO_STATS] = undefined;
1089
+ }
1090
+ // Removing App Delegate listener
1091
+ this.onLocalVideoStatsDelegate = null;
1092
+ break;
1093
+ }
810
1094
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS:
811
- this.onRemoteAudioStatsDelegate = null;
812
- break;
1095
+ {
1096
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS];
1097
+ // Removing ON_REMOTE_AUDIO_STATS native listener
1098
+ if (subscription) {
1099
+ subscription.remove();
1100
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_AUDIO_STATS] = undefined;
1101
+ }
1102
+ // Removing App Delegate listener
1103
+ this.onRemoteAudioStatsDelegate = null;
1104
+ break;
1105
+ }
813
1106
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS:
814
- this.onRemoteVideoStatsDelegate = null;
815
- break;
1107
+ {
1108
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS];
1109
+ // Removing ON_REMOTE_VIDEO_STATS native listener
1110
+ if (subscription) {
1111
+ subscription.remove();
1112
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_REMOTE_VIDEO_STATS] = undefined;
1113
+ }
1114
+ // Removing App Delegate listener
1115
+ this.onRemoteVideoStatsDelegate = null;
1116
+ break;
1117
+ }
816
1118
  case _HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED:
817
- this.onAudioDeviceChangedDelegate = null;
818
- break;
1119
+ {
1120
+ const subscription = this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED];
1121
+ // Removing ON_AUDIO_DEVICE_CHANGED native listener
1122
+ if (subscription) {
1123
+ subscription.remove();
1124
+ this.emitterSubscriptions[_HMSUpdateListenerActions.HMSUpdateListenerActions.ON_AUDIO_DEVICE_CHANGED] = undefined;
1125
+ }
1126
+ // Removing App Delegate listener
1127
+ this.onAudioDeviceChangedDelegate = null;
1128
+ break;
1129
+ }
819
1130
  case _HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE:
820
- this.onPIPRoomLeaveDelegate = null;
821
- break;
1131
+ {
1132
+ if (_reactNative.Platform.OS === 'android') {
1133
+ const subscription = this.emitterSubscriptions[_HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE];
1134
+ // Removing ON_PIP_ROOM_LEAVE native listener
1135
+ if (subscription) {
1136
+ subscription.remove();
1137
+ this.emitterSubscriptions[_HMSPIPListenerActions.HMSPIPListenerActions.ON_PIP_ROOM_LEAVE] = undefined;
1138
+ }
1139
+ // Removing App Delegate listener
1140
+ this.onPIPRoomLeaveDelegate = null;
1141
+ }
1142
+ break;
1143
+ }
822
1144
  default:
823
1145
  }
824
1146
  });
@@ -837,6 +1159,14 @@ class HMSSDK {
837
1159
  this.onChangeTrackStateRequestDelegate = null;
838
1160
  this.onRemovedFromRoomDelegate = null;
839
1161
  this.onPIPRoomLeaveDelegate = null;
1162
+
1163
+ // Getting list of all available `emitterSubscription` objects
1164
+ Object.values(this.emitterSubscriptions).filter(Boolean).forEach(emitterSubscription => {
1165
+ emitterSubscription.remove();
1166
+ });
1167
+
1168
+ // clearing reference of all `emitterSubscription` objects
1169
+ this.emitterSubscriptions = {};
840
1170
  _HMSLogger.logger === null || _HMSLogger.logger === void 0 ? void 0 : _HMSLogger.logger.verbose('#Function REMOVE_ALL_LISTENER', {
841
1171
  id: this.id
842
1172
  });
@@ -982,6 +1312,7 @@ class HMSSDK {
982
1312
  if (data.id !== this.id) {
983
1313
  return;
984
1314
  }
1315
+ this.roomLeaveCleanup();
985
1316
  if (this.onRemovedFromRoomDelegate) {
986
1317
  let requestedBy = null;
987
1318
  if (data.requestedBy) {
@@ -1134,12 +1465,10 @@ class HMSSDK {
1134
1465
  }
1135
1466
  });
1136
1467
  _defineProperty(this, "onPIPRoomLeaveListener", data => {
1137
- var _this$appStateSubscri2;
1138
1468
  if (data.id !== this.id) {
1139
1469
  return;
1140
1470
  }
1141
- this.muteStatus = undefined;
1142
- this === null || this === void 0 ? void 0 : (_this$appStateSubscri2 = this.appStateSubscription) === null || _this$appStateSubscri2 === void 0 ? void 0 : _this$appStateSubscri2.remove();
1471
+ this.roomLeaveCleanup();
1143
1472
  if (this.onPIPRoomLeaveDelegate) {
1144
1473
  _HMSLogger.logger === null || _HMSLogger.logger === void 0 ? void 0 : _HMSLogger.logger.verbose('#Listener onPIPRoomLeave_CALL', data);
1145
1474
  this.onPIPRoomLeaveDelegate({
@@ -1189,7 +1518,6 @@ class HMSSDK {
1189
1518
  logSettings: params === null || params === void 0 ? void 0 : params.logSettings
1190
1519
  });
1191
1520
  HmsSdk = new HMSSDK(id);
1192
- HmsSdk.attachListeners();
1193
1521
  return HmsSdk;
1194
1522
  }
1195
1523