@cloudflare/realtimekit-react-native 0.1.4-staging.1 → 0.1.4-staging.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/lib/commonjs/AudioSampleHandler.js +61 -0
  2. package/lib/commonjs/AudioSampleHandler.js.map +1 -0
  3. package/lib/commonjs/BackgroundHandler.js +109 -0
  4. package/lib/commonjs/BackgroundHandler.js.map +1 -0
  5. package/lib/commonjs/DeviceInfo.js +37 -0
  6. package/lib/commonjs/DeviceInfo.js.map +1 -0
  7. package/lib/commonjs/LocalMediaError.js +18 -0
  8. package/lib/commonjs/LocalMediaError.js.map +1 -0
  9. package/lib/commonjs/LocalMediaHandler.js +791 -0
  10. package/lib/commonjs/LocalMediaHandler.js.map +1 -0
  11. package/lib/commonjs/LocalMediaInterfaces.js +2 -0
  12. package/lib/commonjs/LocalMediaInterfaces.js.map +1 -0
  13. package/lib/commonjs/LocalMediaUtils.js +298 -0
  14. package/lib/commonjs/LocalMediaUtils.js.map +1 -0
  15. package/lib/commonjs/NativeAudioManager.js +72 -0
  16. package/lib/commonjs/NativeAudioManager.js.map +1 -0
  17. package/lib/commonjs/PermissionHandler.js +157 -0
  18. package/lib/commonjs/PermissionHandler.js.map +1 -0
  19. package/lib/commonjs/ReactContext.js +116 -0
  20. package/lib/commonjs/ReactContext.js.map +1 -0
  21. package/lib/commonjs/ReactHooks.js +99 -0
  22. package/lib/commonjs/ReactHooks.js.map +1 -0
  23. package/lib/commonjs/index.js +95 -0
  24. package/lib/commonjs/index.js.map +1 -0
  25. package/lib/commonjs/utils/constants.js +7 -0
  26. package/lib/commonjs/utils/constants.js.map +1 -0
  27. package/lib/commonjs/utils/crypto.js +76 -0
  28. package/lib/commonjs/utils/crypto.js.map +1 -0
  29. package/lib/commonjs/utils/version.js +8 -0
  30. package/lib/commonjs/utils/version.js.map +1 -0
  31. package/lib/module/AudioSampleHandler.js +54 -0
  32. package/lib/module/AudioSampleHandler.js.map +1 -0
  33. package/lib/module/BackgroundHandler.js +103 -0
  34. package/lib/module/BackgroundHandler.js.map +1 -0
  35. package/lib/module/DeviceInfo.js +31 -0
  36. package/lib/module/DeviceInfo.js.map +1 -0
  37. package/lib/module/LocalMediaError.js +11 -0
  38. package/lib/module/LocalMediaError.js.map +1 -0
  39. package/lib/module/LocalMediaHandler.js +784 -0
  40. package/lib/module/LocalMediaHandler.js.map +1 -0
  41. package/lib/module/LocalMediaInterfaces.js +2 -0
  42. package/lib/module/LocalMediaInterfaces.js.map +1 -0
  43. package/lib/module/LocalMediaUtils.js +290 -0
  44. package/lib/module/LocalMediaUtils.js.map +1 -0
  45. package/lib/module/NativeAudioManager.js +65 -0
  46. package/lib/module/NativeAudioManager.js.map +1 -0
  47. package/lib/module/PermissionHandler.js +149 -0
  48. package/lib/module/PermissionHandler.js.map +1 -0
  49. package/lib/module/ReactContext.js +107 -0
  50. package/lib/module/ReactContext.js.map +1 -0
  51. package/lib/module/ReactHooks.js +75 -0
  52. package/lib/module/ReactHooks.js.map +1 -0
  53. package/lib/{src → module}/index.js +32 -32
  54. package/lib/module/index.js.map +1 -0
  55. package/lib/module/utils/constants.js +5 -0
  56. package/lib/module/utils/constants.js.map +1 -0
  57. package/lib/module/utils/crypto.js +74 -0
  58. package/lib/module/utils/crypto.js.map +1 -0
  59. package/lib/module/utils/version.js +2 -0
  60. package/lib/module/utils/version.js.map +1 -0
  61. package/lib/{src → typescript}/LocalMediaHandler.d.ts +0 -4
  62. package/lib/{src → typescript}/ReactHooks.d.ts +2 -2
  63. package/lib/typescript/utils/constants.d.ts +1 -0
  64. package/lib/typescript/utils/version.d.ts +1 -0
  65. package/package.json +5 -4
  66. package/plugin/build/withRTK.js +43 -17
  67. package/plugin/src/withRTK.ts +55 -25
  68. package/android/src/main/res/values/strings.xml +0 -3
  69. package/lib/package.json +0 -168
  70. package/lib/src/AudioSampleHandler.js +0 -57
  71. package/lib/src/BackgroundHandler.js +0 -100
  72. package/lib/src/DeviceInfo.js +0 -27
  73. package/lib/src/LocalMediaError.js +0 -6
  74. package/lib/src/LocalMediaHandler.js +0 -860
  75. package/lib/src/LocalMediaInterfaces.js +0 -1
  76. package/lib/src/LocalMediaUtils.js +0 -288
  77. package/lib/src/NativeAudioManager.js +0 -93
  78. package/lib/src/PermissionHandler.js +0 -179
  79. package/lib/src/ReactContext.js +0 -90
  80. package/lib/src/ReactHooks.js +0 -80
  81. package/lib/src/utils/crypto.js +0 -82
  82. /package/lib/{src → typescript}/AudioSampleHandler.d.ts +0 -0
  83. /package/lib/{src → typescript}/BackgroundHandler.d.ts +0 -0
  84. /package/lib/{src → typescript}/DeviceInfo.d.ts +0 -0
  85. /package/lib/{src → typescript}/LocalMediaError.d.ts +0 -0
  86. /package/lib/{src → typescript}/LocalMediaInterfaces.d.ts +0 -0
  87. /package/lib/{src → typescript}/LocalMediaUtils.d.ts +0 -0
  88. /package/lib/{src → typescript}/NativeAudioManager.d.ts +0 -0
  89. /package/lib/{src → typescript}/PermissionHandler.d.ts +0 -0
  90. /package/lib/{src → typescript}/ReactContext.d.ts +0 -0
  91. /package/lib/{src → typescript}/index.d.ts +0 -0
  92. /package/lib/{src → typescript}/utils/crypto.d.ts +0 -0
