@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,76 @@
|
|
|
1
|
+
export type MediaDeviceKind = 'audioinput' | 'audiooutput' | 'videoinput';
|
|
2
|
+
export interface MediaDeviceInfo {
|
|
3
|
+
readonly deviceId: string;
|
|
4
|
+
readonly groupId: string;
|
|
5
|
+
readonly kind: MediaDeviceKind;
|
|
6
|
+
readonly label: string;
|
|
7
|
+
readonly facing: string;
|
|
8
|
+
toJSON(): any;
|
|
9
|
+
}
|
|
10
|
+
interface ULongRange {
|
|
11
|
+
max?: number;
|
|
12
|
+
min?: number;
|
|
13
|
+
}
|
|
14
|
+
interface DoubleRange {
|
|
15
|
+
max?: number;
|
|
16
|
+
min?: number;
|
|
17
|
+
}
|
|
18
|
+
interface ConstrainDoubleRange extends DoubleRange {
|
|
19
|
+
exact?: number;
|
|
20
|
+
ideal?: number;
|
|
21
|
+
}
|
|
22
|
+
interface ConstrainDOMStringParameters {
|
|
23
|
+
exact?: string | string[];
|
|
24
|
+
ideal?: string | string[];
|
|
25
|
+
}
|
|
26
|
+
interface ConstrainULongRange extends ULongRange {
|
|
27
|
+
exact?: number;
|
|
28
|
+
ideal?: number;
|
|
29
|
+
}
|
|
30
|
+
interface ConstrainBooleanParameters {
|
|
31
|
+
exact?: boolean;
|
|
32
|
+
ideal?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export type ConstrainBoolean = boolean | ConstrainBooleanParameters;
|
|
35
|
+
export type ConstrainDOMString = string | string[] | ConstrainDOMStringParameters;
|
|
36
|
+
export type ConstrainDouble = number | ConstrainDoubleRange;
|
|
37
|
+
export type ConstrainULong = number | ConstrainULongRange;
|
|
38
|
+
export interface MediaTrackConstraintSet {
|
|
39
|
+
aspectRatio?: ConstrainDouble;
|
|
40
|
+
autoGainControl?: ConstrainBoolean;
|
|
41
|
+
channelCount?: ConstrainULong;
|
|
42
|
+
deviceId?: ConstrainDOMString;
|
|
43
|
+
echoCancellation?: ConstrainBoolean;
|
|
44
|
+
facingMode?: ConstrainDOMString;
|
|
45
|
+
frameRate?: ConstrainDouble;
|
|
46
|
+
groupId?: ConstrainDOMString;
|
|
47
|
+
height?: ConstrainULong;
|
|
48
|
+
latency?: ConstrainDouble;
|
|
49
|
+
noiseSuppression?: ConstrainBoolean;
|
|
50
|
+
sampleRate?: ConstrainULong;
|
|
51
|
+
sampleSize?: ConstrainULong;
|
|
52
|
+
suppressLocalAudioPlayback?: ConstrainBoolean;
|
|
53
|
+
width?: ConstrainULong;
|
|
54
|
+
}
|
|
55
|
+
interface MediaStreamConstraints {
|
|
56
|
+
audio?: boolean | MediaTrackConstraints;
|
|
57
|
+
peerIdentity?: string;
|
|
58
|
+
preferCurrentTab?: boolean;
|
|
59
|
+
video?: boolean | MediaTrackConstraints;
|
|
60
|
+
}
|
|
61
|
+
export interface MediaTrackConstraints extends MediaTrackConstraintSet {
|
|
62
|
+
advanced?: MediaTrackConstraintSet[];
|
|
63
|
+
}
|
|
64
|
+
export type VideoQuality = 'qvga' | 'vga' | 'hd' | 'hd_cropped';
|
|
65
|
+
export type ScreenShareQuality = 'vga' | 'hd' | 'full_hd';
|
|
66
|
+
export interface RealtimeKitMediaTrackConstraints extends MediaTrackConstraints {
|
|
67
|
+
optional?: Array<object>;
|
|
68
|
+
}
|
|
69
|
+
export interface RealtimeKitMediaStreamConstraints extends MediaStreamConstraints {
|
|
70
|
+
audio?: boolean | RealtimeKitMediaTrackConstraints;
|
|
71
|
+
}
|
|
72
|
+
export interface VideoConstraints {
|
|
73
|
+
[key: string]: RealtimeKitMediaTrackConstraints;
|
|
74
|
+
}
|
|
75
|
+
export type MediaPermission = 'ACCEPTED' | 'DENIED' | 'SYS_DENIED' | 'UNAVAILABLE' | 'NOT_REQUESTED';
|
|
76
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { ConstrainDouble, RealtimeKitMediaStreamConstraints, RealtimeKitMediaTrackConstraints, MediaDeviceInfo } from './LocalMediaInterfaces';
|
|
2
|
+
export interface LocalAudioOptions {
|
|
3
|
+
disableAP?: boolean;
|
|
4
|
+
disableAEC?: boolean;
|
|
5
|
+
disableNS?: boolean;
|
|
6
|
+
disableAGC?: boolean;
|
|
7
|
+
disableHPF?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const VIDEO_CONSTRAINTS: {
|
|
10
|
+
qvga: {
|
|
11
|
+
width: {
|
|
12
|
+
ideal: number;
|
|
13
|
+
};
|
|
14
|
+
height: {
|
|
15
|
+
ideal: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
vga: {
|
|
19
|
+
width: {
|
|
20
|
+
ideal: number;
|
|
21
|
+
};
|
|
22
|
+
height: {
|
|
23
|
+
ideal: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
hd: {
|
|
27
|
+
width: {
|
|
28
|
+
ideal: number;
|
|
29
|
+
};
|
|
30
|
+
height: {
|
|
31
|
+
ideal: number;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
hd_cropped: {
|
|
35
|
+
width: {
|
|
36
|
+
ideal: number;
|
|
37
|
+
};
|
|
38
|
+
height: {
|
|
39
|
+
ideal: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* To initialize an instance of this class, use the
|
|
45
|
+
* `.init()` static method.
|
|
46
|
+
*/
|
|
47
|
+
export default class LocalMediaUtils {
|
|
48
|
+
#private;
|
|
49
|
+
private constructor();
|
|
50
|
+
static init(): Promise<LocalMediaUtils>;
|
|
51
|
+
destruct(): Promise<void>;
|
|
52
|
+
static isDeviceListAvailable(): boolean;
|
|
53
|
+
private static enumerateVideoDevices;
|
|
54
|
+
private static enumerateAudioDevices;
|
|
55
|
+
static getVideoConstraints(options?: {
|
|
56
|
+
videoDeviceId?: string;
|
|
57
|
+
videoTrackConstraints?: boolean | RealtimeKitMediaTrackConstraints;
|
|
58
|
+
facingMode?: string;
|
|
59
|
+
frameRate?: ConstrainDouble;
|
|
60
|
+
}): RealtimeKitMediaStreamConstraints;
|
|
61
|
+
private static getUserMediaWithTimeout;
|
|
62
|
+
static getAudioTrack(): Promise<import("@dyteinternals/react-native-webrtc").MediaStreamTrack>;
|
|
63
|
+
static getVideoTrack(constraints: RealtimeKitMediaStreamConstraints): Promise<import("@dyteinternals/react-native-webrtc").MediaStreamTrack>;
|
|
64
|
+
static getScreenShareTracks(): Promise<{
|
|
65
|
+
video: import("@dyteinternals/react-native-webrtc").MediaStreamTrack;
|
|
66
|
+
audio: import("@dyteinternals/react-native-webrtc").MediaStreamTrack;
|
|
67
|
+
}>;
|
|
68
|
+
static getAudioAndVideoTrack(constraints: RealtimeKitMediaStreamConstraints): Promise<{
|
|
69
|
+
audioTrack: import("@dyteinternals/react-native-webrtc").MediaStreamTrack;
|
|
70
|
+
videoTrack: import("@dyteinternals/react-native-webrtc").MediaStreamTrack;
|
|
71
|
+
}>;
|
|
72
|
+
onDeviceChange(callback: (changedDevices: {
|
|
73
|
+
added: MediaDeviceInfo[];
|
|
74
|
+
removed: MediaDeviceInfo[];
|
|
75
|
+
}, forceDeviceChange?: boolean) => void): void;
|
|
76
|
+
repopulateAvailableDevices(): Promise<void>;
|
|
77
|
+
chooseAudioRoute(route: String): Promise<any>;
|
|
78
|
+
get availableDevices(): MediaDeviceInfo[];
|
|
79
|
+
getAvailableDevicesByKind(kind: string): MediaDeviceInfo[];
|
|
80
|
+
getDeviceById(deviceId: string, kind: 'audioinput' | 'audiooutput' | 'videoinput'): MediaDeviceInfo;
|
|
81
|
+
/**
|
|
82
|
+
* Returns all audio input devices (microphone devices).
|
|
83
|
+
*/
|
|
84
|
+
getAudioDevices(): MediaDeviceInfo[];
|
|
85
|
+
/**
|
|
86
|
+
* Returns all video input devices.
|
|
87
|
+
*/
|
|
88
|
+
getVideoDevices(): MediaDeviceInfo[];
|
|
89
|
+
/**
|
|
90
|
+
* Returns all audio output devices (speaker devices).
|
|
91
|
+
*/
|
|
92
|
+
getSpeakerDevices(): MediaDeviceInfo[];
|
|
93
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
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 _LocalMediaUtils_availableDevices, _LocalMediaUtils_nativeEventEmitter;
|
|
22
|
+
import { NativeEventEmitter, NativeModules, LogBox } from 'react-native';
|
|
23
|
+
import { mediaDevices } from '@dyteinternals/react-native-webrtc';
|
|
24
|
+
import LocalMediaError from './LocalMediaError';
|
|
25
|
+
import NativeAudioManager from './NativeAudioManager';
|
|
26
|
+
LogBox.ignoreLogs(['new NativeEventEmitter']);
|
|
27
|
+
export const VIDEO_CONSTRAINTS = {
|
|
28
|
+
qvga: { width: { ideal: 320 }, height: { ideal: 240 } },
|
|
29
|
+
vga: { width: { ideal: 640 }, height: { ideal: 480 } },
|
|
30
|
+
hd: { width: { ideal: 1280 }, height: { ideal: 720 } },
|
|
31
|
+
hd_cropped: { width: { ideal: 900 }, height: { ideal: 720 } },
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* To initialize an instance of this class, use the
|
|
35
|
+
* `.init()` static method.
|
|
36
|
+
*/
|
|
37
|
+
class LocalMediaUtils {
|
|
38
|
+
constructor(availableDevices) {
|
|
39
|
+
_LocalMediaUtils_availableDevices.set(this, void 0);
|
|
40
|
+
_LocalMediaUtils_nativeEventEmitter.set(this, void 0);
|
|
41
|
+
__classPrivateFieldSet(this, _LocalMediaUtils_availableDevices, availableDevices, "f");
|
|
42
|
+
__classPrivateFieldSet(this, _LocalMediaUtils_nativeEventEmitter, new NativeEventEmitter(NativeModules.InCallManager), "f");
|
|
43
|
+
}
|
|
44
|
+
static init() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const availableVideoDevices = yield LocalMediaUtils.enumerateVideoDevices();
|
|
47
|
+
const availableAudioDevices = yield LocalMediaUtils.enumerateAudioDevices();
|
|
48
|
+
return new LocalMediaUtils(availableAudioDevices.concat(availableVideoDevices));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
destruct() {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
__classPrivateFieldGet(this, _LocalMediaUtils_nativeEventEmitter, "f").removeAllListeners('onAudioDeviceChanged');
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
static isDeviceListAvailable() {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
static enumerateVideoDevices() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
try {
|
|
62
|
+
const deviceMem = {};
|
|
63
|
+
const videoDevices = (yield mediaDevices.enumerateDevices());
|
|
64
|
+
return videoDevices.filter((d) => {
|
|
65
|
+
if (d.kind === 'videoinput' && !deviceMem[d.facing]) {
|
|
66
|
+
deviceMem[d.facing] = true;
|
|
67
|
+
return d;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
static enumerateAudioDevices() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
let audioDevices = {
|
|
80
|
+
earpiece: {
|
|
81
|
+
connected: true,
|
|
82
|
+
haveMic: true,
|
|
83
|
+
},
|
|
84
|
+
speaker: {
|
|
85
|
+
connected: true,
|
|
86
|
+
haveMic: true,
|
|
87
|
+
},
|
|
88
|
+
bluetooth: {
|
|
89
|
+
connected: false,
|
|
90
|
+
haveMic: false,
|
|
91
|
+
},
|
|
92
|
+
wired: {
|
|
93
|
+
connected: false,
|
|
94
|
+
haveMic: false,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
const isWiredHeadphonesConnected = yield NativeAudioManager.getIsWiredHeadsetPluggedIn();
|
|
98
|
+
audioDevices.wired = isWiredHeadphonesConnected
|
|
99
|
+
? {
|
|
100
|
+
connected: true,
|
|
101
|
+
haveMic: true,
|
|
102
|
+
}
|
|
103
|
+
: {
|
|
104
|
+
connected: false,
|
|
105
|
+
haveMic: false,
|
|
106
|
+
};
|
|
107
|
+
const isBluetoothHeadsetConnected = yield NativeAudioManager.isBluetoothHeadsetConnected();
|
|
108
|
+
audioDevices.bluetooth = isBluetoothHeadsetConnected
|
|
109
|
+
? {
|
|
110
|
+
connected: true,
|
|
111
|
+
haveMic: true,
|
|
112
|
+
}
|
|
113
|
+
: {
|
|
114
|
+
connected: false,
|
|
115
|
+
haveMic: false,
|
|
116
|
+
};
|
|
117
|
+
const resp = Object.keys(audioDevices)
|
|
118
|
+
.map((audioDevice) => {
|
|
119
|
+
const audioDeviceProps = audioDevices[audioDevice];
|
|
120
|
+
return Object.assign(Object.assign({}, audioDeviceProps), { deviceId: audioDevice, label: audioDevice, kind: 'audioinput' });
|
|
121
|
+
})
|
|
122
|
+
.filter((audioDevice) => audioDevice.connected);
|
|
123
|
+
// console.log('Resp: ', JSON.stringify(resp, null, 2));
|
|
124
|
+
return resp;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
static getVideoConstraints(options) {
|
|
128
|
+
const constraints = {};
|
|
129
|
+
const { videoDeviceId, videoTrackConstraints, facingMode = 'user', frameRate = { ideal: 24, max: 30 }, } = options;
|
|
130
|
+
constraints.video = videoTrackConstraints || VIDEO_CONSTRAINTS.vga;
|
|
131
|
+
if (typeof constraints.video === 'boolean') {
|
|
132
|
+
return constraints;
|
|
133
|
+
}
|
|
134
|
+
constraints.video.deviceId = videoDeviceId;
|
|
135
|
+
constraints.video.facingMode = facingMode;
|
|
136
|
+
constraints.video.frameRate = frameRate;
|
|
137
|
+
return constraints;
|
|
138
|
+
}
|
|
139
|
+
static getUserMediaWithTimeout() {
|
|
140
|
+
return __awaiter(this, arguments, void 0, function* (constraints = {}, timeout = 0) {
|
|
141
|
+
try {
|
|
142
|
+
if (!timeout) {
|
|
143
|
+
return yield mediaDevices.getUserMedia(constraints);
|
|
144
|
+
}
|
|
145
|
+
// NOTE(roerohan): The await is required to catch errors (if any).
|
|
146
|
+
return yield Promise.race([
|
|
147
|
+
mediaDevices.getUserMedia(constraints),
|
|
148
|
+
new Promise((_resolve, reject) => {
|
|
149
|
+
setTimeout(() => reject(new LocalMediaError('Get user media timed out', 'ERR_GUM_TIMEOUT')), timeout);
|
|
150
|
+
}),
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
throw err;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
static getAudioTrack() {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
const mediaStream = (yield LocalMediaUtils.getUserMediaWithTimeout({
|
|
161
|
+
audio: true,
|
|
162
|
+
}));
|
|
163
|
+
return mediaStream.getAudioTracks()[0];
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
static getVideoTrack(constraints) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const mediaStream = (yield LocalMediaUtils.getUserMediaWithTimeout(constraints));
|
|
169
|
+
return mediaStream.getVideoTracks()[0];
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
static getScreenShareTracks() {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
/**
|
|
175
|
+
* getDisplayMedia is not defined on type MediaDevices.
|
|
176
|
+
* Need to update this when a fix
|
|
177
|
+
* is made: https://github.com/microsoft/TypeScript/issues/33232
|
|
178
|
+
*/
|
|
179
|
+
const stream = (yield mediaDevices.getDisplayMedia());
|
|
180
|
+
// console.log('Screenshare stream: ', stream.getVideoTracks());
|
|
181
|
+
return {
|
|
182
|
+
video: stream.getVideoTracks()[0],
|
|
183
|
+
audio: stream.getAudioTracks()[0],
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
static getAudioAndVideoTrack(constraints) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
const mediaStream = (yield LocalMediaUtils.getUserMediaWithTimeout(constraints));
|
|
190
|
+
return {
|
|
191
|
+
audioTrack: mediaStream.getAudioTracks()[0],
|
|
192
|
+
videoTrack: mediaStream.getVideoTracks()[0],
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
onDeviceChange(callback) {
|
|
197
|
+
const onChange = (deviceData) => __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
const checkDeviceId = (_id) => {
|
|
199
|
+
if (_id.toLowerCase().includes('speaker'))
|
|
200
|
+
return 'speaker';
|
|
201
|
+
else
|
|
202
|
+
return _id;
|
|
203
|
+
};
|
|
204
|
+
const previouslyAvailableDevices = __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f").filter((device) => device.kind === 'audioinput' || device.kind === 'audiooutput');
|
|
205
|
+
const previouslyAvailableDeviceIds = previouslyAvailableDevices.map((device) => checkDeviceId(device.deviceId));
|
|
206
|
+
const len = deviceData.availableAudioDeviceList.length;
|
|
207
|
+
if (len === 0) {
|
|
208
|
+
const currentlyAvailableDevices = yield LocalMediaUtils.enumerateAudioDevices();
|
|
209
|
+
const currentlyAvailableDeviceIds = currentlyAvailableDevices.map((device) => checkDeviceId(device.deviceId));
|
|
210
|
+
const changedDevices = {
|
|
211
|
+
added: currentlyAvailableDevices.filter((device) => !previouslyAvailableDeviceIds.includes(checkDeviceId(device.deviceId))),
|
|
212
|
+
removed: previouslyAvailableDevices.filter((device) => !currentlyAvailableDeviceIds.includes(device.deviceId)),
|
|
213
|
+
};
|
|
214
|
+
this.repopulateAvailableDevices().then(() => {
|
|
215
|
+
callback(changedDevices, false);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
const currentlyAvailableDevices = yield LocalMediaUtils.enumerateAudioDevices();
|
|
220
|
+
const currentlyAvailableDeviceIds = currentlyAvailableDevices.map((device) => checkDeviceId(device.deviceId));
|
|
221
|
+
const availableAudioDevices = yield LocalMediaUtils.enumerateAudioDevices();
|
|
222
|
+
const changedDevices = {
|
|
223
|
+
added: availableAudioDevices.filter((device) => !previouslyAvailableDeviceIds.includes(checkDeviceId(device.deviceId))),
|
|
224
|
+
removed: previouslyAvailableDevices.filter((device) => !currentlyAvailableDeviceIds.includes(device.deviceId)),
|
|
225
|
+
};
|
|
226
|
+
this.repopulateAvailableDevices().then(() => {
|
|
227
|
+
callback(changedDevices, false);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
if (__classPrivateFieldGet(this, _LocalMediaUtils_nativeEventEmitter, "f").listenerCount('onAudioDeviceChanged') === 0) {
|
|
232
|
+
__classPrivateFieldGet(this, _LocalMediaUtils_nativeEventEmitter, "f").addListener('onAudioDeviceChanged', onChange);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
repopulateAvailableDevices() {
|
|
236
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
const videoDevices = yield LocalMediaUtils.enumerateVideoDevices();
|
|
238
|
+
const audioDevices = yield LocalMediaUtils.enumerateAudioDevices();
|
|
239
|
+
__classPrivateFieldSet(this, _LocalMediaUtils_availableDevices, videoDevices.concat(audioDevices), "f");
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
chooseAudioRoute(route) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
return yield NativeAudioManager.chooseAudioRoute(route);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
get availableDevices() {
|
|
248
|
+
return __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f");
|
|
249
|
+
}
|
|
250
|
+
getAvailableDevicesByKind(kind) {
|
|
251
|
+
return __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f").filter((device) => device.kind === kind);
|
|
252
|
+
}
|
|
253
|
+
getDeviceById(deviceId, kind) {
|
|
254
|
+
return __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f").find((device) => device.deviceId === deviceId && device.kind === kind);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Returns all audio input devices (microphone devices).
|
|
258
|
+
*/
|
|
259
|
+
getAudioDevices() {
|
|
260
|
+
return this.getAvailableDevicesByKind('audioinput');
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Returns all video input devices.
|
|
264
|
+
*/
|
|
265
|
+
getVideoDevices() {
|
|
266
|
+
return this.getAvailableDevicesByKind('videoinput');
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Returns all audio output devices (speaker devices).
|
|
270
|
+
*/
|
|
271
|
+
getSpeakerDevices() {
|
|
272
|
+
return this.getAvailableDevicesByKind('audiooutput');
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
_LocalMediaUtils_availableDevices = new WeakMap(), _LocalMediaUtils_nativeEventEmitter = new WeakMap();
|
|
276
|
+
export default LocalMediaUtils;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare class InCallManager {
|
|
2
|
+
constructor();
|
|
3
|
+
start(setup: any): void;
|
|
4
|
+
stop(setup: any): void;
|
|
5
|
+
getIsWiredHeadsetPluggedIn(): Promise<any>;
|
|
6
|
+
isBluetoothHeadsetConnected(): Promise<any>;
|
|
7
|
+
setKeepScreenOn(enable: any): void;
|
|
8
|
+
setSpeakerphoneOn(enable: any): void;
|
|
9
|
+
setForceSpeakerphoneOn(_flag: any): void;
|
|
10
|
+
setMicrophoneMute(enable: any): void;
|
|
11
|
+
chooseAudioRoute(route: String): Promise<any>;
|
|
12
|
+
requestAudioFocus(): Promise<any>;
|
|
13
|
+
abandonAudioFocus(): Promise<any>;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: InCallManager;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
// @ts-nocheck
|
|
11
|
+
import { Platform, NativeModules } from 'react-native';
|
|
12
|
+
const _InCallManager = NativeModules.InCallManager;
|
|
13
|
+
class InCallManager {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.vibrate = false;
|
|
16
|
+
}
|
|
17
|
+
start(setup) {
|
|
18
|
+
setup = setup === undefined ? {} : setup;
|
|
19
|
+
const auto = setup.auto !== false;
|
|
20
|
+
const media = setup.media === 'video' ? 'video' : 'audio';
|
|
21
|
+
const ringback = setup.ringback
|
|
22
|
+
? typeof setup.ringback === 'string'
|
|
23
|
+
? setup.ringback
|
|
24
|
+
: ''
|
|
25
|
+
: '';
|
|
26
|
+
_InCallManager.start(media, auto, ringback);
|
|
27
|
+
}
|
|
28
|
+
stop(setup) {
|
|
29
|
+
setup = setup === undefined ? {} : setup;
|
|
30
|
+
const busytone = setup.busytone
|
|
31
|
+
? typeof setup.busytone === 'string'
|
|
32
|
+
? setup.busytone
|
|
33
|
+
: ''
|
|
34
|
+
: '';
|
|
35
|
+
_InCallManager.stop(busytone);
|
|
36
|
+
}
|
|
37
|
+
getIsWiredHeadsetPluggedIn() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
try {
|
|
40
|
+
return yield _InCallManager.getIsWiredHeadsetPluggedIn();
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
return {};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
isBluetoothHeadsetConnected() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
try {
|
|
50
|
+
return yield _InCallManager.isBluetoothHeadsetConnected();
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
setKeepScreenOn(enable) {
|
|
58
|
+
enable = enable === true;
|
|
59
|
+
_InCallManager.setKeepScreenOn(enable);
|
|
60
|
+
}
|
|
61
|
+
setSpeakerphoneOn(enable) {
|
|
62
|
+
enable = enable === true;
|
|
63
|
+
_InCallManager.setSpeakerphoneOn(enable);
|
|
64
|
+
}
|
|
65
|
+
setForceSpeakerphoneOn(_flag) {
|
|
66
|
+
const flag = typeof _flag === 'boolean' ? (_flag ? 1 : -1) : 0;
|
|
67
|
+
_InCallManager.setForceSpeakerphoneOn(flag);
|
|
68
|
+
}
|
|
69
|
+
setMicrophoneMute(enable) {
|
|
70
|
+
enable = enable === true;
|
|
71
|
+
_InCallManager.setMicrophoneMute(enable);
|
|
72
|
+
}
|
|
73
|
+
chooseAudioRoute(route) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
return yield _InCallManager.chooseAudioRoute(route);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
requestAudioFocus() {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
if (Platform.OS === 'android') {
|
|
81
|
+
return yield _InCallManager.requestAudioFocusJS();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
abandonAudioFocus() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
if (Platform.OS === 'android') {
|
|
88
|
+
return yield _InCallManager.abandonAudioFocusJS();
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export default new InCallManager();
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MediaPermission } from './LocalMediaInterfaces';
|
|
2
|
+
declare const ANDROID: Readonly<{
|
|
3
|
+
readonly CAMERA: "android.permission.CAMERA";
|
|
4
|
+
readonly BLUETOOTH: "android.permission.BLUETOOTH_CONNECT";
|
|
5
|
+
readonly RECORD_AUDIO: "android.permission.RECORD_AUDIO";
|
|
6
|
+
readonly LOCATION: "android.permission.ACCESS_FINE_LOCATION";
|
|
7
|
+
}>;
|
|
8
|
+
type AndroidPermissionMap = typeof ANDROID;
|
|
9
|
+
declare const IOS: Readonly<{
|
|
10
|
+
readonly APP_TRACKING_TRANSPARENCY: "ios.permission.APP_TRACKING_TRANSPARENCY";
|
|
11
|
+
readonly BLUETOOTH_PERIPHERAL: "ios.permission.BLUETOOTH_PERIPHERAL";
|
|
12
|
+
readonly CAMERA: "ios.permission.CAMERA";
|
|
13
|
+
readonly MICROPHONE: "ios.permission.MICROPHONE";
|
|
14
|
+
}>;
|
|
15
|
+
type IOSPermissionMap = typeof IOS;
|
|
16
|
+
export declare const PERMISSIONS: Readonly<{
|
|
17
|
+
readonly ANDROID: AndroidPermissionMap;
|
|
18
|
+
readonly IOS: IOSPermissionMap;
|
|
19
|
+
}>;
|
|
20
|
+
export declare const RESULTS: Readonly<{
|
|
21
|
+
readonly UNAVAILABLE: "unavailable";
|
|
22
|
+
readonly BLOCKED: "blocked";
|
|
23
|
+
readonly DENIED: "denied";
|
|
24
|
+
readonly GRANTED: "granted";
|
|
25
|
+
readonly LIMITED: "limited";
|
|
26
|
+
readonly PROMPTED: "prompted";
|
|
27
|
+
}>;
|
|
28
|
+
export declare function uniq(array: any): any;
|
|
29
|
+
export type DynamicPermissions = Array<'camera' | 'microphone'>;
|
|
30
|
+
export declare const setupPermissions: (audio: boolean, video: boolean) => Promise<{
|
|
31
|
+
[key: string]: MediaPermission;
|
|
32
|
+
}>;
|
|
33
|
+
export type ResultMap = typeof RESULTS;
|
|
34
|
+
export {};
|