@cloudflare/realtimekit-react-native 0.0.0 → 0.0.1-staging.3
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/LICENSE +13 -0
- package/README.md +83 -0
- package/RealtimeKitCore.podspec +19 -0
- package/android/build.gradle +58 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/src/main/AndroidManifest.xml +23 -0
- package/android/src/main/java/com/reactnativecore/BackgroundTimer/RNBackgroundTimer.java +97 -0
- package/android/src/main/java/com/reactnativecore/Constants.java +14 -0
- package/android/src/main/java/com/reactnativecore/CoreModule.java +49 -0
- package/android/src/main/java/com/reactnativecore/CorePackage.java +34 -0
- package/android/src/main/java/com/reactnativecore/DyteHelperModule.java +268 -0
- package/android/src/main/java/com/reactnativecore/DyteHolder.java +7 -0
- package/android/src/main/java/com/reactnativecore/ForegroundService.java +48 -0
- package/android/src/main/java/com/reactnativecore/NotificationHelper.java +127 -0
- package/android/src/main/java/com/reactnativecore/RNPermissionsModule.java +226 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/AppRTCBluetoothManager.java +637 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/AppRTCProximitySensor.java +133 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/AppRTCUtils.java +41 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/InCallManagerModule.java +1881 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/InCallProximityManager.java +162 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/InCallWakeLockUtils.java +116 -0
- package/android/src/main/java/com/reactnativecore/incallmanager/ThreadUtils.java +39 -0
- package/app.plugin.js +1 -0
- package/ios/BroadcastEventEmitter.h +11 -0
- package/ios/BroadcastEventEmitter.m +72 -0
- package/ios/Core.h +5 -0
- package/ios/Core.m +28 -0
- package/ios/Core.xcodeproj/project.pbxproj +287 -0
- package/ios/DyteRNBackgroundTimer.h +22 -0
- package/ios/DyteRNBackgroundTimer.m +90 -0
- package/ios/DyteRNPermissionHandlerNotifications.h +17 -0
- package/ios/DyteRNPermissionHandlerNotifications.m +127 -0
- package/ios/DyteRNPermissions.h +50 -0
- package/ios/DyteRNPermissions.m +275 -0
- package/ios/DyteScreensharePickerView.h +8 -0
- package/ios/DyteScreensharePickerView.m +27 -0
- package/ios/PrivacyInfo.xcprivacy +60 -0
- package/ios/RNInCallManager.h +16 -0
- package/ios/RNInCallManager.m +1354 -0
- package/ios/permissions/DyteRNPermissionHandlerBluetoothPeripheral.h +4 -0
- package/ios/permissions/DyteRNPermissionHandlerBluetoothPeripheral.m +87 -0
- package/ios/permissions/DyteRNPermissionHandlerCamera.h +5 -0
- package/ios/permissions/DyteRNPermissionHandlerCamera.m +38 -0
- package/ios/permissions/DyteRNPermissionHandlerMicrophone.h +5 -0
- package/ios/permissions/DyteRNPermissionHandlerMicrophone.m +34 -0
- package/ios/permissions/DyteRNPermissionHandlerPhotoLibrary.h +8 -0
- package/ios/permissions/DyteRNPermissionHandlerPhotoLibrary.m +70 -0
- package/ios/screenshare/DyteDarwinNotificationCenter.swift +21 -0
- package/ios/screenshare/DyteScreenshareAtomic.swift +29 -0
- package/ios/screenshare/DyteScreenshareHandler.swift +103 -0
- package/ios/screenshare/DyteScreenshareUploader.swift +139 -0
- package/ios/screenshare/DyteSocketConnection.swift +190 -0
- package/lib/BackgroundHandler.d.ts +20 -0
- package/lib/BackgroundHandler.js +87 -0
- package/lib/LocalMediaError.d.ts +4 -0
- package/lib/LocalMediaError.js +6 -0
- package/lib/LocalMediaHandler.d.ts +118 -0
- package/lib/LocalMediaHandler.js +853 -0
- package/lib/LocalMediaInterfaces.d.ts +76 -0
- package/lib/LocalMediaInterfaces.js +1 -0
- package/lib/LocalMediaUtils.d.ts +93 -0
- package/lib/LocalMediaUtils.js +276 -0
- package/lib/NativeAudioManager.d.ts +16 -0
- package/lib/NativeAudioManager.js +93 -0
- package/lib/PermissionHandler.d.ts +34 -0
- package/lib/PermissionHandler.js +179 -0
- package/lib/ReactContext.d.ts +42 -0
- package/lib/ReactContext.js +96 -0
- package/lib/ReactHooks.d.ts +11 -0
- package/lib/ReactHooks.js +73 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +40 -0
- package/lib/utils/crypto.d.ts +17 -0
- package/lib/utils/crypto.js +82 -0
- package/package.json +51 -4
- package/plugin/build/withDyte.d.ts +25 -0
- package/plugin/build/withDyte.js +100 -0
- package/plugin/src/withDyte.ts +150 -0
- package/plugin/tsconfig.json +10 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
11
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
|
+
};
|
|
16
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
17
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
18
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
|
+
};
|
|
21
|
+
var _LocalMediaHandler_localMediaUtils, _LocalMediaHandler_appState, _LocalMediaHandler_appStateSubscription, _LocalMediaHandler_interval;
|
|
22
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
23
|
+
import { EventEmitter } from 'events';
|
|
24
|
+
import LocalMediaUtils from './LocalMediaUtils';
|
|
25
|
+
import { AppState, NativeEventEmitter, NativeModules, Platform, } from 'react-native';
|
|
26
|
+
import BackgroundTimer from './BackgroundHandler';
|
|
27
|
+
import InCallManger from './NativeAudioManager';
|
|
28
|
+
import { setupPermissions } from './PermissionHandler';
|
|
29
|
+
const { DyteHelper, BroadcastEventEmitter } = NativeModules;
|
|
30
|
+
const broadcastEmitter = new NativeEventEmitter(BroadcastEventEmitter);
|
|
31
|
+
export var MediaEvents;
|
|
32
|
+
(function (MediaEvents) {
|
|
33
|
+
MediaEvents[MediaEvents["AUDIO_TRACK_CHANGE"] = 0] = "AUDIO_TRACK_CHANGE";
|
|
34
|
+
MediaEvents[MediaEvents["VIDEO_TRACK_CHANGE"] = 1] = "VIDEO_TRACK_CHANGE";
|
|
35
|
+
MediaEvents[MediaEvents["SCREENSHARE_TRACK_CHANGE"] = 2] = "SCREENSHARE_TRACK_CHANGE";
|
|
36
|
+
MediaEvents[MediaEvents["SCREENSHARE_ENDED"] = 3] = "SCREENSHARE_ENDED";
|
|
37
|
+
MediaEvents[MediaEvents["DEVICE_CHANGE"] = 4] = "DEVICE_CHANGE";
|
|
38
|
+
MediaEvents[MediaEvents["SCREENSHARE_STARTED"] = 5] = "SCREENSHARE_STARTED";
|
|
39
|
+
MediaEvents[MediaEvents["MEDIA_PERMISSION_UPDATE"] = 6] = "MEDIA_PERMISSION_UPDATE";
|
|
40
|
+
MediaEvents[MediaEvents["DEVICE_LIST_UPDATED"] = 7] = "DEVICE_LIST_UPDATED";
|
|
41
|
+
})(MediaEvents || (MediaEvents = {}));
|
|
42
|
+
function checkIfAudioTrackIsSilent(track) {
|
|
43
|
+
//TODO
|
|
44
|
+
return !!track;
|
|
45
|
+
}
|
|
46
|
+
class LocalMediaHandler extends EventEmitter {
|
|
47
|
+
configureForeground() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const val = yield DyteHelper.isForegroundServiceRunning();
|
|
50
|
+
if (Platform.Version >= 26) {
|
|
51
|
+
yield DyteHelper.createNotificationChannel();
|
|
52
|
+
}
|
|
53
|
+
if (!val)
|
|
54
|
+
yield DyteHelper.startService();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
constructor(localMediaUtils) {
|
|
58
|
+
super();
|
|
59
|
+
_LocalMediaHandler_localMediaUtils.set(this, void 0);
|
|
60
|
+
_LocalMediaHandler_appState.set(this, void 0);
|
|
61
|
+
_LocalMediaHandler_appStateSubscription.set(this, void 0);
|
|
62
|
+
_LocalMediaHandler_interval.set(this, void 0);
|
|
63
|
+
this._handleAppStateChange = (nextAppState) => {
|
|
64
|
+
// console.log('App state changed to : ', nextAppState);
|
|
65
|
+
if (__classPrivateFieldGet(this, _LocalMediaHandler_appState, "f").match(/inactive|background/) &&
|
|
66
|
+
nextAppState === 'active') {
|
|
67
|
+
BackgroundTimer.clearInterval(__classPrivateFieldGet(this, _LocalMediaHandler_interval, "f"));
|
|
68
|
+
__classPrivateFieldSet(this, _LocalMediaHandler_interval, null, "f");
|
|
69
|
+
if (this.videoTrack) {
|
|
70
|
+
this.videoTrack.enabled = false;
|
|
71
|
+
setTimeout(() => {
|
|
72
|
+
if (this.videoTrack) {
|
|
73
|
+
this.videoTrack.enabled = true;
|
|
74
|
+
}
|
|
75
|
+
}, 100);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
if (__classPrivateFieldGet(this, _LocalMediaHandler_interval, "f") === null) {
|
|
80
|
+
this.configureForeground();
|
|
81
|
+
}
|
|
82
|
+
__classPrivateFieldSet(this, _LocalMediaHandler_interval, BackgroundTimer.setInterval(() => { }, 1000), "f");
|
|
83
|
+
__classPrivateFieldSet(this, _LocalMediaHandler_appState, nextAppState, "f");
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
__classPrivateFieldSet(this, _LocalMediaHandler_localMediaUtils, localMediaUtils, "f");
|
|
87
|
+
__classPrivateFieldSet(this, _LocalMediaHandler_appState, '', "f");
|
|
88
|
+
this.audioEnabled = true;
|
|
89
|
+
this.videoEnabled = true;
|
|
90
|
+
this.screenShareEnabled = false;
|
|
91
|
+
this.permissions = { audio: 'NOT_REQUESTED', video: 'NOT_REQUESTED' };
|
|
92
|
+
this.screenShareTracks = {
|
|
93
|
+
audio: undefined,
|
|
94
|
+
video: undefined,
|
|
95
|
+
};
|
|
96
|
+
this.currentDevices = {
|
|
97
|
+
audio: undefined,
|
|
98
|
+
video: undefined,
|
|
99
|
+
speaker: undefined,
|
|
100
|
+
};
|
|
101
|
+
// NOTE(roerohan): The arrow function is required so that the reference to "this" is proper.
|
|
102
|
+
//if (Platform.OS === 'android')
|
|
103
|
+
__classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").onDeviceChange((changedDevices) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
yield this.onDeviceChange(changedDevices, false);
|
|
105
|
+
}));
|
|
106
|
+
if (Platform.OS === 'ios') {
|
|
107
|
+
broadcastEmitter.addListener('iOS_BroadcastStarted', () => {
|
|
108
|
+
this.oniOSBroadcastStart();
|
|
109
|
+
});
|
|
110
|
+
broadcastEmitter.addListener('iOS_BroadcastStopped', () => {
|
|
111
|
+
this.oniOSBroadcastStop();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
InCallManger.start({});
|
|
115
|
+
}
|
|
116
|
+
destructor() {
|
|
117
|
+
__classPrivateFieldGet(this, _LocalMediaHandler_appStateSubscription, "f").remove();
|
|
118
|
+
broadcastEmitter.removeAllListeners('iOS_BroadcastStarted');
|
|
119
|
+
broadcastEmitter.removeAllListeners('iOS_BroadcastStopped');
|
|
120
|
+
BackgroundTimer.stop();
|
|
121
|
+
}
|
|
122
|
+
handlePermissionErrors(kind, err) {
|
|
123
|
+
// pass
|
|
124
|
+
}
|
|
125
|
+
conditionallyRestartAudio() {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
var _a;
|
|
128
|
+
if (!this.currentDevices.audio || !this.audioEnabled) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// log.info('maybe_restart_audio: ');
|
|
132
|
+
yield Promise.race([
|
|
133
|
+
new Promise((resolve) => {
|
|
134
|
+
var _a;
|
|
135
|
+
return (_a = this.audioTrack) === null || _a === void 0 ? void 0 : _a.addEventListener('unmute', (e) => {
|
|
136
|
+
resolve(e);
|
|
137
|
+
});
|
|
138
|
+
}),
|
|
139
|
+
new Promise((resolve) => setTimeout(resolve, 50)),
|
|
140
|
+
]);
|
|
141
|
+
const reacquireTrack = yield this.shouldReacquireTrack('audio');
|
|
142
|
+
if (reacquireTrack) {
|
|
143
|
+
this.removeMediaStreamTrackListeners(this.audioTrack);
|
|
144
|
+
yield this.setupAudioStream((_a = this.currentDevices.audio) === null || _a === void 0 ? void 0 : _a.deviceId);
|
|
145
|
+
this.addMediaStreamTrackListeners(this.audioTrack);
|
|
146
|
+
this.emit('AUDIO_TRACK_CHANGE');
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
conditionallyRestartVideo() {
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
if (!this.currentDevices.video || !this.videoEnabled)
|
|
153
|
+
return;
|
|
154
|
+
// log.info('maybe_restart_video');
|
|
155
|
+
yield Promise.race([
|
|
156
|
+
new Promise((resolve) => { var _a; return (_a = this.videoTrack) === null || _a === void 0 ? void 0 : _a.addEventListener('unmute', resolve); }),
|
|
157
|
+
new Promise((resolve) => setTimeout(resolve, 50)),
|
|
158
|
+
]);
|
|
159
|
+
const reacquireTrack = yield this.shouldReacquireTrack('video');
|
|
160
|
+
if (reacquireTrack) {
|
|
161
|
+
this.removeMediaStreamTrackListeners(this.videoTrack);
|
|
162
|
+
yield this.setupVideoStream(this.currentDevices.video.deviceId);
|
|
163
|
+
this.addMediaStreamTrackListeners(this.videoTrack);
|
|
164
|
+
this.emit('VIDEO_TRACK_CHANGE');
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
shouldReacquireTrack(kind) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
const workaroundWebKitBug1208516 = false;
|
|
171
|
+
let mediaStreamTrack;
|
|
172
|
+
let wasEnabled = false;
|
|
173
|
+
if (kind === 'audio') {
|
|
174
|
+
mediaStreamTrack = this.audioTrack;
|
|
175
|
+
wasEnabled = this.audioEnabled;
|
|
176
|
+
}
|
|
177
|
+
else if (kind === 'video') {
|
|
178
|
+
mediaStreamTrack = this.videoTrack;
|
|
179
|
+
wasEnabled = this.videoEnabled;
|
|
180
|
+
}
|
|
181
|
+
if (!mediaStreamTrack)
|
|
182
|
+
return false;
|
|
183
|
+
if (!this.rawAudioTrack || !this.audioTrack)
|
|
184
|
+
return true;
|
|
185
|
+
if (!this.rawVideoTrack || !this.videoTrack)
|
|
186
|
+
return true;
|
|
187
|
+
const isStopped = mediaStreamTrack.readyState === 'ended';
|
|
188
|
+
const isInadvertentlyStopped = isStopped && wasEnabled && workaroundWebKitBug1208516;
|
|
189
|
+
let isSilentAudio = false;
|
|
190
|
+
if (kind === 'audio') {
|
|
191
|
+
isSilentAudio = yield checkIfAudioTrackIsSilent(this.audioTrack);
|
|
192
|
+
}
|
|
193
|
+
return mediaStreamTrack.muted || isInadvertentlyStopped || isSilentAudio;
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
removeDocumentEventListeners() {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () { });
|
|
198
|
+
}
|
|
199
|
+
onUnmute(ev) {
|
|
200
|
+
// log.info('Track unmuted', ev);
|
|
201
|
+
}
|
|
202
|
+
removeMediaStreamTrackListeners(mediaStreamTrack) {
|
|
203
|
+
if (!mediaStreamTrack) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
const conditionallyRestart = mediaStreamTrack.kind === 'audio'
|
|
207
|
+
? this.conditionallyRestartAudio
|
|
208
|
+
: this.conditionallyRestartVideo;
|
|
209
|
+
mediaStreamTrack.removeEventListener('ended', conditionallyRestart);
|
|
210
|
+
mediaStreamTrack.removeEventListener('mute', conditionallyRestart);
|
|
211
|
+
mediaStreamTrack.removeEventListener('unmute', this.onUnmute);
|
|
212
|
+
return mediaStreamTrack;
|
|
213
|
+
}
|
|
214
|
+
addMediaStreamTrackListeners(mediaStreamTrack) {
|
|
215
|
+
if (!mediaStreamTrack) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const conditionallyRestart = mediaStreamTrack.kind === 'audio'
|
|
219
|
+
? this.conditionallyRestartAudio
|
|
220
|
+
: this.conditionallyRestartVideo;
|
|
221
|
+
mediaStreamTrack.addEventListener('ended', conditionallyRestart);
|
|
222
|
+
mediaStreamTrack.addEventListener('mute', conditionallyRestart);
|
|
223
|
+
mediaStreamTrack.addEventListener('unmute', this.onUnmute);
|
|
224
|
+
return mediaStreamTrack;
|
|
225
|
+
}
|
|
226
|
+
setupAudioStream(deviceId_1) {
|
|
227
|
+
return __awaiter(this, arguments, void 0, function* (deviceId, forceStopTrack = false) {
|
|
228
|
+
var _a, _b, _c;
|
|
229
|
+
const audioDevices = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getAudioDevices();
|
|
230
|
+
if (!audioDevices.length) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
let audioDeviceId = deviceId;
|
|
234
|
+
if (!audioDeviceId) {
|
|
235
|
+
audioDeviceId = (yield this.getOperationalMicDeviceId()).deviceId;
|
|
236
|
+
}
|
|
237
|
+
if (((_a = this.currentDevices.audio) === null || _a === void 0 ? void 0 : _a.deviceId) !== audioDeviceId) {
|
|
238
|
+
this.currentDevices.audio = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getDeviceById(audioDeviceId, 'audioinput');
|
|
239
|
+
}
|
|
240
|
+
if (forceStopTrack) {
|
|
241
|
+
(_b = this.audioTrack) === null || _b === void 0 ? void 0 : _b.stop();
|
|
242
|
+
(_c = this.rawAudioTrack) === null || _c === void 0 ? void 0 : _c.stop();
|
|
243
|
+
}
|
|
244
|
+
this.rawAudioTrack = yield LocalMediaUtils.getAudioTrack();
|
|
245
|
+
this.setAudioTrack(this.rawAudioTrack);
|
|
246
|
+
this.addMediaStreamTrackListeners(this.audioTrack);
|
|
247
|
+
this.setDevice(this.currentDevices.audio);
|
|
248
|
+
// await InCallManger.chooseAudioRoute(audioDeviceId);
|
|
249
|
+
// console.log('Device selected: ', audioDeviceId);
|
|
250
|
+
/**
|
|
251
|
+
* NOTE(roerohan): Firefox does not show device labels until permissions are granted.
|
|
252
|
+
* So, we need to repopulate the devices once permission is granted.
|
|
253
|
+
*/
|
|
254
|
+
if (this.audioTrack && this.permissions.audio === 'NOT_REQUESTED') {
|
|
255
|
+
yield __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").repopulateAvailableDevices();
|
|
256
|
+
}
|
|
257
|
+
this.permissions.audio = 'ACCEPTED';
|
|
258
|
+
this.emit('MEDIA_PERMISSION_UPDATE', {
|
|
259
|
+
kind: 'audio',
|
|
260
|
+
message: this.permissions.audio,
|
|
261
|
+
});
|
|
262
|
+
this.emit('DEVICE_CHANGE', {
|
|
263
|
+
device: this.currentDevices.audio,
|
|
264
|
+
});
|
|
265
|
+
/*
|
|
266
|
+
TODO
|
|
267
|
+
callStats.mediaPermission('AUDIO', CallStatsPermissionEnum.ACCEPTED);
|
|
268
|
+
callStats.selectedDevice('AUDIO', this.currentDevices.audio); */
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
onVisibilityChange() {
|
|
272
|
+
// pass
|
|
273
|
+
}
|
|
274
|
+
setupVideoStream(deviceId_1) {
|
|
275
|
+
return __awaiter(this, arguments, void 0, function* (deviceId, forceStopTrack = false) {
|
|
276
|
+
var _a, _b, _c;
|
|
277
|
+
const videoDevices = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getVideoDevices();
|
|
278
|
+
if (!videoDevices.length) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
let videoDeviceId = deviceId;
|
|
282
|
+
if (!videoDeviceId) {
|
|
283
|
+
videoDeviceId = (yield this.getOperationalWebcamDeviceId()).deviceId;
|
|
284
|
+
}
|
|
285
|
+
if (((_a = this.currentDevices.video) === null || _a === void 0 ? void 0 : _a.deviceId) !== videoDeviceId) {
|
|
286
|
+
this.currentDevices.video = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getDeviceById(videoDeviceId, 'videoinput');
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* NOTE(roerohan): this.videoEnabled is checked, so that upon device change,
|
|
290
|
+
* the video track is not set when the user has turned off his camera.
|
|
291
|
+
*/
|
|
292
|
+
if (this.videoEnabled) {
|
|
293
|
+
const videoConstraints = LocalMediaUtils.getVideoConstraints({
|
|
294
|
+
videoDeviceId,
|
|
295
|
+
});
|
|
296
|
+
if (!this.rawVideoTrack) {
|
|
297
|
+
this.rawVideoTrack = yield LocalMediaUtils.getVideoTrack(videoConstraints);
|
|
298
|
+
}
|
|
299
|
+
this.setVideoTrack(this.rawVideoTrack);
|
|
300
|
+
this.addMediaStreamTrackListeners(this.rawVideoTrack);
|
|
301
|
+
}
|
|
302
|
+
if (forceStopTrack) {
|
|
303
|
+
(_b = this.videoTrack) === null || _b === void 0 ? void 0 : _b.stop();
|
|
304
|
+
(_c = this.rawVideoTrack) === null || _c === void 0 ? void 0 : _c.stop();
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* NOTE(roerohan): Firefox does not show device labels until permissions are granted.
|
|
308
|
+
* So, we need to repopulate the devices once permission is granted.
|
|
309
|
+
*/
|
|
310
|
+
if (this.videoTrack && this.permissions.video === 'NOT_REQUESTED') {
|
|
311
|
+
yield __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").repopulateAvailableDevices();
|
|
312
|
+
}
|
|
313
|
+
this.permissions.video = 'ACCEPTED';
|
|
314
|
+
this.emit('MEDIA_PERMISSION_UPDATE', {
|
|
315
|
+
kind: 'video',
|
|
316
|
+
message: this.permissions.video,
|
|
317
|
+
});
|
|
318
|
+
this.emit('DEVICE_CHANGE', {
|
|
319
|
+
device: this.currentDevices.video,
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
setupSpeaker(deviceId) {
|
|
324
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
var _a;
|
|
326
|
+
const speakerDevices = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getSpeakerDevices();
|
|
327
|
+
if (!speakerDevices.length) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const speakerDeviceId = deviceId !== null && deviceId !== void 0 ? deviceId : speakerDevices[0].deviceId;
|
|
331
|
+
if (((_a = this.currentDevices.speaker) === null || _a === void 0 ? void 0 : _a.deviceId) !== speakerDeviceId) {
|
|
332
|
+
this.currentDevices.speaker = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getDeviceById(speakerDeviceId, 'audiooutput');
|
|
333
|
+
}
|
|
334
|
+
this.emit('DEVICE_CHANGE', {
|
|
335
|
+
device: this.currentDevices.speaker,
|
|
336
|
+
});
|
|
337
|
+
/*
|
|
338
|
+
TODO
|
|
339
|
+
const speakerDeviceId = deviceId ?? speakerDevices[0].deviceId;
|
|
340
|
+
if (this.currentDevices.speaker?.deviceId !== speakerDeviceId) {
|
|
341
|
+
this.currentDevices.speaker = this.#localMediaUtils.getDeviceById(
|
|
342
|
+
speakerDeviceId,
|
|
343
|
+
'audiooutput'
|
|
344
|
+
);
|
|
345
|
+
callStats.selectedDevice('SPEAKER', this.currentDevices.speaker);
|
|
346
|
+
} */
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
getOperationalWebcamDeviceId() {
|
|
350
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
351
|
+
let videoDevices = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getVideoDevices();
|
|
352
|
+
if (!videoDevices.length) {
|
|
353
|
+
return { isOperational: false, deviceId: null };
|
|
354
|
+
}
|
|
355
|
+
/*
|
|
356
|
+
NOTE(ravindra-dyte): Usually external devices come at the bottom,
|
|
357
|
+
By reversing the deviceList and breaking on first operational device
|
|
358
|
+
We are giving preference to external device
|
|
359
|
+
*/
|
|
360
|
+
videoDevices = [...videoDevices].reverse();
|
|
361
|
+
let operationalDeviceId = null;
|
|
362
|
+
for (let deviceIndex = 0; deviceIndex < videoDevices.length; deviceIndex += 1) {
|
|
363
|
+
try {
|
|
364
|
+
operationalDeviceId = videoDevices[deviceIndex].deviceId;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
catch (err) { }
|
|
368
|
+
}
|
|
369
|
+
return operationalDeviceId
|
|
370
|
+
? { isOperational: true, deviceId: operationalDeviceId }
|
|
371
|
+
: { isOperational: false, deviceId: videoDevices[0].deviceId };
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
getOperationalMicDeviceId() {
|
|
375
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
376
|
+
let audioDevices = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getAudioDevices();
|
|
377
|
+
// console.log(
|
|
378
|
+
// 'getOperationalMicDeviceId: ',
|
|
379
|
+
// JSON.stringify(audioDevices, null, 2)
|
|
380
|
+
// );
|
|
381
|
+
if (!audioDevices.length) {
|
|
382
|
+
return { isOperational: false, deviceId: null };
|
|
383
|
+
}
|
|
384
|
+
/*
|
|
385
|
+
NOTE(ravindra-dyte): Usually external devices come at the bottom,
|
|
386
|
+
By reversing the deviceList and breaking on first operational device
|
|
387
|
+
We are giving preference to external device
|
|
388
|
+
*/
|
|
389
|
+
audioDevices = [...audioDevices].reverse();
|
|
390
|
+
// console.log(
|
|
391
|
+
// 'getOperationalMicDeviceId Reverse: ',
|
|
392
|
+
// JSON.stringify(audioDevices, null, 2)
|
|
393
|
+
// );
|
|
394
|
+
let operationalDeviceId = null;
|
|
395
|
+
for (let deviceIndex = 0; deviceIndex < audioDevices.length; deviceIndex += 1) {
|
|
396
|
+
try {
|
|
397
|
+
const audioTrack = yield LocalMediaUtils.getAudioTrack();
|
|
398
|
+
const isSilent = yield checkIfAudioTrackIsSilent(audioTrack);
|
|
399
|
+
audioTrack.stop();
|
|
400
|
+
audioTrack.release();
|
|
401
|
+
if (!isSilent) {
|
|
402
|
+
operationalDeviceId = audioDevices[deviceIndex].deviceId;
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
catch (err) { }
|
|
407
|
+
}
|
|
408
|
+
return operationalDeviceId
|
|
409
|
+
? { isOperational: true, deviceId: operationalDeviceId }
|
|
410
|
+
: { isOperational: false, deviceId: audioDevices[0].deviceId };
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
setupStreams(_a) {
|
|
414
|
+
return __awaiter(this, arguments, void 0, function* ({ audio, video, }) {
|
|
415
|
+
var _b, _c, _d;
|
|
416
|
+
try {
|
|
417
|
+
const permResult = yield setupPermissions(audio, video);
|
|
418
|
+
this.permissions.video = permResult.camera;
|
|
419
|
+
this.permissions.audio = permResult.microphone;
|
|
420
|
+
}
|
|
421
|
+
catch (val) {
|
|
422
|
+
this.permissions.video = (_b = val.camera) !== null && _b !== void 0 ? _b : false;
|
|
423
|
+
this.permissions.audio = (_c = val.microphone) !== null && _c !== void 0 ? _c : false;
|
|
424
|
+
}
|
|
425
|
+
const constraints = {};
|
|
426
|
+
if (!this.currentDevices) {
|
|
427
|
+
this.currentDevices = {
|
|
428
|
+
audio: undefined,
|
|
429
|
+
video: undefined,
|
|
430
|
+
speaker: undefined,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
if (audio) {
|
|
434
|
+
const audioDevices = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getAudioDevices();
|
|
435
|
+
if (audioDevices.length !== 0) {
|
|
436
|
+
const audioDeviceId = (yield this.getOperationalMicDeviceId()).deviceId;
|
|
437
|
+
this.currentDevices.audio = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getDeviceById(audioDeviceId, 'audioinput');
|
|
438
|
+
constraints.audio = true;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
if (video) {
|
|
442
|
+
const videoDevices = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getVideoDevices();
|
|
443
|
+
if (videoDevices.length !== 0) {
|
|
444
|
+
const videoDeviceId = (yield this.getOperationalWebcamDeviceId())
|
|
445
|
+
.deviceId;
|
|
446
|
+
this.currentDevices.video = __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getDeviceById(videoDeviceId, 'videoinput');
|
|
447
|
+
const videoConstraints = LocalMediaUtils.getVideoConstraints({
|
|
448
|
+
videoDeviceId,
|
|
449
|
+
});
|
|
450
|
+
constraints.video = videoConstraints.video;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const { audioTrack, videoTrack } = yield LocalMediaUtils.getAudioAndVideoTrack(constraints);
|
|
454
|
+
if (audio && audioTrack) {
|
|
455
|
+
this.rawAudioTrack = audioTrack;
|
|
456
|
+
this.permissions.audio = 'ACCEPTED';
|
|
457
|
+
}
|
|
458
|
+
this.emit('MEDIA_PERMISSION_UPDATE', {
|
|
459
|
+
kind: 'audio',
|
|
460
|
+
message: this.permissions.audio,
|
|
461
|
+
});
|
|
462
|
+
if (video && videoTrack) {
|
|
463
|
+
this.rawVideoTrack = videoTrack;
|
|
464
|
+
this.permissions.video = 'ACCEPTED';
|
|
465
|
+
}
|
|
466
|
+
this.emit('MEDIA_PERMISSION_UPDATE', {
|
|
467
|
+
kind: 'video',
|
|
468
|
+
message: this.permissions.video,
|
|
469
|
+
});
|
|
470
|
+
if (((_d = Object.keys(constraints)) === null || _d === void 0 ? void 0 : _d.length) === 0) {
|
|
471
|
+
this.audioEnabled = false;
|
|
472
|
+
this.videoEnabled = false;
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
if (audio)
|
|
476
|
+
yield this.setupAudioStream();
|
|
477
|
+
if (video)
|
|
478
|
+
yield this.setupVideoStream();
|
|
479
|
+
if (audioTrack)
|
|
480
|
+
this.audioEnabled = true;
|
|
481
|
+
if (videoTrack)
|
|
482
|
+
this.videoEnabled = true;
|
|
483
|
+
this.screenShareEnabled = false;
|
|
484
|
+
yield this.setupSpeaker();
|
|
485
|
+
// Setup Foreground Service after handling permissions
|
|
486
|
+
if (Platform.OS === 'android') {
|
|
487
|
+
__classPrivateFieldSet(this, _LocalMediaHandler_appStateSubscription, AppState.addEventListener('change', this._handleAppStateChange), "f");
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
stopAudioTrack() {
|
|
492
|
+
var _a, _b;
|
|
493
|
+
(_a = this.audioTrack) === null || _a === void 0 ? void 0 : _a.stop();
|
|
494
|
+
(_b = this.audioTrack) === null || _b === void 0 ? void 0 : _b.release();
|
|
495
|
+
this.audioEnabled = false;
|
|
496
|
+
}
|
|
497
|
+
stopVideoTrack() {
|
|
498
|
+
var _a, _b, _c, _d;
|
|
499
|
+
(_a = this.rawVideoTrack) === null || _a === void 0 ? void 0 : _a.stop();
|
|
500
|
+
(_b = this.videoTrack) === null || _b === void 0 ? void 0 : _b.stop();
|
|
501
|
+
(_c = this.rawVideoTrack) === null || _c === void 0 ? void 0 : _c.release();
|
|
502
|
+
(_d = this.videoTrack) === null || _d === void 0 ? void 0 : _d.release();
|
|
503
|
+
}
|
|
504
|
+
stopScreenShareTracks(tracks = {}) {
|
|
505
|
+
var _a, _b, _c, _d;
|
|
506
|
+
const { audio = true, video = true } = tracks;
|
|
507
|
+
if (audio) {
|
|
508
|
+
(_b = (_a = this.screenShareTracks) === null || _a === void 0 ? void 0 : _a.audio) === null || _b === void 0 ? void 0 : _b.stop();
|
|
509
|
+
}
|
|
510
|
+
if (video) {
|
|
511
|
+
(_d = (_c = this.screenShareTracks) === null || _c === void 0 ? void 0 : _c.video) === null || _d === void 0 ? void 0 : _d.stop();
|
|
512
|
+
}
|
|
513
|
+
if (audio && video) {
|
|
514
|
+
this.screenShareEnabled = false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
removeAudioTrack() {
|
|
518
|
+
this.stopAudioTrack();
|
|
519
|
+
this.audioTrack = undefined;
|
|
520
|
+
this.rawAudioTrack = undefined;
|
|
521
|
+
}
|
|
522
|
+
removeVideoTrack() {
|
|
523
|
+
this.stopVideoTrack();
|
|
524
|
+
this.videoTrack = undefined;
|
|
525
|
+
this.rawVideoTrack = undefined;
|
|
526
|
+
}
|
|
527
|
+
removeScreenShareTracks(tracks) {
|
|
528
|
+
var _a;
|
|
529
|
+
(_a = this.screenShareTracks.video) === null || _a === void 0 ? void 0 : _a.removeEventListener('ended', this.onScreenShareEnded);
|
|
530
|
+
this.stopScreenShareTracks(tracks);
|
|
531
|
+
this.screenShareTracks = {
|
|
532
|
+
audio: undefined,
|
|
533
|
+
video: undefined,
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
removeAllTracks() {
|
|
537
|
+
this.removeAudioTrack();
|
|
538
|
+
this.removeVideoTrack();
|
|
539
|
+
this.removeScreenShareTracks();
|
|
540
|
+
}
|
|
541
|
+
setAudioTrack(audioTrack) {
|
|
542
|
+
if (audioTrack === this.audioTrack) {
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if (audioTrack === undefined) {
|
|
546
|
+
this.stopAudioTrack();
|
|
547
|
+
}
|
|
548
|
+
this.audioTrack = audioTrack;
|
|
549
|
+
}
|
|
550
|
+
setVideoTrack(videoTrack) {
|
|
551
|
+
if (videoTrack === this.videoTrack) {
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
if (videoTrack === undefined) {
|
|
555
|
+
this.stopVideoTrack();
|
|
556
|
+
}
|
|
557
|
+
this.videoTrack = videoTrack;
|
|
558
|
+
}
|
|
559
|
+
setScreenShareTracks(tracks) {
|
|
560
|
+
var _a;
|
|
561
|
+
const { audio, video } = tracks;
|
|
562
|
+
// console.log('SetScreenshare called');
|
|
563
|
+
if (!audio || !video) {
|
|
564
|
+
this.stopScreenShareTracks({ audio: !!audio, video: !!video });
|
|
565
|
+
}
|
|
566
|
+
this.screenShareTracks = tracks;
|
|
567
|
+
(_a = this.screenShareTracks.video) === null || _a === void 0 ? void 0 : _a.addEventListener('ended', this.onScreenShareEnded.bind(this));
|
|
568
|
+
}
|
|
569
|
+
onScreenShareEnded() {
|
|
570
|
+
this.emit('SCREENSHARE_ENDED');
|
|
571
|
+
}
|
|
572
|
+
disableAudio() {
|
|
573
|
+
this.audioEnabled = false;
|
|
574
|
+
if (this.audioTrack) {
|
|
575
|
+
this.audioTrack.enabled = this.audioEnabled;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
enableAudio() {
|
|
579
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
580
|
+
var _a, _b;
|
|
581
|
+
if (this.permissions.audio !== 'ACCEPTED') {
|
|
582
|
+
try {
|
|
583
|
+
const permResult = yield setupPermissions(true, false);
|
|
584
|
+
this.permissions.audio = permResult.microphone;
|
|
585
|
+
}
|
|
586
|
+
catch (val) {
|
|
587
|
+
this.permissions.audio = (_a = val.microphone) !== null && _a !== void 0 ? _a : false;
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
this.emit('MEDIA_PERMISSION_UPDATE', {
|
|
591
|
+
kind: 'audio',
|
|
592
|
+
message: this.permissions.audio,
|
|
593
|
+
});
|
|
594
|
+
if (this.permissions.audio === 'DENIED') {
|
|
595
|
+
this.audioEnabled = false;
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
try {
|
|
599
|
+
/**
|
|
600
|
+
* NOTE (@madhugb): We need to setup new stream,
|
|
601
|
+
* if the audio track is not preset or it has ended
|
|
602
|
+
*/
|
|
603
|
+
if (!this.audioTrack || this.audioTrack.readyState === 'ended') {
|
|
604
|
+
yield this.setupAudioStream((_b = this.currentDevices.audio) === null || _b === void 0 ? void 0 : _b.deviceId);
|
|
605
|
+
}
|
|
606
|
+
// if we still can't get a track after setting up audio stream
|
|
607
|
+
// do not toggle the audio state
|
|
608
|
+
if (!this.audioTrack) {
|
|
609
|
+
this.audioEnabled = false;
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
this.audioEnabled = true;
|
|
613
|
+
}
|
|
614
|
+
catch (ex) {
|
|
615
|
+
this.audioEnabled = false;
|
|
616
|
+
this.audioTrack = undefined;
|
|
617
|
+
this.rawAudioTrack = undefined;
|
|
618
|
+
}
|
|
619
|
+
if (this.audioTrack) {
|
|
620
|
+
this.audioTrack.enabled = true;
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
enableVideo() {
|
|
625
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
626
|
+
yield this.toggleVideo();
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
disableVideo() {
|
|
630
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
631
|
+
yield this.toggleVideo();
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
toggleAudio() {
|
|
635
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
636
|
+
var _a;
|
|
637
|
+
if (this.permissions.audio === 'DENIED') {
|
|
638
|
+
this.audioEnabled = false;
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (!this.audioTrack) {
|
|
642
|
+
yield this.setupAudioStream((_a = this.currentDevices.audio) === null || _a === void 0 ? void 0 : _a.deviceId);
|
|
643
|
+
}
|
|
644
|
+
this.audioEnabled = !this.audioEnabled;
|
|
645
|
+
this.audioTrack.enabled = this.audioEnabled;
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
toggleVideo() {
|
|
649
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
650
|
+
var _a, _b;
|
|
651
|
+
if (this.permissions.video !== 'ACCEPTED') {
|
|
652
|
+
try {
|
|
653
|
+
const permResult = yield setupPermissions(false, true);
|
|
654
|
+
this.permissions.video = permResult.camera;
|
|
655
|
+
}
|
|
656
|
+
catch (val) {
|
|
657
|
+
this.permissions.video = (_a = val.camera) !== null && _a !== void 0 ? _a : false;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
this.emit('MEDIA_PERMISSION_UPDATE', {
|
|
661
|
+
kind: 'video',
|
|
662
|
+
message: this.permissions.video,
|
|
663
|
+
});
|
|
664
|
+
if (this.permissions.video === 'DENIED') {
|
|
665
|
+
this.videoEnabled = false;
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
if (this.videoEnabled) {
|
|
669
|
+
this.removeVideoTrack();
|
|
670
|
+
this.videoEnabled = false;
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* NOTE(roerohan): The videoEnabled flag is used inside the setupVideoStream method
|
|
675
|
+
* hence it must be set to true first.
|
|
676
|
+
*/
|
|
677
|
+
this.videoEnabled = true;
|
|
678
|
+
yield this.setupVideoStream((_b = this.currentDevices.video) === null || _b === void 0 ? void 0 : _b.deviceId);
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
setAudioDevice(device) {
|
|
682
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
683
|
+
yield __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").chooseAudioRoute(device.deviceId);
|
|
684
|
+
this.setupAudioStream(device.deviceId);
|
|
685
|
+
this.emit('AUDIO_TRACK_CHANGE');
|
|
686
|
+
this.emit('DEVICE_CHANGE', { device });
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
setVideoDevice(device) {
|
|
690
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
691
|
+
if (this.videoEnabled) {
|
|
692
|
+
this.removeVideoTrack();
|
|
693
|
+
}
|
|
694
|
+
yield this.setupVideoStream(device.deviceId);
|
|
695
|
+
this.emit('VIDEO_TRACK_CHANGE');
|
|
696
|
+
this.emit('DEVICE_CHANGE', { device });
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
setSpeakerDevice(device) {
|
|
700
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
701
|
+
yield this.setupSpeaker(device.deviceId);
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
setDevice(route) {
|
|
705
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
706
|
+
return yield __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").chooseAudioRoute(route.deviceId);
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
oniOSBroadcastStart() {
|
|
710
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
711
|
+
this.setScreenShareTracks(yield LocalMediaUtils.getScreenShareTracks());
|
|
712
|
+
this.screenShareEnabled = true;
|
|
713
|
+
this.emit('SCREENSHARE_TRACK_CHANGE');
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
oniOSBroadcastStop() {
|
|
717
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
718
|
+
if (this.screenShareEnabled) {
|
|
719
|
+
this.removeScreenShareTracks();
|
|
720
|
+
this.emit('SCREENSHARE_TRACK_CHANGE');
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
toggleScreenShare() {
|
|
726
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
727
|
+
if (this.screenShareEnabled && Platform.OS !== 'ios') {
|
|
728
|
+
this.removeScreenShareTracks();
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
if (Platform.OS === 'ios' && this.screenShareEnabled) {
|
|
732
|
+
NativeModules.DyteScreensharePickerView.showScreenSharePickerView();
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
if (Platform.OS === 'android') {
|
|
736
|
+
/* getDisplayMedia() needs to be called before configureForeground()
|
|
737
|
+
This is because we need to get user permission starting foreground service in Android >=14
|
|
738
|
+
1. createScreenCaptureIntent() -> startForeground()
|
|
739
|
+
*/
|
|
740
|
+
this.setScreenShareTracks(yield LocalMediaUtils.getScreenShareTracks());
|
|
741
|
+
yield this.configureForeground();
|
|
742
|
+
this.screenShareEnabled = true;
|
|
743
|
+
}
|
|
744
|
+
if (Platform.OS === 'ios') {
|
|
745
|
+
NativeModules.DyteScreensharePickerView.showScreenSharePickerView();
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
enableScreenShare() {
|
|
750
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
751
|
+
yield this.toggleScreenShare();
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
disableScreenShare() {
|
|
755
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
756
|
+
yield this.toggleScreenShare();
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
destruct() {
|
|
760
|
+
this.removeAllTracks();
|
|
761
|
+
this.removeAllListeners();
|
|
762
|
+
InCallManger.stop(undefined);
|
|
763
|
+
}
|
|
764
|
+
getAllDevices() {
|
|
765
|
+
return __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").availableDevices;
|
|
766
|
+
}
|
|
767
|
+
getCurrentDevices() {
|
|
768
|
+
return this.currentDevices;
|
|
769
|
+
}
|
|
770
|
+
getDeviceById(deviceId, kind) {
|
|
771
|
+
return __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getDeviceById(deviceId, kind);
|
|
772
|
+
}
|
|
773
|
+
getAudioDevices() {
|
|
774
|
+
return __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getAudioDevices();
|
|
775
|
+
}
|
|
776
|
+
getVideoDevices() {
|
|
777
|
+
return __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getVideoDevices();
|
|
778
|
+
}
|
|
779
|
+
getSpeakerDevices() {
|
|
780
|
+
return __classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").getSpeakerDevices();
|
|
781
|
+
}
|
|
782
|
+
onDeviceChange(changedDevices, forceDeviceChange) {
|
|
783
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
784
|
+
let addedDevice;
|
|
785
|
+
let removedDevice;
|
|
786
|
+
if (changedDevices.added.length)
|
|
787
|
+
[addedDevice] = changedDevices.added;
|
|
788
|
+
if (changedDevices.removed.length)
|
|
789
|
+
[removedDevice] = changedDevices.removed;
|
|
790
|
+
/**
|
|
791
|
+
* NOTE(roerohan): forceStopTrack is set required to be set to true for firefox.
|
|
792
|
+
* https://stackoverflow.com/questions/59068146/navigator-mediadevices-getusermedia-api-rejecting-with-error-notreadableerror
|
|
793
|
+
* forceStopTrack is the second argument of setupAudioStream and setupVideoStream.
|
|
794
|
+
*/
|
|
795
|
+
if (addedDevice) {
|
|
796
|
+
if (addedDevice.kind === 'audioinput') {
|
|
797
|
+
yield this.setupAudioStream(addedDevice.deviceId);
|
|
798
|
+
this.emit('DEVICE_CHANGE', this.currentDevices.audio);
|
|
799
|
+
}
|
|
800
|
+
else if (addedDevice.kind === 'videoinput') {
|
|
801
|
+
yield this.setupVideoStream(addedDevice.deviceId);
|
|
802
|
+
this.emit('DEVICE_CHANGE', this.currentDevices.video);
|
|
803
|
+
}
|
|
804
|
+
else if (addedDevice.kind === 'audiooutput') {
|
|
805
|
+
yield this.setupSpeaker(addedDevice.deviceId);
|
|
806
|
+
}
|
|
807
|
+
this.emit('AUDIO_TRACK_CHANGE');
|
|
808
|
+
}
|
|
809
|
+
if (removedDevice) {
|
|
810
|
+
if (removedDevice.kind === 'audioinput') {
|
|
811
|
+
yield this.setupAudioStream();
|
|
812
|
+
}
|
|
813
|
+
else if (removedDevice.kind === 'videoinput') {
|
|
814
|
+
yield this.setupVideoStream();
|
|
815
|
+
}
|
|
816
|
+
else if (removedDevice.kind === 'audiooutput') {
|
|
817
|
+
yield this.setupSpeaker();
|
|
818
|
+
}
|
|
819
|
+
this.emit('AUDIO_TRACK_CHANGE');
|
|
820
|
+
}
|
|
821
|
+
this.emit('DEVICE_LIST_UPDATED', changedDevices);
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
cleanUpTracks() {
|
|
825
|
+
var _a, _b, _c, _d;
|
|
826
|
+
(_a = this.audioTrack) === null || _a === void 0 ? void 0 : _a.stop();
|
|
827
|
+
(_b = this.rawAudioTrack) === null || _b === void 0 ? void 0 : _b.stop();
|
|
828
|
+
(_c = this.videoTrack) === null || _c === void 0 ? void 0 : _c.stop();
|
|
829
|
+
(_d = this.rawVideoTrack) === null || _d === void 0 ? void 0 : _d.stop();
|
|
830
|
+
this.destructor();
|
|
831
|
+
}
|
|
832
|
+
destructMediaHandler() {
|
|
833
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
834
|
+
__classPrivateFieldGet(this, _LocalMediaHandler_localMediaUtils, "f").destruct();
|
|
835
|
+
return this.destruct();
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
static init(_) {
|
|
839
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
840
|
+
yield setupPermissions(true, true);
|
|
841
|
+
const localMediaUtils = yield LocalMediaUtils.init();
|
|
842
|
+
return new LocalMediaHandler(localMediaUtils);
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
emit(event, ...args) {
|
|
846
|
+
return super.emit(event, ...args);
|
|
847
|
+
}
|
|
848
|
+
on(event, listener) {
|
|
849
|
+
return super.on(event, listener);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
_LocalMediaHandler_localMediaUtils = new WeakMap(), _LocalMediaHandler_appState = new WeakMap(), _LocalMediaHandler_appStateSubscription = new WeakMap(), _LocalMediaHandler_interval = new WeakMap();
|
|
853
|
+
export default LocalMediaHandler;
|