@@ -1 +0,0 @@
1
- export {};
@@ -1,288 +0,0 @@
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 '@cloudflare/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
- return resp;
124
- });
125
- }
126
- static getVideoConstraints(options) {
127
- const constraints = {};
128
- const { videoDeviceId, videoTrackConstraints, facingMode = 'user', frameRate = { ideal: 24, max: 30 }, } = options;
129
- constraints.video = videoTrackConstraints || VIDEO_CONSTRAINTS.vga;
130
- if (typeof constraints.video === 'boolean') {
131
- return constraints;
132
- }
133
- constraints.video.deviceId = videoDeviceId;
134
- constraints.video.facingMode = facingMode;
135
- constraints.video.frameRate = frameRate;
136
- return constraints;
137
- }
138
- static getUserMediaWithTimeout() {
139
- return __awaiter(this, arguments, void 0, function* (constraints = {}, timeout = 0) {
140
- try {
141
- if (!timeout) {
142
- return yield mediaDevices.getUserMedia(constraints);
143
- }
144
- // NOTE(roerohan): The await is required to catch errors (if any).
145
- return Promise.race([
146
- mediaDevices.getUserMedia(constraints),
147
- new Promise((_resolve, reject) => {
148
- setTimeout(() => reject(new LocalMediaError('Get user media timed out', 'ERR_GUM_TIMEOUT')), timeout);
149
- }),
150
- ]);
151
- }
152
- catch (err) {
153
- throw err;
154
- }
155
- });
156
- }
157
- static getAudioTrack() {
158
- return __awaiter(this, void 0, void 0, function* () {
159
- const mediaStream = (yield LocalMediaUtils.getUserMediaWithTimeout({
160
- audio: true,
161
- timeout: 5000,
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(Object.assign(Object.assign({}, constraints), { timeout: 5000 })));
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
- return {
181
- video: stream.getVideoTracks()[0],
182
- audio: stream.getAudioTracks()[0],
183
- };
184
- });
185
- }
186
- static getAudioAndVideoTrack(constraints) {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- try {
189
- const mediaStream = (yield LocalMediaUtils.getUserMediaWithTimeout(Object.assign(Object.assign({}, constraints), { timeout: 5000 })));
190
- return {
191
- audioTrack: mediaStream.getAudioTracks()[0],
192
- videoTrack: mediaStream.getVideoTracks()[0],
193
- };
194
- }
195
- catch (err) {
196
- throw err;
197
- }
198
- });
199
- }
200
- onDeviceChange(callback) {
201
- const onChange = (deviceData) => __awaiter(this, void 0, void 0, function* () {
202
- const checkDeviceId = (_id) => {
203
- if (_id.toLowerCase().includes('speaker'))
204
- return 'speaker';
205
- else
206
- return _id;
207
- };
208
- const previouslyAvailableDevices = __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f").filter((device) => device.kind === 'audioinput' || device.kind === 'audiooutput');
209
- const previouslyAvailableDeviceIds = previouslyAvailableDevices.map((device) => checkDeviceId(device.deviceId));
210
- const len = deviceData.availableAudioDeviceList.length;
211
- if (len === 0) {
212
- const currentlyAvailableDevices = yield LocalMediaUtils.enumerateAudioDevices();
213
- const currentlyAvailableDeviceIds = currentlyAvailableDevices.map((device) => checkDeviceId(device.deviceId));
214
- const changedDevices = {
215
- added: currentlyAvailableDevices.filter((device) => !previouslyAvailableDeviceIds.includes(checkDeviceId(device.deviceId))),
216
- removed: previouslyAvailableDevices.filter((device) => !currentlyAvailableDeviceIds.includes(device.deviceId)),
217
- };
218
- this.repopulateAvailableDevices().then(() => {
219
- if (changedDevices.added.length || changedDevices.removed.length) {
220
- callback(changedDevices, false);
221
- }
222
- });
223
- }
224
- else {
225
- const currentlyAvailableDevices = yield LocalMediaUtils.enumerateAudioDevices();
226
- const currentlyAvailableDeviceIds = currentlyAvailableDevices.map((device) => checkDeviceId(device.deviceId));
227
- const availableAudioDevices = yield LocalMediaUtils.enumerateAudioDevices();
228
- const changedDevices = {
229
- added: availableAudioDevices.filter((device) => !previouslyAvailableDeviceIds.includes(checkDeviceId(device.deviceId))),
230
- removed: previouslyAvailableDevices.filter((device) => !currentlyAvailableDeviceIds.includes(device.deviceId)),
231
- };
232
- this.repopulateAvailableDevices().then(() => {
233
- if (changedDevices.added.length || changedDevices.removed.length) {
234
- callback(changedDevices, false);
235
- }
236
- });
237
- }
238
- });
239
- if (__classPrivateFieldGet(this, _LocalMediaUtils_nativeEventEmitter, "f").listenerCount('onAudioDeviceChanged') === 0) {
240
- __classPrivateFieldGet(this, _LocalMediaUtils_nativeEventEmitter, "f").addListener('onAudioDeviceChanged', onChange);
241
- }
242
- }
243
- repopulateAvailableDevices() {
244
- return __awaiter(this, void 0, void 0, function* () {
245
- const videoDevices = yield LocalMediaUtils.enumerateVideoDevices();
246
- const audioDevices = yield LocalMediaUtils.enumerateAudioDevices();
247
- __classPrivateFieldSet(this, _LocalMediaUtils_availableDevices, videoDevices.concat(audioDevices), "f");
248
- });
249
- }
250
- chooseAudioRoute(route) {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- return yield NativeAudioManager.chooseAudioRoute(route);
253
- });
254
- }
255
- get availableDevices() {
256
- return __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f");
257
- }
258
- getAvailableDevicesByKind(kind) {
259
- return __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f").filter((device) => device.kind === kind);
260
- }
261
- getDeviceById(deviceId, kind) {
262
- return __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f").find((device) => device.deviceId === deviceId && device.kind === kind);
263
- }
264
- /**
265
- * Returns all audio input devices (microphone devices).
266
- */
267
- getAudioDevices() {
268
- return this.getAvailableDevicesByKind('audioinput');
269
- }
270
- /**
271
- * Returns all video input devices.
272
- */
273
- getVideoDevices() {
274
- return this.getAvailableDevicesByKind('videoinput');
275
- }
276
- /**
277
- * Returns all audio output devices (speaker devices).
278
- */
279
- getSpeakerDevices() {
280
- const speakerDevices = __classPrivateFieldGet(this, _LocalMediaUtils_availableDevices, "f");
281
- // In Mobile, speaker devices are the same as audio input devices
282
- return speakerDevices
283
- .filter((device) => device.kind === 'audioinput')
284
- .map((device) => (Object.assign(Object.assign({}, device), { deviceId: device.deviceId, label: device.label, kind: 'audiooutput' })));
285
- }
286
- }
287
- _LocalMediaUtils_availableDevices = new WeakMap(), _LocalMediaUtils_nativeEventEmitter = new WeakMap();
288
- export default LocalMediaUtils;
@@ -1,93 +0,0 @@
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();
@@ -1,179 +0,0 @@
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
- import { Platform, NativeModules } from 'react-native';
11
- const ANDROID = Object.freeze({
12
- CAMERA: 'android.permission.CAMERA',
13
- BLUETOOTH: 'android.permission.BLUETOOTH_CONNECT',
14
- RECORD_AUDIO: 'android.permission.RECORD_AUDIO',
15
- LOCATION: 'android.permission.ACCESS_FINE_LOCATION',
16
- });
17
- const IOS = Object.freeze({
18
- APP_TRACKING_TRANSPARENCY: 'ios.permission.APP_TRACKING_TRANSPARENCY',
19
- BLUETOOTH_PERIPHERAL: 'ios.permission.BLUETOOTH_PERIPHERAL',
20
- CAMERA: 'ios.permission.CAMERA',
21
- MICROPHONE: 'ios.permission.MICROPHONE',
22
- });
23
- export const PERMISSIONS = Object.freeze({
24
- ANDROID: ANDROID,
25
- IOS: IOS,
26
- });
27
- export const RESULTS = Object.freeze({
28
- UNAVAILABLE: 'unavailable',
29
- BLOCKED: 'blocked',
30
- DENIED: 'denied',
31
- GRANTED: 'granted',
32
- LIMITED: 'limited',
33
- PROMPTED: 'prompted',
34
- });
35
- const { RTKRNPermissions } = NativeModules;
36
- function request(permission) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- return RTKRNPermissions.available.includes(permission)
39
- ? yield RTKRNPermissions.request(permission)
40
- : RESULTS.UNAVAILABLE;
41
- });
42
- }
43
- function check(permission) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return RTKRNPermissions.available.includes(permission)
46
- ? yield RTKRNPermissions.check(permission)
47
- : RESULTS.UNAVAILABLE;
48
- });
49
- }
50
- export function uniq(array) {
51
- return array.filter((item, index) => item != null && array.indexOf(item) === index);
52
- }
53
- function requestMultiplePermissions(permissions) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- if (Platform.OS === 'ios') {
56
- const output = {};
57
- const dedup = uniq(permissions);
58
- for (let index = 0; index < dedup.length; index += 1) {
59
- const permission = dedup[index];
60
- output[permission] = yield request(permission);
61
- }
62
- return output;
63
- }
64
- const output = yield RTKRNPermissions.requestMultiplePermissions(permissions, true);
65
- return output;
66
- });
67
- }
68
- function checkMultiplePermissions(permissions) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- if (Platform.OS === 'ios') {
71
- const output = {};
72
- const dedup = uniq(permissions);
73
- for (let index = 0; index < dedup.length; index += 1) {
74
- const permission = dedup[index];
75
- output[permission] = yield check(permission);
76
- }
77
- return output;
78
- }
79
- const output = yield RTKRNPermissions.checkMultiplePermissions(permissions);
80
- return output;
81
- });
82
- }
83
- const getPlatformEquiPermission = (permission, reverse = false) => {
84
- const android = {
85
- camera: PERMISSIONS.ANDROID.CAMERA,
86
- microphone: PERMISSIONS.ANDROID.RECORD_AUDIO,
87
- bluetooth: PERMISSIONS.ANDROID.BLUETOOTH,
88
- location: PERMISSIONS.ANDROID.LOCATION,
89
- };
90
- const ios = {
91
- camera: PERMISSIONS.IOS.CAMERA,
92
- microphone: PERMISSIONS.IOS.MICROPHONE,
93
- bluetooth: PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL,
94
- };
95
- if (!reverse) {
96
- if (Platform.OS === 'android') {
97
- return android[permission];
98
- }
99
- return ios[permission];
100
- }
101
- if (Platform.OS === 'android') {
102
- const androidReverse = {};
103
- Object.keys(android).forEach((key) => {
104
- androidReverse[android[key]] = key;
105
- });
106
- return androidReverse[permission];
107
- }
108
- const iosReverse = {};
109
- Object.keys(ios).forEach((key) => {
110
- iosReverse[ios[key]] = key;
111
- });
112
- return iosReverse[permission];
113
- };
114
- let timeout;
115
- const processPermissionResult = (systemPermissionRequired, audio, video) => (status) => __awaiter(void 0, void 0, void 0, function* () {
116
- const permissionState = {
117
- camera: 'NOT_REQUESTED',
118
- microphone: 'NOT_REQUESTED',
119
- bluetooth: 'NOT_REQUESTED',
120
- location: 'NOT_REQUESTED',
121
- };
122
- systemPermissionRequired.forEach((permission) => {
123
- const normalPermission = getPlatformEquiPermission(permission, true);
124
- if (status[permission] === RESULTS.GRANTED) {
125
- permissionState[normalPermission] = 'ACCEPTED';
126
- }
127
- else if (status[permission] !== RESULTS.PROMPTED) {
128
- permissionState[normalPermission] = 'DENIED';
129
- }
130
- });
131
- const isBluetoothGranted = Platform.OS === 'ios' || permissionState.bluetooth !== 'NOT_REQUESTED';
132
- if ((permissionState.camera !== 'NOT_REQUESTED' || !video) &&
133
- (permissionState.microphone !== 'NOT_REQUESTED' || !audio) &&
134
- isBluetoothGranted &&
135
- timeout)
136
- clearInterval(timeout);
137
- else {
138
- yield requestMultiplePermissions(systemPermissionRequired);
139
- const checkResponse = yield checkMultiplePermissions(systemPermissionRequired);
140
- yield processPermissionResult(systemPermissionRequired, audio, video)(checkResponse);
141
- }
142
- return permissionState;
143
- });
144
- export const setupPermissions = (audio, video) => __awaiter(void 0, void 0, void 0, function* () {
145
- return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
146
- let statusCheck;
147
- const systemPermissionRequired = [];
148
- const isIOS = Platform.OS === 'ios';
149
- const permissionsRequired = []
150
- .concat(audio ? ['microphone'] : [])
151
- .concat(isIOS ? [] : ['bluetooth'])
152
- .concat(video ? ['camera'] : []);
153
- permissionsRequired.forEach((permission) => {
154
- const systemPermissionEquivalent = getPlatformEquiPermission(permission);
155
- if (systemPermissionEquivalent) {
156
- systemPermissionRequired.push(systemPermissionEquivalent);
157
- }
158
- });
159
- const checkPermLoop = (id) => __awaiter(void 0, void 0, void 0, function* () {
160
- timeout = id;
161
- statusCheck = yield processPermissionResult(systemPermissionRequired, audio, video)(requestResponse);
162
- if (statusCheck !== undefined)
163
- resolve(statusCheck);
164
- });
165
- // Requesting permission status
166
- const requestResponse = yield requestMultiplePermissions(systemPermissionRequired);
167
- const timeout_sample = setInterval(() => checkPermLoop(timeout_sample), 1000);
168
- if (timeout)
169
- statusCheck = yield processPermissionResult(systemPermissionRequired, audio, video)(requestResponse);
170
- if (timeout) {
171
- clearInterval(timeout);
172
- }
173
- if (statusCheck)
174
- resolve(statusCheck);
175
- setTimeout(() => {
176
- reject(statusCheck);
177
- }, 20000);
178
- }));
179
- });
@@ -1,90 +0,0 @@
1
- // @ts-nocheck
2
- import React, { createContext, useContext, useEffect, useRef, useState, } from 'react';
3
- class RealtimeKitUpdates {
4
- constructor(meeting) {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
6
- this.meeting = meeting;
7
- this.l = new Set();
8
- (_a = this.meeting.self) === null || _a === void 0 ? void 0 : _a.addListener('*', this.update.bind(this));
9
- (_b = this.meeting.meta) === null || _b === void 0 ? void 0 : _b.addListener('*', this.update.bind(this));
10
- (_c = this.meeting.participants) === null || _c === void 0 ? void 0 : _c.addListener('*', this.update.bind(this));
11
- (_e = (_d = this.meeting.participants) === null || _d === void 0 ? void 0 : _d.joined) === null || _e === void 0 ? void 0 : _e.addListener('*', this.update.bind(this));
12
- (_g = (_f = this.meeting.participants) === null || _f === void 0 ? void 0 : _f.active) === null || _g === void 0 ? void 0 : _g.addListener('*', this.update.bind(this));
13
- (_j = (_h = this.meeting.participants) === null || _h === void 0 ? void 0 : _h.pinned) === null || _j === void 0 ? void 0 : _j.addListener('*', this.update.bind(this));
14
- (_k = this.meeting.chat) === null || _k === void 0 ? void 0 : _k.addListener('*', this.update.bind(this));
15
- (_l = this.meeting.polls) === null || _l === void 0 ? void 0 : _l.addListener('*', this.update.bind(this));
16
- (_o = (_m = this.meeting.plugins) === null || _m === void 0 ? void 0 : _m.all) === null || _o === void 0 ? void 0 : _o.addListener('*', this.update.bind(this));
17
- (_q = (_p = this.meeting.plugins) === null || _p === void 0 ? void 0 : _p.active) === null || _q === void 0 ? void 0 : _q.addListener('*', this.update.bind(this));
18
- (_r = this.meeting.recording) === null || _r === void 0 ? void 0 : _r.addListener('*', this.update.bind(this));
19
- (_s = this.meeting.stage) === null || _s === void 0 ? void 0 : _s.addListener('*', this.update.bind(this));
20
- (_t = this.meeting.livestream) === null || _t === void 0 ? void 0 : _t.addListener('*', this.update.bind(this));
21
- }
22
- clean() {
23
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
24
- (_a = this.meeting.self) === null || _a === void 0 ? void 0 : _a.removeListener('*', this.update.bind(this));
25
- (_b = this.meeting.meta) === null || _b === void 0 ? void 0 : _b.removeListener('*', this.update.bind(this));
26
- (_c = this.meeting.participants) === null || _c === void 0 ? void 0 : _c.removeListener('*', this.update.bind(this));
27
- (_e = (_d = this.meeting.participants) === null || _d === void 0 ? void 0 : _d.joined) === null || _e === void 0 ? void 0 : _e.removeListener('*', this.update.bind(this));
28
- (_g = (_f = this.meeting.participants) === null || _f === void 0 ? void 0 : _f.active) === null || _g === void 0 ? void 0 : _g.removeListener('*', this.update.bind(this));
29
- (_j = (_h = this.meeting.participants) === null || _h === void 0 ? void 0 : _h.pinned) === null || _j === void 0 ? void 0 : _j.removeListener('*', this.update.bind(this));
30
- (_k = this.meeting.chat) === null || _k === void 0 ? void 0 : _k.removeListener('*', this.update.bind(this));
31
- (_l = this.meeting.polls) === null || _l === void 0 ? void 0 : _l.removeListener('*', this.update.bind(this));
32
- (_o = (_m = this.meeting.plugins) === null || _m === void 0 ? void 0 : _m.all) === null || _o === void 0 ? void 0 : _o.removeListener('*', this.update.bind(this));
33
- (_q = (_p = this.meeting.plugins) === null || _p === void 0 ? void 0 : _p.active) === null || _q === void 0 ? void 0 : _q.removeListener('*', this.update.bind(this));
34
- (_r = this.meeting.recording) === null || _r === void 0 ? void 0 : _r.removeListener('*', this.update.bind(this));
35
- (_s = this.meeting.stage) === null || _s === void 0 ? void 0 : _s.removeListener('*', this.update.bind(this));
36
- (_t = this.meeting.livestream) === null || _t === void 0 ? void 0 : _t.removeListener('*', this.update.bind(this));
37
- }
38
- addListener(listener) {
39
- this.l.add(listener);
40
- }
41
- removeListener(listener) {
42
- this.l.delete(listener);
43
- }
44
- update() {
45
- this.l.forEach((l) => {
46
- l();
47
- });
48
- }
49
- }
50
- export const RealtimeKitContext = createContext({
51
- meeting: undefined,
52
- updates: undefined,
53
- });
54
- /**
55
- * Provider component which makes the RealtimeKitClient object
56
- * available to nested components
57
- * @component
58
- * @param value The RealtimeKitClient instance from `useRealtimeKitClient()`
59
- * @param renderBeforeLoad The provider will not render children by default
60
- * until it gets a client object, renderBeforeLoad can be used to override that
61
- */
62
- export function RealtimeKitProvider({ value, children, fallback = null, }) {
63
- const [updates, setUpdates] = useState();
64
- const updatesRef = useRef();
65
- useEffect(() => {
66
- if (value) {
67
- const newUpdate = new RealtimeKitUpdates(value);
68
- setUpdates(newUpdate);
69
- updatesRef.current = newUpdate;
70
- }
71
- return () => {
72
- var _a;
73
- (_a = updatesRef.current) === null || _a === void 0 ? void 0 : _a.clean();
74
- };
75
- }, [value]);
76
- return (React.createElement(RealtimeKitContext.Provider, { value: {
77
- meeting: value,
78
- updates,
79
- } }, value ? children : fallback));
80
- }
81
- /**
82
- * Hook which returns the reference to the RealtimeKitClient object
83
- * @returns meeting instance from `useRealtimeKitClient()`
84
- */
85
- export const useRealtimeKitMeeting = () => {
86
- const { meeting } = useContext(RealtimeKitContext);
87
- if (!meeting)
88
- throw new Error('useRealtimeKitMeeting must be used within the RealtimeKitProvider');
89
- return { meeting };
90
- };