@100mslive/react-native-hms 1.3.0 → 1.5.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.
- package/README.md +59 -5
- package/android/build.gradle +3 -2
- package/android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt +189 -55
- package/android/src/main/java/com/reactnativehmssdk/HMSHelper.kt +1 -0
- package/android/src/main/java/com/reactnativehmssdk/HMSManager.kt +49 -14
- package/android/src/main/java/com/reactnativehmssdk/HMSRNSDK.kt +240 -46
- package/android/src/main/java/com/reactnativehmssdk/HMSSDKViewManager.kt +5 -0
- package/android/src/main/java/com/reactnativehmssdk/HMSView.kt +29 -21
- package/android/src/main/res/layout/hms_view.xml +2 -2
- package/ios/HMSConstants.swift +31 -0
- package/ios/HMSDecoder.swift +371 -156
- package/ios/HMSManager.m +10 -2
- package/ios/HMSManager.swift +149 -74
- package/ios/HMSRNSDK.swift +431 -181
- package/ios/HMSView.m +1 -0
- package/ios/HMSView.swift +21 -19
- package/lib/commonjs/classes/HMSAudioTrackSettings.js +1 -1
- package/lib/commonjs/classes/HMSAudioTrackSettings.js.map +1 -1
- package/lib/commonjs/classes/HMSCameraControl.js +28 -0
- package/lib/commonjs/classes/HMSCameraControl.js.map +1 -0
- package/lib/commonjs/classes/HMSEncoder.js +95 -13
- package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
- package/lib/commonjs/classes/HMSException.js +3 -4
- package/lib/commonjs/classes/HMSException.js.map +1 -1
- package/lib/commonjs/classes/HMSLayer.js +14 -0
- package/lib/commonjs/classes/HMSLayer.js.map +1 -0
- package/lib/commonjs/classes/HMSLocalVideoStats.js +11 -0
- package/lib/commonjs/classes/HMSLocalVideoStats.js.map +1 -1
- package/lib/commonjs/classes/HMSLocalVideoTrack.js +5 -6
- package/lib/commonjs/classes/HMSLocalVideoTrack.js.map +1 -1
- package/lib/commonjs/classes/HMSMessage.js +1 -2
- package/lib/commonjs/classes/HMSMessage.js.map +1 -1
- package/lib/commonjs/classes/HMSPeer.js +3 -4
- package/lib/commonjs/classes/HMSPeer.js.map +1 -1
- package/lib/commonjs/classes/HMSPublishSettings.js +2 -0
- package/lib/commonjs/classes/HMSPublishSettings.js.map +1 -1
- package/lib/commonjs/classes/HMSQualityLimitationReason.js +16 -0
- package/lib/commonjs/classes/HMSQualityLimitationReason.js.map +1 -0
- package/lib/commonjs/classes/HMSQualityLimitationReasons.js +27 -0
- package/lib/commonjs/classes/HMSQualityLimitationReasons.js.map +1 -0
- package/lib/commonjs/classes/HMSRemotePeer.js.map +1 -1
- package/lib/commonjs/classes/HMSRemoteVideoTrack.js +39 -4
- package/lib/commonjs/classes/HMSRemoteVideoTrack.js.map +1 -1
- package/lib/commonjs/classes/HMSRoom.js +4 -0
- package/lib/commonjs/classes/HMSRoom.js.map +1 -1
- package/lib/commonjs/classes/HMSRoomUpdate.js +1 -0
- package/lib/commonjs/classes/HMSRoomUpdate.js.map +1 -1
- package/lib/commonjs/classes/HMSSDK.js +70 -62
- package/lib/commonjs/classes/HMSSDK.js.map +1 -1
- package/lib/commonjs/classes/HMSSimulcastLayerDefinition.js +19 -0
- package/lib/commonjs/classes/HMSSimulcastLayerDefinition.js.map +1 -0
- package/lib/commonjs/classes/HMSSimulcastLayerSettingsPolicy.js +23 -0
- package/lib/commonjs/classes/HMSSimulcastLayerSettingsPolicy.js.map +1 -0
- package/lib/commonjs/classes/HMSSimulcastSettings.js +5 -4
- package/lib/commonjs/classes/HMSSimulcastSettings.js.map +1 -1
- package/lib/commonjs/classes/HMSSimulcastSettingsPolicy.js +17 -0
- package/lib/commonjs/classes/HMSSimulcastSettingsPolicy.js.map +1 -0
- package/lib/commonjs/classes/HMSSubscribeDegradationPolicy.js +21 -0
- package/lib/commonjs/classes/HMSSubscribeDegradationPolicy.js.map +1 -0
- package/lib/commonjs/classes/HMSSubscribeSettings.js +2 -0
- package/lib/commonjs/classes/HMSSubscribeSettings.js.map +1 -1
- package/lib/commonjs/classes/HMSVideoResolution.js.map +1 -1
- package/lib/commonjs/classes/HMSVideoTrackSettings.js +1 -1
- package/lib/commonjs/classes/HMSVideoTrackSettings.js.map +1 -1
- package/lib/commonjs/classes/HmsView.js +2 -0
- package/lib/commonjs/classes/HmsView.js.map +1 -1
- package/lib/commonjs/index.js +60 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/classes/HMSAudioTrackSettings.js +1 -1
- package/lib/module/classes/HMSAudioTrackSettings.js.map +1 -1
- package/lib/module/classes/HMSCameraControl.js +21 -0
- package/lib/module/classes/HMSCameraControl.js.map +1 -0
- package/lib/module/classes/HMSEncoder.js +95 -13
- package/lib/module/classes/HMSEncoder.js.map +1 -1
- package/lib/module/classes/HMSException.js +3 -4
- package/lib/module/classes/HMSException.js.map +1 -1
- package/lib/module/classes/HMSLayer.js +7 -0
- package/lib/module/classes/HMSLayer.js.map +1 -0
- package/lib/module/classes/HMSLocalVideoStats.js +11 -0
- package/lib/module/classes/HMSLocalVideoStats.js.map +1 -1
- package/lib/module/classes/HMSLocalVideoTrack.js +5 -6
- package/lib/module/classes/HMSLocalVideoTrack.js.map +1 -1
- package/lib/module/classes/HMSMessage.js +1 -2
- package/lib/module/classes/HMSMessage.js.map +1 -1
- package/lib/module/classes/HMSPeer.js +3 -4
- package/lib/module/classes/HMSPeer.js.map +1 -1
- package/lib/module/classes/HMSPublishSettings.js +2 -0
- package/lib/module/classes/HMSPublishSettings.js.map +1 -1
- package/lib/module/classes/HMSQualityLimitationReason.js +9 -0
- package/lib/module/classes/HMSQualityLimitationReason.js.map +1 -0
- package/lib/module/classes/HMSQualityLimitationReasons.js +20 -0
- package/lib/module/classes/HMSQualityLimitationReasons.js.map +1 -0
- package/lib/module/classes/HMSRemotePeer.js.map +1 -1
- package/lib/module/classes/HMSRemoteVideoTrack.js +39 -4
- package/lib/module/classes/HMSRemoteVideoTrack.js.map +1 -1
- package/lib/module/classes/HMSRoom.js +4 -0
- package/lib/module/classes/HMSRoom.js.map +1 -1
- package/lib/module/classes/HMSRoomUpdate.js +1 -0
- package/lib/module/classes/HMSRoomUpdate.js.map +1 -1
- package/lib/module/classes/HMSSDK.js +71 -62
- package/lib/module/classes/HMSSDK.js.map +1 -1
- package/lib/module/classes/HMSSimulcastLayerDefinition.js +12 -0
- package/lib/module/classes/HMSSimulcastLayerDefinition.js.map +1 -0
- package/lib/module/classes/HMSSimulcastLayerSettingsPolicy.js +16 -0
- package/lib/module/classes/HMSSimulcastLayerSettingsPolicy.js.map +1 -0
- package/lib/module/classes/HMSSimulcastSettings.js +5 -4
- package/lib/module/classes/HMSSimulcastSettings.js.map +1 -1
- package/lib/module/classes/HMSSimulcastSettingsPolicy.js +10 -0
- package/lib/module/classes/HMSSimulcastSettingsPolicy.js.map +1 -0
- package/lib/module/classes/HMSSubscribeDegradationPolicy.js +14 -0
- package/lib/module/classes/HMSSubscribeDegradationPolicy.js.map +1 -0
- package/lib/module/classes/HMSSubscribeSettings.js +2 -0
- package/lib/module/classes/HMSSubscribeSettings.js.map +1 -1
- package/lib/module/classes/HMSVideoResolution.js.map +1 -1
- package/lib/module/classes/HMSVideoTrackSettings.js +1 -1
- package/lib/module/classes/HMSVideoTrackSettings.js.map +1 -1
- package/lib/module/classes/HmsView.js +2 -0
- package/lib/module/classes/HmsView.js.map +1 -1
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/classes/HMSCameraControl.d.ts +9 -0
- package/lib/typescript/classes/HMSEncoder.d.ts +13 -1
- package/lib/typescript/classes/HMSLayer.d.ts +5 -0
- package/lib/typescript/classes/HMSLocalVideoStats.d.ts +6 -0
- package/lib/typescript/classes/HMSPeer.d.ts +1 -1
- package/lib/typescript/classes/HMSPublishSettings.d.ts +3 -0
- package/lib/typescript/classes/HMSQualityLimitationReason.d.ts +7 -0
- package/lib/typescript/classes/HMSQualityLimitationReasons.d.ts +17 -0
- package/lib/typescript/classes/HMSRemotePeer.d.ts +0 -1
- package/lib/typescript/classes/HMSRemoteVideoTrack.d.ts +6 -2
- package/lib/typescript/classes/HMSRoomUpdate.d.ts +2 -1
- package/lib/typescript/classes/HMSSDK.d.ts +24 -42
- package/lib/typescript/classes/HMSSimulcastLayerDefinition.d.ts +10 -0
- package/lib/typescript/classes/HMSSimulcastLayerSettingsPolicy.d.ts +12 -0
- package/lib/typescript/classes/HMSSimulcastSettings.d.ts +7 -3
- package/lib/typescript/classes/HMSSimulcastSettingsPolicy.d.ts +7 -0
- package/lib/typescript/classes/HMSSubscribeDegradationPolicy.d.ts +10 -0
- package/lib/typescript/classes/HMSSubscribeSettings.d.ts +5 -2
- package/lib/typescript/classes/HMSVideoResolution.d.ts +2 -2
- package/lib/typescript/classes/HmsView.d.ts +2 -2
- package/lib/typescript/index.d.ts +5 -0
- package/package.json +2 -2
- package/sdk-versions.json +3 -3
- package/src/classes/HMSCameraControl.ts +21 -0
- package/src/classes/HMSEncoder.ts +125 -11
- package/src/classes/HMSLayer.ts +5 -0
- package/src/classes/HMSLocalVideoStats.ts +21 -0
- package/src/classes/HMSPeer.ts +1 -1
- package/src/classes/HMSPublishSettings.ts +4 -0
- package/src/classes/HMSQualityLimitationReason.ts +7 -0
- package/src/classes/HMSQualityLimitationReasons.ts +27 -0
- package/src/classes/HMSRemotePeer.ts +0 -1
- package/src/classes/HMSRemoteVideoTrack.ts +52 -4
- package/src/classes/HMSRoom.ts +2 -0
- package/src/classes/HMSRoomUpdate.ts +1 -0
- package/src/classes/HMSSDK.tsx +99 -67
- package/src/classes/HMSSimulcastLayerDefinition.ts +12 -0
- package/src/classes/HMSSimulcastLayerSettingsPolicy.ts +18 -0
- package/src/classes/HMSSimulcastSettings.ts +12 -3
- package/src/classes/HMSSimulcastSettingsPolicy.ts +9 -0
- package/src/classes/HMSSubscribeDegradationPolicy.ts +15 -0
- package/src/classes/HMSSubscribeSettings.ts +10 -2
- package/src/classes/HMSVideoResolution.ts +1 -1
- package/src/classes/HmsView.tsx +5 -1
- package/src/index.ts +5 -0
package/ios/HMSRNSDK.swift
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Hmssdk.swift
|
|
3
|
-
//
|
|
3
|
+
// HMSSDK
|
|
4
4
|
//
|
|
5
|
-
// Copyright ©
|
|
5
|
+
// Copyright © 2023 100ms. All rights reserved.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
8
|
import Foundation
|
|
@@ -16,7 +16,6 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
16
16
|
var recentRoleChangeRequest: HMSRoleChangeRequest?
|
|
17
17
|
var delegate: HMSManager?
|
|
18
18
|
var id: String = "12345"
|
|
19
|
-
var recentPreviewTracks: [HMSTrack]? = []
|
|
20
19
|
private var reconnectingStage: Bool = false
|
|
21
20
|
private var preferredExtension: String?
|
|
22
21
|
private var systemBroadcastPicker: RPSystemBroadcastPickerView?
|
|
@@ -24,28 +23,9 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
24
23
|
private var stopScreenshareResolve: RCTPromiseResolveBlock?
|
|
25
24
|
private var isScreenShared: Bool? = false
|
|
26
25
|
private var previewInProgress = false
|
|
27
|
-
private var rtcStatsAttached = false
|
|
28
26
|
private var networkQualityUpdatesAttached = false
|
|
29
27
|
private var eventsEnableStatus: [String: Bool] = [:]
|
|
30
28
|
|
|
31
|
-
let ON_PREVIEW = "ON_PREVIEW"
|
|
32
|
-
let ON_JOIN = "ON_JOIN"
|
|
33
|
-
let ON_ROOM_UPDATE = "ON_ROOM_UPDATE"
|
|
34
|
-
let ON_PEER_UPDATE = "3"
|
|
35
|
-
let ON_TRACK_UPDATE = "ON_TRACK_UPDATE"
|
|
36
|
-
let ON_ROLE_CHANGE_REQUEST = "ON_ROLE_CHANGE_REQUEST"
|
|
37
|
-
let ON_REMOVED_FROM_ROOM = "ON_REMOVED_FROM_ROOM"
|
|
38
|
-
let ON_ERROR = "ON_ERROR"
|
|
39
|
-
let ON_MESSAGE = "ON_MESSAGE"
|
|
40
|
-
let ON_SPEAKER = "ON_SPEAKER"
|
|
41
|
-
let RECONNECTING = "RECONNECTING"
|
|
42
|
-
let RECONNECTED = "RECONNECTED"
|
|
43
|
-
let ON_RTC_STATS = "ON_RTC_STATS"
|
|
44
|
-
let ON_LOCAL_AUDIO_STATS = "ON_LOCAL_AUDIO_STATS"
|
|
45
|
-
let ON_LOCAL_VIDEO_STATS = "ON_LOCAL_VIDEO_STATS"
|
|
46
|
-
let ON_REMOTE_AUDIO_STATS = "ON_REMOTE_AUDIO_STATS"
|
|
47
|
-
let ON_REMOTE_VIDEO_STATS = "ON_REMOTE_VIDEO_STATS"
|
|
48
|
-
|
|
49
29
|
// MARK: - Setup
|
|
50
30
|
init(data: NSDictionary?, delegate manager: HMSManager?, uid id: String) {
|
|
51
31
|
preferredExtension = data?.value(forKey: "preferredExtension") as? String
|
|
@@ -68,8 +48,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
68
48
|
func preview(_ credentials: NSDictionary) {
|
|
69
49
|
|
|
70
50
|
guard !previewInProgress else {
|
|
71
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
72
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 5000, "description": "Preview is in progress", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
51
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
52
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 5000, "description": "Preview is in progress", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
73
53
|
}
|
|
74
54
|
return
|
|
75
55
|
}
|
|
@@ -112,13 +92,12 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
112
92
|
if let extractedRole = roleObj {
|
|
113
93
|
hms?.preview(role: extractedRole, completion: { tracks, error in
|
|
114
94
|
if error != nil {
|
|
115
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
116
|
-
delegate?.emitEvent(ON_ERROR, ["error": HMSDecoder.getError(error), "id": id])
|
|
95
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
96
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": id])
|
|
117
97
|
}
|
|
118
98
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
119
99
|
return
|
|
120
100
|
}
|
|
121
|
-
self.recentPreviewTracks = tracks
|
|
122
101
|
|
|
123
102
|
let decodedTracks = HMSDecoder.getAllTracks(tracks ?? [])
|
|
124
103
|
|
|
@@ -129,15 +108,14 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
129
108
|
}
|
|
130
109
|
|
|
131
110
|
func cancelPreview() {
|
|
132
|
-
self.recentPreviewTracks = []
|
|
133
111
|
hms?.cancelPreview()
|
|
134
112
|
}
|
|
135
113
|
|
|
136
114
|
func join(_ credentials: NSDictionary) {
|
|
137
115
|
|
|
138
116
|
guard !previewInProgress else {
|
|
139
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
140
|
-
delegate?.emitEvent(
|
|
117
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
118
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 5000, "description": "Preview is in progress", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
141
119
|
}
|
|
142
120
|
return
|
|
143
121
|
}
|
|
@@ -169,6 +147,44 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
169
147
|
}
|
|
170
148
|
}
|
|
171
149
|
|
|
150
|
+
func getAuthTokenByRoomCode(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
151
|
+
guard let roomCode = data.value(forKey: "roomCode") as? String
|
|
152
|
+
else {
|
|
153
|
+
let errorMessage = "getAuthTokenByRoomCode: " + HMSHelper.getUnavailableRequiredKey(data, ["roomCode"])
|
|
154
|
+
reject?("40000", errorMessage, nil)
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
let userId = data.value(forKey: "userId") as? String? ?? nil
|
|
158
|
+
let endpoint = data.value(forKey: "endpoint") as? String? ?? nil
|
|
159
|
+
|
|
160
|
+
// This is to make the QA links work
|
|
161
|
+
if endpoint != nil && endpoint!.contains("nonprod") {
|
|
162
|
+
UserDefaults.standard.set(endpoint, forKey: "HMSAuthTokenEndpointOverride")
|
|
163
|
+
} else {
|
|
164
|
+
UserDefaults.standard.removeObject(forKey: "HMSAuthTokenEndpointOverride")
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
DispatchQueue.main.async { [weak self] in
|
|
168
|
+
self?.hms?.getAuthTokenByRoomCode(roomCode, userID: userId) { token, error in
|
|
169
|
+
// error occurred
|
|
170
|
+
if error != nil {
|
|
171
|
+
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
// no error and token is valid
|
|
175
|
+
else if token != nil {
|
|
176
|
+
resolve?(token)
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
// no error but token is null
|
|
180
|
+
else {
|
|
181
|
+
reject?("50000", "token is null", nil)
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
172
188
|
func setLocalMute(_ data: NSDictionary) {
|
|
173
189
|
guard let isMute = data.value(forKey: "isMute") as? Bool
|
|
174
190
|
else {
|
|
@@ -214,15 +230,14 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
214
230
|
self?.stopScreenshareResolve = nil
|
|
215
231
|
self?.startScreenshareResolve = nil
|
|
216
232
|
self?.isScreenShared = false
|
|
217
|
-
self?.rtcStatsAttached = false
|
|
218
233
|
self?.networkQualityUpdatesAttached = false
|
|
219
234
|
self?.hms?.leave({ success, error in
|
|
220
235
|
if success {
|
|
221
236
|
HMSDecoder.clearRestrictDataStates()
|
|
222
237
|
resolve?(["success": success])
|
|
223
238
|
} else {
|
|
224
|
-
if strongSelf.eventsEnableStatus[
|
|
225
|
-
strongSelf.delegate?.emitEvent(
|
|
239
|
+
if strongSelf.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
240
|
+
strongSelf.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": strongSelf.id])
|
|
226
241
|
}
|
|
227
242
|
reject?("error in leave", "error in leave", nil)
|
|
228
243
|
}
|
|
@@ -248,8 +263,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
248
263
|
resolve?(["success": true, "data": ["sender": message?.sender?.name ?? "", "message": message?.message ?? "", "type": message?.type]])
|
|
249
264
|
return
|
|
250
265
|
} else {
|
|
251
|
-
if self?.eventsEnableStatus[
|
|
252
|
-
self?.delegate?.emitEvent(
|
|
266
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
267
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
253
268
|
}
|
|
254
269
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
255
270
|
return
|
|
@@ -276,8 +291,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
276
291
|
resolve?(["success": true, "data": ["sender": message?.sender?.name ?? "", "message": message?.message ?? "", "type": message?.type]])
|
|
277
292
|
return
|
|
278
293
|
} else {
|
|
279
|
-
if self?.eventsEnableStatus[
|
|
280
|
-
self?.delegate?.emitEvent(
|
|
294
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
295
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
281
296
|
}
|
|
282
297
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
283
298
|
return
|
|
@@ -304,8 +319,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
304
319
|
resolve?(["success": true, "data": ["sender": message?.sender?.name ?? "", "message": message?.message ?? "", "type": message?.type]])
|
|
305
320
|
return
|
|
306
321
|
} else {
|
|
307
|
-
if self?.eventsEnableStatus[
|
|
308
|
-
self?.delegate?.emitEvent(
|
|
322
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
323
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
309
324
|
}
|
|
310
325
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
311
326
|
return
|
|
@@ -330,13 +345,12 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
330
345
|
if success {
|
|
331
346
|
resolve?(["success": success])
|
|
332
347
|
} else {
|
|
333
|
-
if self?.eventsEnableStatus[
|
|
334
|
-
self?.delegate?.emitEvent(
|
|
348
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
349
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
335
350
|
}
|
|
336
351
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
337
352
|
}
|
|
338
353
|
})
|
|
339
|
-
self?.recentPreviewTracks = []
|
|
340
354
|
self?.recentRoleChangeRequest = nil
|
|
341
355
|
}
|
|
342
356
|
}
|
|
@@ -363,8 +377,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
363
377
|
if success {
|
|
364
378
|
resolve?(["success": success])
|
|
365
379
|
} else {
|
|
366
|
-
if self?.eventsEnableStatus[
|
|
367
|
-
self?.delegate?.emitEvent(
|
|
380
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
381
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
368
382
|
}
|
|
369
383
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
370
384
|
}
|
|
@@ -401,8 +415,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
401
415
|
if success {
|
|
402
416
|
resolve?(["success": success])
|
|
403
417
|
} else {
|
|
404
|
-
if self?.eventsEnableStatus[
|
|
405
|
-
self?.delegate?.emitEvent(
|
|
418
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
419
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
406
420
|
}
|
|
407
421
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
408
422
|
}
|
|
@@ -434,8 +448,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
434
448
|
if success {
|
|
435
449
|
resolve?(["success": success])
|
|
436
450
|
} else {
|
|
437
|
-
if self?.eventsEnableStatus[
|
|
438
|
-
self?.delegate?.emitEvent(
|
|
451
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
452
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
439
453
|
}
|
|
440
454
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
441
455
|
}
|
|
@@ -471,8 +485,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
471
485
|
if success {
|
|
472
486
|
resolve?(["success": success])
|
|
473
487
|
} else {
|
|
474
|
-
if self?.eventsEnableStatus[
|
|
475
|
-
self?.delegate?.emitEvent(
|
|
488
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
489
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
476
490
|
}
|
|
477
491
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
478
492
|
}
|
|
@@ -497,8 +511,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
497
511
|
guard let remotePeers = self?.hms?.remotePeers,
|
|
498
512
|
let track = HMSHelper.getTrackFromTrackId(trackId, remotePeers)
|
|
499
513
|
else {
|
|
500
|
-
if strongSelf.eventsEnableStatus[
|
|
501
|
-
strongSelf.delegate?.emitEvent(
|
|
514
|
+
if strongSelf.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
515
|
+
strongSelf.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "Track not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": strongSelf.id])
|
|
502
516
|
}
|
|
503
517
|
reject?("Track not found", "Track not found", nil)
|
|
504
518
|
return
|
|
@@ -537,8 +551,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
537
551
|
if success {
|
|
538
552
|
resolve?(["success": success])
|
|
539
553
|
} else {
|
|
540
|
-
if self?.eventsEnableStatus[
|
|
541
|
-
self?.delegate?.emitEvent(
|
|
554
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
555
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
542
556
|
}
|
|
543
557
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
544
558
|
}
|
|
@@ -562,8 +576,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
562
576
|
if success {
|
|
563
577
|
resolve?(["success": success])
|
|
564
578
|
} else {
|
|
565
|
-
if self?.eventsEnableStatus[
|
|
566
|
-
self?.delegate?.emitEvent(
|
|
579
|
+
if self?.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
580
|
+
self?.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self?.id ?? "12345"])
|
|
567
581
|
}
|
|
568
582
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
569
583
|
}
|
|
@@ -643,8 +657,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
643
657
|
resolve?(["success": success])
|
|
644
658
|
return
|
|
645
659
|
} else {
|
|
646
|
-
if self.eventsEnableStatus[
|
|
647
|
-
self.delegate?.emitEvent(
|
|
660
|
+
if self.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
661
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
648
662
|
}
|
|
649
663
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
650
664
|
return
|
|
@@ -669,8 +683,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
669
683
|
|
|
670
684
|
if remoteAudioTrack != nil {
|
|
671
685
|
remoteAudioTrack?.setVolume(volume)
|
|
672
|
-
} else if strongSelf.eventsEnableStatus[
|
|
673
|
-
strongSelf.delegate?.emitEvent(
|
|
686
|
+
} else if strongSelf.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
687
|
+
strongSelf.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "Track not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": strongSelf.id])
|
|
674
688
|
}
|
|
675
689
|
}
|
|
676
690
|
}
|
|
@@ -691,8 +705,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
691
705
|
if let meetLink = URL(string: meetingString) {
|
|
692
706
|
meetingUrl = meetLink
|
|
693
707
|
} else {
|
|
694
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
695
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "Invalid meeting url passed", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
708
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
709
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "Invalid meeting url passed", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
696
710
|
}
|
|
697
711
|
reject?("Invalid meeting url passed", "Invalid meeting url passed", nil)
|
|
698
712
|
}
|
|
@@ -705,8 +719,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
705
719
|
resolve?(["success": success])
|
|
706
720
|
return
|
|
707
721
|
} else {
|
|
708
|
-
if self.eventsEnableStatus[
|
|
709
|
-
self.delegate?.emitEvent(
|
|
722
|
+
if self.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
723
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
710
724
|
}
|
|
711
725
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
712
726
|
return
|
|
@@ -720,8 +734,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
720
734
|
resolve?(["success": success])
|
|
721
735
|
return
|
|
722
736
|
} else {
|
|
723
|
-
if self.eventsEnableStatus[
|
|
724
|
-
self.delegate?.emitEvent(
|
|
737
|
+
if self.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
738
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
725
739
|
}
|
|
726
740
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
727
741
|
return
|
|
@@ -742,8 +756,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
742
756
|
resolve?(["success": success])
|
|
743
757
|
return
|
|
744
758
|
} else {
|
|
745
|
-
if self.eventsEnableStatus[
|
|
746
|
-
self.delegate?.emitEvent(
|
|
759
|
+
if self.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
760
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
747
761
|
}
|
|
748
762
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
749
763
|
return
|
|
@@ -757,8 +771,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
757
771
|
resolve?(["success": success])
|
|
758
772
|
return
|
|
759
773
|
} else {
|
|
760
|
-
if self.eventsEnableStatus[
|
|
761
|
-
self.delegate?.emitEvent(
|
|
774
|
+
if self.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
775
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
762
776
|
}
|
|
763
777
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
764
778
|
return
|
|
@@ -779,8 +793,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
779
793
|
if success {
|
|
780
794
|
resolve?(["success": success])
|
|
781
795
|
} else {
|
|
782
|
-
if self.eventsEnableStatus[
|
|
783
|
-
self.delegate?.emitEvent(
|
|
796
|
+
if self.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
797
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
784
798
|
}
|
|
785
799
|
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
786
800
|
}
|
|
@@ -821,18 +835,10 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
821
835
|
}
|
|
822
836
|
}
|
|
823
837
|
|
|
824
|
-
func enableRTCStats() {
|
|
825
|
-
rtcStatsAttached = true
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
func disableRTCStats() {
|
|
829
|
-
rtcStatsAttached = false
|
|
830
|
-
}
|
|
831
|
-
|
|
832
838
|
func startScreenshare(_ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
833
839
|
guard let preferredExtension = preferredExtension else {
|
|
834
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
835
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "Could not start screen share, preferredExtension not passed in Build method", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
840
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
841
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "Could not start screen share, preferredExtension not passed in Build method", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
836
842
|
}
|
|
837
843
|
reject?("Could not start screen share, preferredExtension not passed in Build method", "Could not start screen share, preferredExtension not passed in Build method", nil)
|
|
838
844
|
return
|
|
@@ -855,8 +861,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
855
861
|
|
|
856
862
|
func stopScreenshare(_ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
857
863
|
guard let preferredExtension = preferredExtension else {
|
|
858
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
859
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "Could not start screen share, preferredExtension not passed in Build method", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
864
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
865
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "Could not start screen share, preferredExtension not passed in Build method", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
860
866
|
}
|
|
861
867
|
reject?("Could not start screen share, preferredExtension not passed in Build method", "Could not start screen share, preferredExtension not passed in Build method", nil)
|
|
862
868
|
return
|
|
@@ -900,20 +906,20 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
900
906
|
try audioFilePlayerNode.play(fileUrl: url, loops: loops, interrupts: interrupts)
|
|
901
907
|
resolve?(["success": true])
|
|
902
908
|
} catch {
|
|
903
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
904
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": error.localizedDescription, "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
909
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
910
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": error.localizedDescription, "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
905
911
|
}
|
|
906
912
|
reject?(error.localizedDescription, error.localizedDescription, nil)
|
|
907
913
|
}
|
|
908
914
|
} else {
|
|
909
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
910
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "Incorrect url", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
915
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
916
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "Incorrect url", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
911
917
|
}
|
|
912
918
|
reject?("Incorrect URL", "Incorrect URL", nil)
|
|
913
919
|
}
|
|
914
920
|
} else {
|
|
915
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
916
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
921
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
922
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
917
923
|
}
|
|
918
924
|
reject?("AudioFilePlayerNode not found", "AudioFilePlayerNode not found", nil)
|
|
919
925
|
}
|
|
@@ -948,8 +954,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
948
954
|
}
|
|
949
955
|
if let audioFilePlayerNode = playerNode as? HMSAudioFilePlayerNode {
|
|
950
956
|
audioFilePlayerNode.stop()
|
|
951
|
-
} else if eventsEnableStatus[ON_ERROR] == true {
|
|
952
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
957
|
+
} else if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
958
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
953
959
|
}
|
|
954
960
|
}
|
|
955
961
|
|
|
@@ -966,12 +972,12 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
966
972
|
do {
|
|
967
973
|
try audioFilePlayerNode.resume()
|
|
968
974
|
} catch {
|
|
969
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
970
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": error.localizedDescription, "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
975
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
976
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": error.localizedDescription, "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
971
977
|
}
|
|
972
978
|
}
|
|
973
|
-
} else if eventsEnableStatus[ON_ERROR] == true {
|
|
974
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
979
|
+
} else if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
980
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
975
981
|
}
|
|
976
982
|
}
|
|
977
983
|
|
|
@@ -986,8 +992,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
986
992
|
}
|
|
987
993
|
if let audioFilePlayerNode = playerNode as? HMSAudioFilePlayerNode {
|
|
988
994
|
audioFilePlayerNode.pause()
|
|
989
|
-
} else if eventsEnableStatus[ON_ERROR] == true {
|
|
990
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
995
|
+
} else if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
996
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
991
997
|
}
|
|
992
998
|
}
|
|
993
999
|
|
|
@@ -1004,8 +1010,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1004
1010
|
if let audioFilePlayerNode = playerNode as? HMSAudioFilePlayerNode {
|
|
1005
1011
|
resolve?(audioFilePlayerNode.isPlaying)
|
|
1006
1012
|
} else {
|
|
1007
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
1008
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
1013
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
1014
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
1009
1015
|
}
|
|
1010
1016
|
reject?("AudioFilePlayerNode not found", "AudioFilePlayerNode not found", nil)
|
|
1011
1017
|
}
|
|
@@ -1024,8 +1030,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1024
1030
|
if let audioFilePlayerNode = playerNode as? HMSAudioFilePlayerNode {
|
|
1025
1031
|
resolve?(audioFilePlayerNode.currentTime)
|
|
1026
1032
|
} else {
|
|
1027
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
1028
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
1033
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
1034
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
1029
1035
|
}
|
|
1030
1036
|
reject?("AudioFilePlayerNode not found", "AudioFilePlayerNode not found", nil)
|
|
1031
1037
|
}
|
|
@@ -1044,8 +1050,8 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1044
1050
|
if let audioFilePlayerNode = playerNode as? HMSAudioFilePlayerNode {
|
|
1045
1051
|
resolve?(audioFilePlayerNode.duration)
|
|
1046
1052
|
} else {
|
|
1047
|
-
if eventsEnableStatus[ON_ERROR] == true {
|
|
1048
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
1053
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
1054
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 6002, "description": "AudioFilePlayerNode not found", "isTerminal": false, "canRetry": true, "params": ["function": #function]], "id": id])
|
|
1049
1055
|
}
|
|
1050
1056
|
reject?("AudioFilePlayerNode not found", "AudioFilePlayerNode not found", nil)
|
|
1051
1057
|
}
|
|
@@ -1062,14 +1068,32 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1062
1068
|
func setSessionMetaData(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1063
1069
|
let metaData = data.value(forKey: "sessionMetaData") as? String ?? ""
|
|
1064
1070
|
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
+
DispatchQueue.main.async { [weak self] in
|
|
1072
|
+
|
|
1073
|
+
guard let self = self else {
|
|
1074
|
+
let errorMessage = "\(#function) Unexpectedly encountered self as null"
|
|
1075
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1076
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1077
|
+
return
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
self.hms?.setSessionMetadata(metaData) { [weak self] success, error in
|
|
1081
|
+
|
|
1082
|
+
guard let self = self else {
|
|
1083
|
+
let errorMessage = "\(#function) Unexpectedly encountered self as null"
|
|
1084
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1085
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1086
|
+
return
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
if success {
|
|
1090
|
+
resolve?(["success": success])
|
|
1091
|
+
} else {
|
|
1092
|
+
if self.eventsEnableStatus[HMSConstants.ON_ERROR] == true {
|
|
1093
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
1094
|
+
}
|
|
1095
|
+
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
1071
1096
|
}
|
|
1072
|
-
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
1073
1097
|
}
|
|
1074
1098
|
}
|
|
1075
1099
|
}
|
|
@@ -1134,14 +1158,31 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1134
1158
|
}
|
|
1135
1159
|
|
|
1136
1160
|
func getSessionMetaData(_ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1161
|
+
|
|
1162
|
+
DispatchQueue.main.async { [weak self] in
|
|
1163
|
+
|
|
1164
|
+
guard let self = self else {
|
|
1165
|
+
let errorMessage = "\(#function) Unexpectedly encountered self as null"
|
|
1166
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1167
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1168
|
+
return
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
self.hms?.getSessionMetadata { [weak self] result, error in
|
|
1172
|
+
|
|
1173
|
+
guard let self = self else {
|
|
1174
|
+
let errorMessage = "\(#function) Unexpectedly encountered self as null"
|
|
1175
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1176
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1177
|
+
return
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
if error != nil {
|
|
1181
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": self.id])
|
|
1182
|
+
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
1183
|
+
} else {
|
|
1184
|
+
resolve?(result)
|
|
1141
1185
|
}
|
|
1142
|
-
reject?(error?.localizedDescription, error?.localizedDescription, nil)
|
|
1143
|
-
} else {
|
|
1144
|
-
resolve?(result)
|
|
1145
1186
|
}
|
|
1146
1187
|
}
|
|
1147
1188
|
}
|
|
@@ -1251,29 +1292,79 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1251
1292
|
}
|
|
1252
1293
|
}
|
|
1253
1294
|
|
|
1295
|
+
func getRemoteVideoTrackFromTrackId(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1296
|
+
|
|
1297
|
+
guard let trackId = data.value(forKey: "trackId") as? String
|
|
1298
|
+
else {
|
|
1299
|
+
let errorMessage = "\(#function) " + HMSHelper.getUnavailableRequiredKey(data, ["trackId"])
|
|
1300
|
+
emitRequiredKeysError(errorMessage)
|
|
1301
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1302
|
+
return
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
DispatchQueue.main.async { [weak self] in
|
|
1306
|
+
|
|
1307
|
+
guard let self = self,
|
|
1308
|
+
let remotePeers = self.hms?.remotePeers,
|
|
1309
|
+
let remoteVideoTrack = HMSHelper.getRemoteVideoTrackFromTrackId(trackId, remotePeers)
|
|
1310
|
+
else {
|
|
1311
|
+
let errorMessage = "\(#function) " + "TRACK_NOT_FOUND"
|
|
1312
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1313
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1314
|
+
return
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
resolve?(HMSDecoder.getHMSRemoteVideoTrack(remoteVideoTrack))
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
func getRemoteAudioTrackFromTrackId(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1322
|
+
guard let trackId = data.value(forKey: "trackId") as? String
|
|
1323
|
+
else {
|
|
1324
|
+
let errorMessage = "\(#function) " + HMSHelper.getUnavailableRequiredKey(data, ["trackId"])
|
|
1325
|
+
emitRequiredKeysError(errorMessage)
|
|
1326
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1327
|
+
return
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
DispatchQueue.main.async { [weak self] in
|
|
1331
|
+
|
|
1332
|
+
guard let self = self,
|
|
1333
|
+
let remotePeers = self.hms?.remotePeers,
|
|
1334
|
+
let remoteAudioTrack = HMSHelper.getRemoteAudioTrackFromTrackId(trackId, remotePeers)
|
|
1335
|
+
else {
|
|
1336
|
+
let errorMessage = "\(#function) " + "TRACK_NOT_FOUND"
|
|
1337
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1338
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1339
|
+
return
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
resolve?(HMSDecoder.getHMSRemoteAudioTrack(remoteAudioTrack))
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1254
1346
|
// MARK: - HMS SDK Delegate Callbacks
|
|
1255
1347
|
func on(join room: HMSRoom) {
|
|
1256
|
-
|
|
1257
|
-
if eventsEnableStatus[ON_JOIN] != true {
|
|
1348
|
+
if eventsEnableStatus[HMSConstants.ON_JOIN] != true {
|
|
1258
1349
|
return
|
|
1259
1350
|
}
|
|
1260
1351
|
let roomData = HMSDecoder.getHmsRoomSubset(room)
|
|
1261
|
-
self.delegate?.emitEvent(ON_JOIN, ["event": ON_JOIN, "id": self.id, "room": roomData])
|
|
1352
|
+
self.delegate?.emitEvent(HMSConstants.ON_JOIN, ["event": HMSConstants.ON_JOIN, "id": self.id, "room": roomData])
|
|
1262
1353
|
}
|
|
1263
1354
|
|
|
1264
1355
|
func onPreview(room: HMSRoom, localTracks: [HMSTrack]) {
|
|
1265
1356
|
previewInProgress = false
|
|
1266
|
-
if eventsEnableStatus[ON_PREVIEW] != true {
|
|
1357
|
+
if eventsEnableStatus[HMSConstants.ON_PREVIEW] != true {
|
|
1267
1358
|
return
|
|
1268
1359
|
}
|
|
1269
1360
|
let previewTracks = HMSDecoder.getPreviewTracks(localTracks)
|
|
1270
1361
|
let hmsRoom = HMSDecoder.getHmsRoomSubset(room)
|
|
1271
1362
|
|
|
1272
|
-
self.delegate?.emitEvent(ON_PREVIEW, ["event": ON_PREVIEW, "id": self.id, "room": hmsRoom, "previewTracks": previewTracks])
|
|
1363
|
+
self.delegate?.emitEvent(HMSConstants.ON_PREVIEW, ["event": HMSConstants.ON_PREVIEW, "id": self.id, "room": hmsRoom, "previewTracks": previewTracks])
|
|
1273
1364
|
}
|
|
1274
1365
|
|
|
1275
1366
|
func on(room: HMSRoom, update: HMSRoomUpdate) {
|
|
1276
|
-
if eventsEnableStatus[ON_ROOM_UPDATE] != true {
|
|
1367
|
+
if eventsEnableStatus[HMSConstants.ON_ROOM_UPDATE] != true {
|
|
1277
1368
|
return
|
|
1278
1369
|
}
|
|
1279
1370
|
if update == .metaDataUpdated || update == .roomTypeChanged {
|
|
@@ -1283,11 +1374,11 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1283
1374
|
let roomData = HMSDecoder.getHmsRoomSubset(room, update)
|
|
1284
1375
|
let type = getString(from: update)
|
|
1285
1376
|
|
|
1286
|
-
self.delegate?.emitEvent(ON_ROOM_UPDATE, ["event": ON_ROOM_UPDATE, "id": self.id, "type": type, "room": roomData])
|
|
1377
|
+
self.delegate?.emitEvent(HMSConstants.ON_ROOM_UPDATE, ["event": HMSConstants.ON_ROOM_UPDATE, "id": self.id, "type": type, "room": roomData])
|
|
1287
1378
|
}
|
|
1288
1379
|
|
|
1289
1380
|
func on(peer: HMSPeer, update: HMSPeerUpdate) {
|
|
1290
|
-
if eventsEnableStatus[ON_PEER_UPDATE] != true {
|
|
1381
|
+
if eventsEnableStatus[HMSConstants.ON_PEER_UPDATE] != true {
|
|
1291
1382
|
return
|
|
1292
1383
|
}
|
|
1293
1384
|
let type = getString(from: update)
|
|
@@ -1297,7 +1388,7 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1297
1388
|
return
|
|
1298
1389
|
}
|
|
1299
1390
|
|
|
1300
|
-
self.delegate?.emitEvent(ON_PEER_UPDATE, hmsPeer)
|
|
1391
|
+
self.delegate?.emitEvent(HMSConstants.ON_PEER_UPDATE, hmsPeer)
|
|
1301
1392
|
}
|
|
1302
1393
|
|
|
1303
1394
|
func on(track: HMSTrack, update: HMSTrackUpdate, for peer: HMSPeer) {
|
|
@@ -1313,7 +1404,7 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1313
1404
|
}
|
|
1314
1405
|
}
|
|
1315
1406
|
|
|
1316
|
-
if eventsEnableStatus[ON_TRACK_UPDATE] != true {
|
|
1407
|
+
if eventsEnableStatus[HMSConstants.ON_TRACK_UPDATE] != true {
|
|
1317
1408
|
return
|
|
1318
1409
|
}
|
|
1319
1410
|
|
|
@@ -1321,71 +1412,71 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1321
1412
|
let hmsPeer = HMSDecoder.getHmsPeerSubset(peer)
|
|
1322
1413
|
let hmsTrack = HMSDecoder.getHmsTrack(track)
|
|
1323
1414
|
|
|
1324
|
-
self.delegate?.emitEvent(ON_TRACK_UPDATE, ["event": ON_TRACK_UPDATE, "id": self.id, "type": type, "peer": hmsPeer, "track": hmsTrack])
|
|
1415
|
+
self.delegate?.emitEvent(HMSConstants.ON_TRACK_UPDATE, ["event": HMSConstants.ON_TRACK_UPDATE, "id": self.id, "type": type, "peer": hmsPeer, "track": hmsTrack])
|
|
1325
1416
|
}
|
|
1326
1417
|
|
|
1327
1418
|
func on(error: Error) {
|
|
1328
1419
|
if previewInProgress { previewInProgress = false }
|
|
1329
|
-
if eventsEnableStatus[ON_ERROR] != true {
|
|
1420
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] != true {
|
|
1330
1421
|
return
|
|
1331
1422
|
}
|
|
1332
|
-
self.delegate?.emitEvent(ON_ERROR, ["error": HMSDecoder.getError(error), "id": id])
|
|
1423
|
+
self.delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": HMSDecoder.getError(error), "id": id])
|
|
1333
1424
|
}
|
|
1334
1425
|
|
|
1335
1426
|
func on(message: HMSMessage) {
|
|
1336
|
-
if eventsEnableStatus[ON_MESSAGE] != true {
|
|
1427
|
+
if eventsEnableStatus[HMSConstants.ON_MESSAGE] != true {
|
|
1337
1428
|
return
|
|
1338
1429
|
}
|
|
1339
|
-
self.delegate?.emitEvent(ON_MESSAGE, ["event": ON_MESSAGE, "id": self.id, "sender": HMSDecoder.getHmsPeerSubset(message.sender), "recipient": HMSDecoder.getHmsMessageRecipient(message.recipient), "time": message.time.timeIntervalSince1970 * 1000, "message": message.message, "type": message.type])
|
|
1430
|
+
self.delegate?.emitEvent(HMSConstants.ON_MESSAGE, ["event": HMSConstants.ON_MESSAGE, "id": self.id, "sender": HMSDecoder.getHmsPeerSubset(message.sender), "recipient": HMSDecoder.getHmsMessageRecipient(message.recipient), "time": message.time.timeIntervalSince1970 * 1000, "message": message.message, "type": message.type])
|
|
1340
1431
|
}
|
|
1341
1432
|
|
|
1342
1433
|
func on(updated speakers: [HMSSpeaker]) {
|
|
1343
|
-
if eventsEnableStatus[ON_SPEAKER] != true {
|
|
1434
|
+
if eventsEnableStatus[HMSConstants.ON_SPEAKER] != true {
|
|
1344
1435
|
return
|
|
1345
1436
|
}
|
|
1346
1437
|
var speakerPeerIds: [[String: Any]] = []
|
|
1347
1438
|
for speaker in speakers {
|
|
1348
1439
|
speakerPeerIds.append(["peer": HMSDecoder.getHmsPeerSubset(speaker.peer), "level": speaker.level, "track": HMSDecoder.getHmsTrack(speaker.track)])
|
|
1349
1440
|
}
|
|
1350
|
-
self.delegate?.emitEvent(ON_SPEAKER, ["event": ON_SPEAKER, "id": self.id, "speakers": speakerPeerIds])
|
|
1441
|
+
self.delegate?.emitEvent(HMSConstants.ON_SPEAKER, ["event": HMSConstants.ON_SPEAKER, "id": self.id, "speakers": speakerPeerIds])
|
|
1351
1442
|
}
|
|
1352
1443
|
|
|
1353
1444
|
func onReconnecting() {
|
|
1354
1445
|
reconnectingStage = true
|
|
1355
|
-
if eventsEnableStatus[RECONNECTING] != true {
|
|
1446
|
+
if eventsEnableStatus[HMSConstants.RECONNECTING] != true {
|
|
1356
1447
|
return
|
|
1357
1448
|
}
|
|
1358
|
-
self.delegate?.emitEvent(RECONNECTING, ["event": RECONNECTING, "error": ["code": 1003, "description": "Network connection lost ", "isTerminal": false, "canRetry": true], "id": self.id ])
|
|
1449
|
+
self.delegate?.emitEvent(HMSConstants.RECONNECTING, ["event": HMSConstants.RECONNECTING, "error": ["code": 1003, "description": "Network connection lost ", "isTerminal": false, "canRetry": true], "id": self.id ])
|
|
1359
1450
|
}
|
|
1360
1451
|
|
|
1361
1452
|
func onReconnected() {
|
|
1362
1453
|
reconnectingStage = false
|
|
1363
|
-
if eventsEnableStatus[RECONNECTED] != true {
|
|
1454
|
+
if eventsEnableStatus[HMSConstants.RECONNECTED] != true {
|
|
1364
1455
|
return
|
|
1365
1456
|
}
|
|
1366
|
-
self.delegate?.emitEvent(RECONNECTED, ["event": RECONNECTED, "id": self.id ])
|
|
1457
|
+
self.delegate?.emitEvent(HMSConstants.RECONNECTED, ["event": HMSConstants.RECONNECTED, "id": self.id ])
|
|
1367
1458
|
}
|
|
1368
1459
|
|
|
1369
1460
|
func on(roleChangeRequest: HMSRoleChangeRequest) {
|
|
1370
1461
|
recentRoleChangeRequest = roleChangeRequest
|
|
1371
|
-
if eventsEnableStatus[ON_ROLE_CHANGE_REQUEST] != true {
|
|
1462
|
+
if eventsEnableStatus[HMSConstants.ON_ROLE_CHANGE_REQUEST] != true {
|
|
1372
1463
|
return
|
|
1373
1464
|
}
|
|
1374
1465
|
let decodedRoleChangeRequest = HMSDecoder.getHmsRoleChangeRequest(roleChangeRequest, self.id)
|
|
1375
|
-
self.delegate?.emitEvent(ON_ROLE_CHANGE_REQUEST, decodedRoleChangeRequest)
|
|
1466
|
+
self.delegate?.emitEvent(HMSConstants.ON_ROLE_CHANGE_REQUEST, decodedRoleChangeRequest)
|
|
1376
1467
|
}
|
|
1377
1468
|
|
|
1378
1469
|
func on(changeTrackStateRequest: HMSChangeTrackStateRequest) {
|
|
1379
|
-
if eventsEnableStatus[
|
|
1470
|
+
if eventsEnableStatus[HMSConstants.ON_CHANGE_TRACK_STATE_REQUEST] != true {
|
|
1380
1471
|
return
|
|
1381
1472
|
}
|
|
1382
1473
|
let decodedChangeTrackStateRequest = HMSDecoder.getHmsChangeTrackStateRequest(changeTrackStateRequest, id)
|
|
1383
|
-
delegate?.emitEvent(
|
|
1474
|
+
delegate?.emitEvent(HMSConstants.ON_CHANGE_TRACK_STATE_REQUEST, decodedChangeTrackStateRequest)
|
|
1384
1475
|
}
|
|
1385
1476
|
|
|
1386
1477
|
func on(removedFromRoom notification: HMSRemovedFromRoomNotification) {
|
|
1387
1478
|
HMSDecoder.clearRestrictDataStates()
|
|
1388
|
-
if eventsEnableStatus[ON_REMOVED_FROM_ROOM] != true {
|
|
1479
|
+
if eventsEnableStatus[HMSConstants.ON_REMOVED_FROM_ROOM] != true {
|
|
1389
1480
|
return
|
|
1390
1481
|
}
|
|
1391
1482
|
let requestedBy = notification.requestedBy as HMSPeer?
|
|
@@ -1395,80 +1486,216 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1395
1486
|
}
|
|
1396
1487
|
let reason = notification.reason
|
|
1397
1488
|
let roomEnded = notification.roomEnded
|
|
1398
|
-
self.delegate?.emitEvent(ON_REMOVED_FROM_ROOM, ["event": ON_REMOVED_FROM_ROOM, "id": self.id, "requestedBy": decodedRequestedBy as Any, "reason": reason, "roomEnded": roomEnded ])
|
|
1489
|
+
self.delegate?.emitEvent(HMSConstants.ON_REMOVED_FROM_ROOM, ["event": HMSConstants.ON_REMOVED_FROM_ROOM, "id": self.id, "requestedBy": decodedRequestedBy as Any, "reason": reason, "roomEnded": roomEnded ])
|
|
1399
1490
|
}
|
|
1400
1491
|
|
|
1401
1492
|
func on(rtcStats: HMSRTCStatsReport) {
|
|
1402
|
-
if eventsEnableStatus[ON_RTC_STATS] != true {
|
|
1493
|
+
if eventsEnableStatus[HMSConstants.ON_RTC_STATS] != true {
|
|
1403
1494
|
return
|
|
1404
1495
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
let video = HMSDecoder.getHMSRTCStats(rtcStats.video)
|
|
1409
|
-
let audio = HMSDecoder.getHMSRTCStats(rtcStats.audio)
|
|
1410
|
-
let combined = HMSDecoder.getHMSRTCStats(rtcStats.combined)
|
|
1496
|
+
let video = HMSDecoder.getHMSRTCStats(rtcStats.video) // [bitrateReceived, bitrateSent, bytesReceived, bytesSent, packetsLost, packetsReceived, roundTripTime]
|
|
1497
|
+
let audio = HMSDecoder.getHMSRTCStats(rtcStats.audio) // [bitrateReceived, bitrateSent, bytesReceived, bytesSent, packetsLost, packetsReceived, roundTripTime]
|
|
1498
|
+
let combined = HMSDecoder.getHMSRTCStats(rtcStats.combined) // [bitrateReceived, bitrateSent, bytesReceived, bytesSent, packetsLost, packetsReceived, roundTripTime]
|
|
1411
1499
|
|
|
1412
|
-
self.delegate?.emitEvent(ON_RTC_STATS, ["video": video, "audio": audio, "combined": combined, "id": self.id])
|
|
1500
|
+
self.delegate?.emitEvent(HMSConstants.ON_RTC_STATS, ["video": video, "audio": audio, "combined": combined, "id": self.id])
|
|
1413
1501
|
}
|
|
1414
1502
|
|
|
1415
1503
|
func on(localAudioStats: HMSLocalAudioStats, track: HMSAudioTrack, peer: HMSPeer) {
|
|
1416
|
-
if eventsEnableStatus[ON_LOCAL_AUDIO_STATS] != true {
|
|
1417
|
-
return
|
|
1418
|
-
}
|
|
1419
|
-
if !rtcStatsAttached {
|
|
1504
|
+
if eventsEnableStatus[HMSConstants.ON_LOCAL_AUDIO_STATS] != true {
|
|
1420
1505
|
return
|
|
1421
1506
|
}
|
|
1422
|
-
let localStats = HMSDecoder.getLocalAudioStats(localAudioStats)
|
|
1507
|
+
let localStats = HMSDecoder.getLocalAudioStats(localAudioStats) // [bitrate, bytesSent, roundTripTime]
|
|
1423
1508
|
let localTrack = HMSDecoder.getHmsAudioTrack(track)
|
|
1424
1509
|
let decodedPeer = HMSDecoder.getHmsPeerSubset(peer)
|
|
1425
1510
|
|
|
1426
|
-
self.delegate?.emitEvent(ON_LOCAL_AUDIO_STATS, ["localAudioStats": localStats, "track": localTrack, "peer": decodedPeer, "id": self.id])
|
|
1511
|
+
self.delegate?.emitEvent(HMSConstants.ON_LOCAL_AUDIO_STATS, ["localAudioStats": localStats, "track": localTrack, "peer": decodedPeer, "id": self.id])
|
|
1427
1512
|
}
|
|
1428
1513
|
|
|
1429
|
-
func on(localVideoStats: [HMSLocalVideoStats], track: HMSVideoTrack, peer: HMSPeer) {
|
|
1430
|
-
if eventsEnableStatus[ON_LOCAL_VIDEO_STATS] != true {
|
|
1514
|
+
func on(localVideoStats: [HMSLocalVideoStats], track: HMSVideoTrack, peer: HMSPeer) { // DOUBT: HMSLocalVideoTrack instead of HMSVideoTrack?
|
|
1515
|
+
if eventsEnableStatus[HMSConstants.ON_LOCAL_VIDEO_STATS] != true {
|
|
1431
1516
|
return
|
|
1432
1517
|
}
|
|
1433
|
-
|
|
1434
|
-
return
|
|
1435
|
-
}
|
|
1436
|
-
let localStats = HMSDecoder.getLocalVideoStats(localVideoStats)
|
|
1518
|
+
let localStats = HMSDecoder.getLocalVideoStats(localVideoStats) // List<[bitrate, bytesSent, roundTripTime, frameRate, resolution, layer]>
|
|
1437
1519
|
let decodedPeer = HMSDecoder.getHmsPeerSubset(peer)
|
|
1438
1520
|
let localTrack = HMSDecoder.getHmsVideoTrack(track)
|
|
1439
1521
|
|
|
1440
|
-
self.delegate?.emitEvent(ON_LOCAL_VIDEO_STATS, ["localVideoStats": localStats, "track": localTrack, "peer": decodedPeer, "id": self.id])
|
|
1522
|
+
self.delegate?.emitEvent(HMSConstants.ON_LOCAL_VIDEO_STATS, ["localVideoStats": localStats, "track": localTrack, "peer": decodedPeer, "id": self.id])
|
|
1441
1523
|
}
|
|
1442
1524
|
|
|
1443
1525
|
func on(remoteAudioStats: HMSRemoteAudioStats, track: HMSAudioTrack, peer: HMSPeer) {
|
|
1444
|
-
if eventsEnableStatus[ON_REMOTE_AUDIO_STATS] != true {
|
|
1445
|
-
return
|
|
1446
|
-
}
|
|
1447
|
-
if !rtcStatsAttached {
|
|
1526
|
+
if eventsEnableStatus[HMSConstants.ON_REMOTE_AUDIO_STATS] != true {
|
|
1448
1527
|
return
|
|
1449
1528
|
}
|
|
1450
|
-
let remoteStats = HMSDecoder.getRemoteAudioStats(remoteAudioStats)
|
|
1529
|
+
let remoteStats = HMSDecoder.getRemoteAudioStats(remoteAudioStats) // [bitrate, bytesReceived, jitter, packetsLost, packetsReceived]
|
|
1451
1530
|
let remoteTrack = HMSDecoder.getHmsAudioTrack(track)
|
|
1452
1531
|
let decodedPeer = HMSDecoder.getHmsPeerSubset(peer)
|
|
1453
1532
|
|
|
1454
|
-
self.delegate?.emitEvent(ON_REMOTE_AUDIO_STATS, ["remoteAudioStats": remoteStats, "track": remoteTrack, "peer": decodedPeer, "id": self.id])
|
|
1533
|
+
self.delegate?.emitEvent(HMSConstants.ON_REMOTE_AUDIO_STATS, ["remoteAudioStats": remoteStats, "track": remoteTrack, "peer": decodedPeer, "id": self.id])
|
|
1455
1534
|
}
|
|
1456
1535
|
|
|
1457
1536
|
func on(remoteVideoStats: HMSRemoteVideoStats, track: HMSVideoTrack, peer: HMSPeer) {
|
|
1458
|
-
if eventsEnableStatus[ON_REMOTE_VIDEO_STATS] != true {
|
|
1459
|
-
return
|
|
1460
|
-
}
|
|
1461
|
-
if !rtcStatsAttached {
|
|
1537
|
+
if eventsEnableStatus[HMSConstants.ON_REMOTE_VIDEO_STATS] != true {
|
|
1462
1538
|
return
|
|
1463
1539
|
}
|
|
1464
|
-
let remoteStats = HMSDecoder.getRemoteVideoStats(remoteVideoStats)
|
|
1540
|
+
let remoteStats = HMSDecoder.getRemoteVideoStats(remoteVideoStats) // [bitrate, bytesReceived, frameRate, jitter, packetsLost, packetsReceived, resolution]
|
|
1465
1541
|
let decodedPeer = HMSDecoder.getHmsPeerSubset(peer)
|
|
1466
1542
|
let remoteTrack = HMSDecoder.getHmsVideoTrack(track)
|
|
1467
1543
|
|
|
1468
|
-
self.delegate?.emitEvent(ON_REMOTE_VIDEO_STATS, ["remoteVideoStats": remoteStats, "track": remoteTrack, "peer": decodedPeer, "id": self.id])
|
|
1544
|
+
self.delegate?.emitEvent(HMSConstants.ON_REMOTE_VIDEO_STATS, ["remoteVideoStats": remoteStats, "track": remoteTrack, "peer": decodedPeer, "id": self.id])
|
|
1545
|
+
}
|
|
1546
|
+
|
|
1547
|
+
// MARK: - Simulcast
|
|
1548
|
+
|
|
1549
|
+
func getVideoTrackLayerDefinition(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1550
|
+
guard let trackId = data.value(forKey: "trackId") as? String
|
|
1551
|
+
else {
|
|
1552
|
+
let errorMessage = "\(#function) " + HMSHelper.getUnavailableRequiredKey(data, ["trackId"])
|
|
1553
|
+
emitRequiredKeysError(errorMessage)
|
|
1554
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1555
|
+
return
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
DispatchQueue.main.async { [weak self] in
|
|
1559
|
+
|
|
1560
|
+
guard let self = self,
|
|
1561
|
+
let remotePeers = self.hms?.remotePeers,
|
|
1562
|
+
let remoteVideoTrack = HMSHelper.getRemoteVideoTrackFromTrackId(trackId, remotePeers)
|
|
1563
|
+
else {
|
|
1564
|
+
let errorMessage = "\(#function) " + "TRACK_NOT_FOUND"
|
|
1565
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1566
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1567
|
+
return
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
guard let layerDefinitions = remoteVideoTrack.layerDefinitions
|
|
1571
|
+
else {
|
|
1572
|
+
let errorMessage = "\(#function) " + "layer definitions not available for track: '\(trackId)' !"
|
|
1573
|
+
self.emitRequiredKeysError(errorMessage)
|
|
1574
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1575
|
+
return
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
let parsedLayerDefinitions = HMSDecoder.getSimulcastLayerDefinitions(for: layerDefinitions)
|
|
1579
|
+
|
|
1580
|
+
resolve?(parsedLayerDefinitions)
|
|
1581
|
+
}
|
|
1469
1582
|
}
|
|
1470
1583
|
|
|
1471
|
-
|
|
1584
|
+
func getVideoTrackLayer(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1585
|
+
|
|
1586
|
+
guard let trackId = data.value(forKey: "trackId") as? String
|
|
1587
|
+
else {
|
|
1588
|
+
let errorMessage = "\(#function) " + HMSHelper.getUnavailableRequiredKey(data, ["trackId"])
|
|
1589
|
+
emitRequiredKeysError(errorMessage)
|
|
1590
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1591
|
+
return
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
DispatchQueue.main.async { [weak self] in
|
|
1595
|
+
|
|
1596
|
+
guard let self = self,
|
|
1597
|
+
let remotePeers = self.hms?.remotePeers,
|
|
1598
|
+
let remoteVideoTrack = HMSHelper.getRemoteVideoTrackFromTrackId(trackId, remotePeers)
|
|
1599
|
+
else {
|
|
1600
|
+
let errorMessage = "\(#function) " + "TRACK_NOT_FOUND"
|
|
1601
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1602
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1603
|
+
return
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
let parsedLayer = HMSDecoder.getString(from: remoteVideoTrack.layer)
|
|
1607
|
+
|
|
1608
|
+
resolve?(parsedLayer)
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
func setVideoTrackLayer(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1613
|
+
guard let trackId = data.value(forKey: "trackId") as? String,
|
|
1614
|
+
let layer = data.value(forKey: "layer") as? String
|
|
1615
|
+
else {
|
|
1616
|
+
let errorMessage = "\(#function) " + HMSHelper.getUnavailableRequiredKey(data, ["trackId", "layer"])
|
|
1617
|
+
emitRequiredKeysError(errorMessage)
|
|
1618
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1619
|
+
return
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
DispatchQueue.main.async { [weak self] in
|
|
1623
|
+
|
|
1624
|
+
guard let self = self,
|
|
1625
|
+
let remotePeers = self.hms?.remotePeers,
|
|
1626
|
+
let remoteVideoTrack = HMSHelper.getRemoteVideoTrackFromTrackId(trackId, remotePeers)
|
|
1627
|
+
else {
|
|
1628
|
+
let errorMessage = "\(#function) " + "TRACK_NOT_FOUND"
|
|
1629
|
+
self?.emitRequiredKeysError(errorMessage)
|
|
1630
|
+
reject?(errorMessage, errorMessage, nil)
|
|
1631
|
+
return
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
switch layer.uppercased() {
|
|
1635
|
+
case "LOW":
|
|
1636
|
+
remoteVideoTrack.layer = .low
|
|
1637
|
+
case "MEDIUM":
|
|
1638
|
+
remoteVideoTrack.layer = .mid
|
|
1639
|
+
default:
|
|
1640
|
+
remoteVideoTrack.layer = .high
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
resolve?(true)
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
// MARK: - Advanced Camera Controls
|
|
1648
|
+
|
|
1649
|
+
func captureImageAtMaxSupportedResolution(_ data: NSDictionary, _ resolve: RCTPromiseResolveBlock?, _ reject: RCTPromiseRejectBlock?) {
|
|
1650
|
+
|
|
1651
|
+
let withFlash = data["flash"] as? Bool ?? false
|
|
1652
|
+
|
|
1653
|
+
DispatchQueue.main.async { [weak self] in
|
|
1654
|
+
|
|
1655
|
+
guard let localPeer = self?.hms?.localPeer else {
|
|
1656
|
+
let errorMessage = "\(#function) An instance of Local Peer could not be found. Please check if a Room is joined."
|
|
1657
|
+
reject?("6004", errorMessage, nil)
|
|
1658
|
+
return
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
guard let localVideoTrack = localPeer.localVideoTrack()
|
|
1662
|
+
else {
|
|
1663
|
+
let errorMessage = "\(#function) Video Track of Local Peer could not be found. Please check if the Local Peer has permission to publish video & video is unmuted currently."
|
|
1664
|
+
reject?("6004", errorMessage, nil)
|
|
1665
|
+
return
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
localVideoTrack.captureImageAtMaxSupportedResolution(withFlash: withFlash) { image in
|
|
1669
|
+
|
|
1670
|
+
guard let rawImage = image, let capturedImage = rawImage.fixOrientation() else {
|
|
1671
|
+
let errorMessage = "\(#function) Could not capture image of the Local Peer's Video Track."
|
|
1672
|
+
reject?("6004", errorMessage, nil)
|
|
1673
|
+
return
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
guard let data = capturedImage.pngData() else {
|
|
1677
|
+
let errorMessage = "\(#function) Could not compress image of the Local Peer's Video Track to png data."
|
|
1678
|
+
reject?("6004", errorMessage, nil)
|
|
1679
|
+
return
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
let filePath = HMSRNSDK.getDocumentsDirectory().appendingPathComponent("hms_\(HMSRNSDK.getTimeStamp()).png")
|
|
1683
|
+
|
|
1684
|
+
do {
|
|
1685
|
+
try data.write(to: filePath)
|
|
1686
|
+
|
|
1687
|
+
resolve?(filePath.relativePath)
|
|
1688
|
+
} catch let error {
|
|
1689
|
+
let errorMessage = "\(#function) Could not write to disk the image data of the Local Peer's Video Track. \(error.localizedDescription)"
|
|
1690
|
+
reject?("6004", errorMessage, nil)
|
|
1691
|
+
return
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// MARK: - Helper Functions
|
|
1698
|
+
|
|
1472
1699
|
private func getString(from update: HMSPeerUpdate) -> String {
|
|
1473
1700
|
switch update {
|
|
1474
1701
|
case .peerJoined:
|
|
@@ -1533,9 +1760,32 @@ class HMSRNSDK: HMSUpdateListener, HMSPreviewListener {
|
|
|
1533
1760
|
}
|
|
1534
1761
|
|
|
1535
1762
|
func emitRequiredKeysError(_ error: String) {
|
|
1536
|
-
if eventsEnableStatus[ON_ERROR] != true {
|
|
1763
|
+
if eventsEnableStatus[HMSConstants.ON_ERROR] != true {
|
|
1537
1764
|
return
|
|
1538
1765
|
}
|
|
1539
|
-
delegate?.emitEvent(ON_ERROR, ["error": ["code":
|
|
1766
|
+
delegate?.emitEvent(HMSConstants.ON_ERROR, ["error": ["code": 7000, "description": error, "isTerminal": false, "canRetry": true], "id": id]) // DOUBT: Error code 6002 or 7000?
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
static private func getDocumentsDirectory() -> URL {
|
|
1770
|
+
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
|
|
1771
|
+
return paths[0]
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
static private func getTimeStamp() -> String {
|
|
1775
|
+
"\(Date().timeIntervalSince1970)"
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
extension UIImage {
|
|
1780
|
+
func fixOrientation() -> UIImage? {
|
|
1781
|
+
if self.imageOrientation == UIImage.Orientation.up {
|
|
1782
|
+
return self
|
|
1783
|
+
}
|
|
1784
|
+
|
|
1785
|
+
UIGraphicsBeginImageContext(self.size)
|
|
1786
|
+
self.draw(in: CGRect(origin: .zero, size: self.size))
|
|
1787
|
+
let normalizedImage = UIGraphicsGetImageFromCurrentImageContext()
|
|
1788
|
+
UIGraphicsEndImageContext()
|
|
1789
|
+
return normalizedImage
|
|
1540
1790
|
}
|
|
1541
1791
|
}
|