@voltkit-rtc/react-native 0.0.0-stage → 0.1.1
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/CHANGELOG.md +121 -0
- package/LICENSE +21 -0
- package/README.md +1608 -2
- package/android/build.gradle +70 -0
- package/android/consumer-rules.pro +21 -0
- package/android/src/main/AndroidManifest.xml +25 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/AppVisibility.kt +67 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/AudioDevices.kt +67 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/AudioRouter.kt +487 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/CallServiceTypes.kt +120 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/NativeTimers.kt +106 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/NetworkWatch.kt +120 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/OutputChoice.kt +65 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/RtcConfig.kt +83 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/ScoLink.kt +61 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitCallService.kt +287 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitRtcInitProvider.kt +215 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitRtcModule.kt +313 -0
- package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitRtcPackage.kt +30 -0
- package/android/src/main/res/drawable/voltkit_rtc_default_call_icon.xml +15 -0
- package/android/src/main/res/raw/voltkit_rtc_keep.xml +7 -0
- package/app.plugin.js +17 -0
- package/lib/commonjs/audio.js +215 -0
- package/lib/commonjs/audio.js.map +1 -0
- package/lib/commonjs/components.js +207 -0
- package/lib/commonjs/components.js.map +1 -0
- package/lib/commonjs/create-client.js +47 -0
- package/lib/commonjs/create-client.js.map +1 -0
- package/lib/commonjs/errors.js +99 -0
- package/lib/commonjs/errors.js.map +1 -0
- package/lib/commonjs/globals.js +61 -0
- package/lib/commonjs/globals.js.map +1 -0
- package/lib/commonjs/index.js +234 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/local-media.js +392 -0
- package/lib/commonjs/local-media.js.map +1 -0
- package/lib/commonjs/native-session.js +365 -0
- package/lib/commonjs/native-session.js.map +1 -0
- package/lib/commonjs/native.js +99 -0
- package/lib/commonjs/native.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/permissions.js +166 -0
- package/lib/commonjs/permissions.js.map +1 -0
- package/lib/commonjs/platform/android.js +126 -0
- package/lib/commonjs/platform/android.js.map +1 -0
- package/lib/commonjs/platform/common.js +138 -0
- package/lib/commonjs/platform/common.js.map +1 -0
- package/lib/commonjs/platform/devices.js +151 -0
- package/lib/commonjs/platform/devices.js.map +1 -0
- package/lib/commonjs/platform/index.js +35 -0
- package/lib/commonjs/platform/index.js.map +1 -0
- package/lib/commonjs/platform/ios.js +54 -0
- package/lib/commonjs/platform/ios.js.map +1 -0
- package/lib/commonjs/platform/streams.js +273 -0
- package/lib/commonjs/platform/streams.js.map +1 -0
- package/lib/commonjs/platform/timers.js +71 -0
- package/lib/commonjs/platform/timers.js.map +1 -0
- package/lib/commonjs/platform/visibility.js +60 -0
- package/lib/commonjs/platform/visibility.js.map +1 -0
- package/lib/commonjs/preflight.js +77 -0
- package/lib/commonjs/preflight.js.map +1 -0
- package/lib/commonjs/provider.js +75 -0
- package/lib/commonjs/provider.js.map +1 -0
- package/lib/commonjs/specs/NativeVoltkitRtc.js +29 -0
- package/lib/commonjs/specs/NativeVoltkitRtc.js.map +1 -0
- package/lib/module/audio.js +207 -0
- package/lib/module/audio.js.map +1 -0
- package/lib/module/components.js +200 -0
- package/lib/module/components.js.map +1 -0
- package/lib/module/create-client.js +42 -0
- package/lib/module/create-client.js.map +1 -0
- package/lib/module/errors.js +87 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/globals.js +53 -0
- package/lib/module/globals.js.map +1 -0
- package/lib/module/index.js +33 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/local-media.js +387 -0
- package/lib/module/local-media.js.map +1 -0
- package/lib/module/native-session.js +360 -0
- package/lib/module/native-session.js.map +1 -0
- package/lib/module/native.js +87 -0
- package/lib/module/native.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/permissions.js +160 -0
- package/lib/module/permissions.js.map +1 -0
- package/lib/module/platform/android.js +122 -0
- package/lib/module/platform/android.js.map +1 -0
- package/lib/module/platform/common.js +128 -0
- package/lib/module/platform/common.js.map +1 -0
- package/lib/module/platform/devices.js +142 -0
- package/lib/module/platform/devices.js.map +1 -0
- package/lib/module/platform/index.js +24 -0
- package/lib/module/platform/index.js.map +1 -0
- package/lib/module/platform/ios.js +49 -0
- package/lib/module/platform/ios.js.map +1 -0
- package/lib/module/platform/streams.js +268 -0
- package/lib/module/platform/streams.js.map +1 -0
- package/lib/module/platform/timers.js +67 -0
- package/lib/module/platform/timers.js.map +1 -0
- package/lib/module/platform/visibility.js +54 -0
- package/lib/module/platform/visibility.js.map +1 -0
- package/lib/module/preflight.js +72 -0
- package/lib/module/preflight.js.map +1 -0
- package/lib/module/provider.js +70 -0
- package/lib/module/provider.js.map +1 -0
- package/lib/module/specs/NativeVoltkitRtc.js +37 -0
- package/lib/module/specs/NativeVoltkitRtc.js.map +1 -0
- package/lib/typescript/commonjs/audio.d.ts +58 -0
- package/lib/typescript/commonjs/audio.d.ts.map +1 -0
- package/lib/typescript/commonjs/components.d.ts +58 -0
- package/lib/typescript/commonjs/components.d.ts.map +1 -0
- package/lib/typescript/commonjs/create-client.d.ts +35 -0
- package/lib/typescript/commonjs/create-client.d.ts.map +1 -0
- package/lib/typescript/commonjs/errors.d.ts +34 -0
- package/lib/typescript/commonjs/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/globals.d.ts +16 -0
- package/lib/typescript/commonjs/globals.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +24 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/local-media.d.ts +86 -0
- package/lib/typescript/commonjs/local-media.d.ts.map +1 -0
- package/lib/typescript/commonjs/native-session.d.ts +38 -0
- package/lib/typescript/commonjs/native-session.d.ts.map +1 -0
- package/lib/typescript/commonjs/native.d.ts +18 -0
- package/lib/typescript/commonjs/native.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/permissions.d.ts +30 -0
- package/lib/typescript/commonjs/permissions.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/android.d.ts +4 -0
- package/lib/typescript/commonjs/platform/android.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/common.d.ts +101 -0
- package/lib/typescript/commonjs/platform/common.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/devices.d.ts +42 -0
- package/lib/typescript/commonjs/platform/devices.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/index.d.ts +6 -0
- package/lib/typescript/commonjs/platform/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/ios.d.ts +4 -0
- package/lib/typescript/commonjs/platform/ios.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/streams.d.ts +82 -0
- package/lib/typescript/commonjs/platform/streams.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/timers.d.ts +19 -0
- package/lib/typescript/commonjs/platform/timers.d.ts.map +1 -0
- package/lib/typescript/commonjs/platform/visibility.d.ts +11 -0
- package/lib/typescript/commonjs/platform/visibility.d.ts.map +1 -0
- package/lib/typescript/commonjs/preflight.d.ts +19 -0
- package/lib/typescript/commonjs/preflight.d.ts.map +1 -0
- package/lib/typescript/commonjs/provider.d.ts +35 -0
- package/lib/typescript/commonjs/provider.d.ts.map +1 -0
- package/lib/typescript/commonjs/specs/NativeVoltkitRtc.d.ts +157 -0
- package/lib/typescript/commonjs/specs/NativeVoltkitRtc.d.ts.map +1 -0
- package/lib/typescript/module/audio.d.ts +58 -0
- package/lib/typescript/module/audio.d.ts.map +1 -0
- package/lib/typescript/module/components.d.ts +58 -0
- package/lib/typescript/module/components.d.ts.map +1 -0
- package/lib/typescript/module/create-client.d.ts +35 -0
- package/lib/typescript/module/create-client.d.ts.map +1 -0
- package/lib/typescript/module/errors.d.ts +34 -0
- package/lib/typescript/module/errors.d.ts.map +1 -0
- package/lib/typescript/module/globals.d.ts +16 -0
- package/lib/typescript/module/globals.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +24 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/local-media.d.ts +86 -0
- package/lib/typescript/module/local-media.d.ts.map +1 -0
- package/lib/typescript/module/native-session.d.ts +38 -0
- package/lib/typescript/module/native-session.d.ts.map +1 -0
- package/lib/typescript/module/native.d.ts +18 -0
- package/lib/typescript/module/native.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/permissions.d.ts +30 -0
- package/lib/typescript/module/permissions.d.ts.map +1 -0
- package/lib/typescript/module/platform/android.d.ts +4 -0
- package/lib/typescript/module/platform/android.d.ts.map +1 -0
- package/lib/typescript/module/platform/common.d.ts +101 -0
- package/lib/typescript/module/platform/common.d.ts.map +1 -0
- package/lib/typescript/module/platform/devices.d.ts +42 -0
- package/lib/typescript/module/platform/devices.d.ts.map +1 -0
- package/lib/typescript/module/platform/index.d.ts +6 -0
- package/lib/typescript/module/platform/index.d.ts.map +1 -0
- package/lib/typescript/module/platform/ios.d.ts +4 -0
- package/lib/typescript/module/platform/ios.d.ts.map +1 -0
- package/lib/typescript/module/platform/streams.d.ts +82 -0
- package/lib/typescript/module/platform/streams.d.ts.map +1 -0
- package/lib/typescript/module/platform/timers.d.ts +19 -0
- package/lib/typescript/module/platform/timers.d.ts.map +1 -0
- package/lib/typescript/module/platform/visibility.d.ts +11 -0
- package/lib/typescript/module/platform/visibility.d.ts.map +1 -0
- package/lib/typescript/module/preflight.d.ts +19 -0
- package/lib/typescript/module/preflight.d.ts.map +1 -0
- package/lib/typescript/module/provider.d.ts +35 -0
- package/lib/typescript/module/provider.d.ts.map +1 -0
- package/lib/typescript/module/specs/NativeVoltkitRtc.d.ts +157 -0
- package/lib/typescript/module/specs/NativeVoltkitRtc.d.ts.map +1 -0
- package/package.json +140 -4
- package/plugin/build/android.d.ts +36 -0
- package/plugin/build/android.js +265 -0
- package/plugin/build/index.d.ts +9 -0
- package/plugin/build/index.js +54 -0
- package/plugin/build/ios.d.ts +4 -0
- package/plugin/build/ios.js +43 -0
- package/plugin/build/options.d.ts +93 -0
- package/plugin/build/options.js +140 -0
- package/react-native.config.js +11 -0
- package/src/audio.ts +221 -0
- package/src/components.tsx +233 -0
- package/src/create-client.ts +53 -0
- package/src/errors.ts +81 -0
- package/src/globals.ts +54 -0
- package/src/index.ts +95 -0
- package/src/local-media.ts +420 -0
- package/src/native-session.tsx +384 -0
- package/src/native.ts +84 -0
- package/src/permissions.ts +173 -0
- package/src/platform/android.ts +128 -0
- package/src/platform/common.ts +157 -0
- package/src/platform/devices.ts +148 -0
- package/src/platform/index.ts +22 -0
- package/src/platform/ios.ts +48 -0
- package/src/platform/streams.ts +285 -0
- package/src/platform/timers.ts +72 -0
- package/src/platform/visibility.ts +59 -0
- package/src/preflight.ts +60 -0
- package/src/provider.tsx +88 -0
- package/src/specs/NativeVoltkitRtc.ts +180 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NativeSession = NativeSession;
|
|
7
|
+
exports.useCallService = useCallService;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _react2 = require("@voltkit-rtc/react");
|
|
10
|
+
var _native = require("./native.js");
|
|
11
|
+
var _errors = require("./errors.js");
|
|
12
|
+
var _audio = require("./audio.js");
|
|
13
|
+
var _localMedia = require("./local-media.js");
|
|
14
|
+
var _visibility = require("./platform/visibility.js");
|
|
15
|
+
var _common = require("./platform/common.js");
|
|
16
|
+
/**
|
|
17
|
+
* What a connected call needs from the device on Android, kept by the provider for its client:
|
|
18
|
+
*
|
|
19
|
+
* - The call audio (audio.ts): held from the join to the close, so the audio mode, focus and routing are a call's; two
|
|
20
|
+
* clients (a PK battle) hold it together and the last out restores the device.
|
|
21
|
+
* - The call service: a foreground service that keeps the call's network, microphone and timers alive while the app is
|
|
22
|
+
* in the background or the screen is off. Without it Android cuts the app's sockets about 6 s after it leaves the
|
|
23
|
+
* foreground or the screen goes off (Phase 0 finding 3). It runs while any call is live, for every client together
|
|
24
|
+
* (one notification), when the app's manifest declares it (the Expo plugin's callService, default on). Android lets
|
|
25
|
+
* it start, and take new foreground service types (the camera, a screen share), only while the app is visible: it
|
|
26
|
+
* starts on the join and is brought up to date whenever the app comes back to the front. Its notification's Leave
|
|
27
|
+
* action, and the app being swiped away from Recents, close every client it runs for (close code 1000, `left`).
|
|
28
|
+
* Failures reach the provider's onError as `media-unavailable` with `{ feature: 'callService' }`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
/** The call service's notification. */
|
|
32
|
+
|
|
33
|
+
/** How the provider manages the call audio. */
|
|
34
|
+
|
|
35
|
+
// ----------------------------------------------------------------------------------------- the call service, shared
|
|
36
|
+
|
|
37
|
+
const NOT_DECLARED = Object.freeze({
|
|
38
|
+
declared: false,
|
|
39
|
+
running: false,
|
|
40
|
+
types: Object.freeze([])
|
|
41
|
+
});
|
|
42
|
+
class CallServices {
|
|
43
|
+
/**
|
|
44
|
+
* What each call wants, read afresh at every decision: a call's state is its client's, which emits no event for some
|
|
45
|
+
* changes. With how to tell the call when its state cannot be read at all.
|
|
46
|
+
*/
|
|
47
|
+
wants = new Map();
|
|
48
|
+
running = false;
|
|
49
|
+
/** The call to the native module under way: a `failed` event during a start or update is its rejection's twin. */
|
|
50
|
+
inFlight = null;
|
|
51
|
+
again = false;
|
|
52
|
+
/** The options the service runs with, as sent. */
|
|
53
|
+
applied = null;
|
|
54
|
+
/** Options a start failed for: not tried again until they change or the app comes back to the front. */
|
|
55
|
+
failed = null;
|
|
56
|
+
watching = null;
|
|
57
|
+
state = null;
|
|
58
|
+
listeners = new Set();
|
|
59
|
+
set(key, want, report = () => undefined) {
|
|
60
|
+
if (want) this.wants.set(key, {
|
|
61
|
+
want,
|
|
62
|
+
report
|
|
63
|
+
});else this.wants.delete(key);
|
|
64
|
+
this.reconcile();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Something a call publishes may have changed: decide again. */
|
|
68
|
+
changed() {
|
|
69
|
+
this.reconcile();
|
|
70
|
+
}
|
|
71
|
+
subscribe = listener => {
|
|
72
|
+
this.listeners.add(listener);
|
|
73
|
+
return () => {
|
|
74
|
+
this.listeners.delete(listener);
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
snapshot = () => {
|
|
78
|
+
if (this.state) return this.state;
|
|
79
|
+
const module = (0, _native.nativeModule)();
|
|
80
|
+
if (!module || !(0, _native.nativeConstants)()?.callServiceDeclared) return NOT_DECLARED;
|
|
81
|
+
let status = {
|
|
82
|
+
declared: true,
|
|
83
|
+
running: false,
|
|
84
|
+
types: []
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
status = module.getCallServiceStatus();
|
|
88
|
+
} catch (err) {
|
|
89
|
+
(0, _errors.logError)('could not read the call service\'s status', err);
|
|
90
|
+
}
|
|
91
|
+
this.state = {
|
|
92
|
+
declared: status.declared,
|
|
93
|
+
running: status.running,
|
|
94
|
+
types: [...status.types]
|
|
95
|
+
};
|
|
96
|
+
return this.state;
|
|
97
|
+
};
|
|
98
|
+
publish(status) {
|
|
99
|
+
const now = this.snapshot();
|
|
100
|
+
const next = {
|
|
101
|
+
...now,
|
|
102
|
+
...status
|
|
103
|
+
};
|
|
104
|
+
if (next.running === now.running && next.declared === now.declared && next.types.join() === now.types.join()) return;
|
|
105
|
+
this.state = next;
|
|
106
|
+
for (const listener of [...this.listeners]) listener();
|
|
107
|
+
}
|
|
108
|
+
live() {
|
|
109
|
+
const live = [];
|
|
110
|
+
for (const [key, {
|
|
111
|
+
want,
|
|
112
|
+
report
|
|
113
|
+
}] of [...this.wants]) {
|
|
114
|
+
let w;
|
|
115
|
+
try {
|
|
116
|
+
w = want();
|
|
117
|
+
} catch (err) {
|
|
118
|
+
// A client whose state cannot be read (a wrapper that throws on a read): this call is left out of the service
|
|
119
|
+
// for good, said once, and never keeps the other calls from theirs (the verifier's F3 on 0.1.1).
|
|
120
|
+
this.wants.delete(key);
|
|
121
|
+
(0, _errors.logError)('a call is left out of the call service: its client\'s state could not be read', err);
|
|
122
|
+
try {
|
|
123
|
+
report((0, _errors.callServiceFailed)(`this call is left out, its client's state could not be read: ${(0, _errors.describeError)(err)}`));
|
|
124
|
+
} catch (reportErr) {
|
|
125
|
+
(0, _errors.logError)('onError threw', reportErr);
|
|
126
|
+
}
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (w.live) live.push(w);
|
|
130
|
+
}
|
|
131
|
+
return live;
|
|
132
|
+
}
|
|
133
|
+
reconcile() {
|
|
134
|
+
const module = (0, _native.nativeModule)();
|
|
135
|
+
if (!module || !(0, _native.nativeConstants)()?.callServiceDeclared) return;
|
|
136
|
+
const live = this.live();
|
|
137
|
+
this.watch(module, live.length > 0 || this.running);
|
|
138
|
+
if (this.inFlight) {
|
|
139
|
+
this.again = true;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (live.length === 0) {
|
|
143
|
+
this.failed = null;
|
|
144
|
+
if (this.running || this.applied !== null) this.run(module, 'stop', null);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const options = merged(live);
|
|
148
|
+
const key = JSON.stringify(options);
|
|
149
|
+
if (this.running && key === this.applied || key === this.failed) return;
|
|
150
|
+
// Android lets a foreground service start, or widen its types, only while the app is visible.
|
|
151
|
+
if (!safeVisible(module)) return;
|
|
152
|
+
this.run(module, this.running ? 'update' : 'start', options);
|
|
153
|
+
}
|
|
154
|
+
run(module, what, options) {
|
|
155
|
+
this.inFlight = what;
|
|
156
|
+
const key = options ? JSON.stringify(options) : null;
|
|
157
|
+
const call = what === 'stop' ? module.stopCallService() : what === 'start' ? module.startCallService(options) : module.updateCallService(options);
|
|
158
|
+
call.then(status => {
|
|
159
|
+
this.running = status.running;
|
|
160
|
+
this.applied = status.running ? key : null;
|
|
161
|
+
if (status.running) this.failed = null;
|
|
162
|
+
this.publish({
|
|
163
|
+
declared: status.declared,
|
|
164
|
+
running: status.running,
|
|
165
|
+
types: [...status.types]
|
|
166
|
+
});
|
|
167
|
+
}, err => {
|
|
168
|
+
if (what === 'stop') {
|
|
169
|
+
(0, _errors.logError)('could not stop the call service', err);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
this.failed = key;
|
|
173
|
+
const error = (0, _errors.callServiceFailed)((0, _errors.describeError)(err));
|
|
174
|
+
for (const want of this.live()) want.report(error);
|
|
175
|
+
}).finally(() => {
|
|
176
|
+
this.inFlight = null;
|
|
177
|
+
if (this.again) {
|
|
178
|
+
this.again = false;
|
|
179
|
+
this.reconcile();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
// Nothing left to keep running: stop listening until the next call.
|
|
183
|
+
if (!this.running && this.live().length === 0) this.watch(module, false);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Visibility and the service's own events, while a call is live or the service runs. */
|
|
188
|
+
watch(module, on) {
|
|
189
|
+
if (on === (this.watching !== null)) return;
|
|
190
|
+
if (!on) {
|
|
191
|
+
this.watching?.();
|
|
192
|
+
this.watching = null;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
const visibility = (0, _visibility.nativeVisibility)(module);
|
|
196
|
+
const stops = [visibility.subscribe(visible => {
|
|
197
|
+
if (!visible) return;
|
|
198
|
+
// Back in front: try again what failed, and bring the service up to date.
|
|
199
|
+
this.failed = null;
|
|
200
|
+
this.reconcile();
|
|
201
|
+
}), (0, _native.listen)(module.onCallServiceEvent, 'onCallServiceEvent', event => this.onEvent(event.type, event.types, event.message))];
|
|
202
|
+
this.watching = () => {
|
|
203
|
+
for (const stop of stops) stop();
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
onEvent(type, types, message) {
|
|
207
|
+
switch (type) {
|
|
208
|
+
case 'started':
|
|
209
|
+
case 'updated':
|
|
210
|
+
this.running = true;
|
|
211
|
+
this.publish({
|
|
212
|
+
running: true,
|
|
213
|
+
types: [...types]
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
case 'stopped':
|
|
217
|
+
this.running = false;
|
|
218
|
+
this.applied = null;
|
|
219
|
+
// Stopped from outside while a call is live: started again when the app next comes to the front, not now.
|
|
220
|
+
if (this.live().length > 0) this.failed = JSON.stringify(merged(this.live()));
|
|
221
|
+
this.publish({
|
|
222
|
+
running: false,
|
|
223
|
+
types: []
|
|
224
|
+
});
|
|
225
|
+
this.reconcile();
|
|
226
|
+
return;
|
|
227
|
+
case 'leave':
|
|
228
|
+
case 'taskRemoved':
|
|
229
|
+
for (const want of this.live()) want.leave();
|
|
230
|
+
return;
|
|
231
|
+
case 'failed':
|
|
232
|
+
{
|
|
233
|
+
// VoltkitCallService.runWith tells `failed` and then rejects the start or update: the rejection reports it (RN010-2).
|
|
234
|
+
if (this.inFlight === 'start' || this.inFlight === 'update') return;
|
|
235
|
+
const error = (0, _errors.callServiceFailed)(message || 'Android refused it');
|
|
236
|
+
for (const want of this.live()) want.report(error);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
default:
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function safeVisible(module) {
|
|
244
|
+
try {
|
|
245
|
+
return module.isAppVisible();
|
|
246
|
+
} catch {
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** What the service runs with for these calls together. */
|
|
252
|
+
function merged(live) {
|
|
253
|
+
const text = [...live].reverse();
|
|
254
|
+
const pick = field => text.find(w => w.text[field])?.text[field] ?? '';
|
|
255
|
+
return {
|
|
256
|
+
title: pick('title'),
|
|
257
|
+
text: pick('text'),
|
|
258
|
+
leaveLabel: pick('leaveLabel'),
|
|
259
|
+
// The camera type only for a call that keeps its camera on in the background.
|
|
260
|
+
pauseCamera: !live.some(w => w.cameraPublished && !w.pauseCamera),
|
|
261
|
+
micPublished: live.some(w => w.micPublished),
|
|
262
|
+
cameraPublished: live.some(w => w.cameraPublished),
|
|
263
|
+
sharing: live.some(w => w.sharing)
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
const callServices = new CallServices();
|
|
267
|
+
|
|
268
|
+
/** The call service: whether the app declares it, whether it runs and with which types. */
|
|
269
|
+
function useCallService() {
|
|
270
|
+
return (0, _react.useSyncExternalStore)(callServices.subscribe, callServices.snapshot, callServices.snapshot);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ---------------------------------------------------------------------------------------------- the provider's part
|
|
274
|
+
|
|
275
|
+
/** Rendered by the provider inside @voltkit-rtc/react's provider: keeps the call audio and the call service for its client. */
|
|
276
|
+
function NativeSession({
|
|
277
|
+
audio,
|
|
278
|
+
callService,
|
|
279
|
+
pauseCamera,
|
|
280
|
+
onError
|
|
281
|
+
}) {
|
|
282
|
+
const client = (0, _react2.useVoltkitClient)();
|
|
283
|
+
const manage = audio !== false && audio?.manage !== false;
|
|
284
|
+
const speakerphone = audio === false ? undefined : audio?.speakerphone;
|
|
285
|
+
const wantsService = callService !== false;
|
|
286
|
+
const text = (0, _react.useMemo)(() => typeof callService === 'object' && callService !== null ? callService : {}, [callService]);
|
|
287
|
+
const latest = (0, _react.useRef)({
|
|
288
|
+
speakerphone,
|
|
289
|
+
text,
|
|
290
|
+
pauseCamera
|
|
291
|
+
});
|
|
292
|
+
(0, _react.useEffect)(() => {
|
|
293
|
+
latest.current = {
|
|
294
|
+
speakerphone,
|
|
295
|
+
text,
|
|
296
|
+
pauseCamera
|
|
297
|
+
};
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// What useLocalMedia shows (the screen being shared) is recorded for as long as the provider has the client.
|
|
301
|
+
(0, _react.useEffect)(() => client ? (0, _localMedia.localSessionOf)(client).hold() : undefined, [client]);
|
|
302
|
+
(0, _react.useEffect)(() => {
|
|
303
|
+
if (!client || !manage || !(0, _native.nativeModule)()) return;
|
|
304
|
+
const hold = (0, _audio.audioHoldOf)(client, error => onError.current?.(error));
|
|
305
|
+
hold.retain();
|
|
306
|
+
const sync = () => {
|
|
307
|
+
const state = client.connectionState;
|
|
308
|
+
if (state === 'connected' || state === 'reconnecting') hold.acquire((0, _audio.speakerPreference)(latest.current.speakerphone));else if (state === 'closed') hold.release();
|
|
309
|
+
};
|
|
310
|
+
sync();
|
|
311
|
+
const off = client.on('connectionStateChanged', sync);
|
|
312
|
+
return () => {
|
|
313
|
+
off();
|
|
314
|
+
hold.unretain();
|
|
315
|
+
};
|
|
316
|
+
}, [client, manage, onError]);
|
|
317
|
+
(0, _react.useEffect)(() => {
|
|
318
|
+
if (!client || !wantsService || !(0, _native.nativeModule)()) return;
|
|
319
|
+
const key = {};
|
|
320
|
+
const report = error => onError.current?.(error);
|
|
321
|
+
callServices.set(key, () => wantOf(client, latest.current, report), report);
|
|
322
|
+
const update = () => callServices.changed();
|
|
323
|
+
// publish() and a camera switch emit no event of their own: useLocalMedia's calls say so through the local session.
|
|
324
|
+
const offs = [...['connectionStateChanged', 'localMediaChanged', 'localStreamChanged', 'screenShareStarted', 'screenShareEnded'].map(event => client.on(event, update)), (0, _localMedia.localSessionOf)(client).subscribe(update)];
|
|
325
|
+
return () => {
|
|
326
|
+
for (const off of offs) off();
|
|
327
|
+
callServices.set(key, null);
|
|
328
|
+
};
|
|
329
|
+
}, [client, wantsService, onError]);
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
function wantOf(client, latest, report) {
|
|
333
|
+
const state = client.connectionState;
|
|
334
|
+
const local = (0, _common.localStream)(client);
|
|
335
|
+
return {
|
|
336
|
+
live: state === 'connected' || state === 'reconnecting',
|
|
337
|
+
micPublished: (local?.getAudioTracks().length ?? 0) > 0,
|
|
338
|
+
cameraPublished: (local?.getVideoTracks().length ?? 0) > 0,
|
|
339
|
+
sharing: (0, _localMedia.localSessionOf)(client).screen !== null,
|
|
340
|
+
pauseCamera: pausesCameraInBackground(client) ?? latest.pauseCamera,
|
|
341
|
+
text: latest.text,
|
|
342
|
+
leave: () => client.close(),
|
|
343
|
+
report
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Whether the client switches its camera off in the background, from its own options: the provider's `background` only
|
|
349
|
+
* describes a client the provider made, and an app-made one (`createClient`, the `client` prop) keeps its camera on with
|
|
350
|
+
* `pauseCamera: false` while the service was asked for no camera type, so Android cut the camera (RN010-1). The client
|
|
351
|
+
* pauses only with `pauseCameraInBackground === true` (left out, the camera runs on). Null when the options cannot be
|
|
352
|
+
* read (missing, not an object, or a read that throws: a wrapped or stubbed client): the provider's setting stands in.
|
|
353
|
+
*/
|
|
354
|
+
function pausesCameraInBackground(client) {
|
|
355
|
+
let options;
|
|
356
|
+
try {
|
|
357
|
+
options = client.options;
|
|
358
|
+
} catch {
|
|
359
|
+
// A wrapper that forbids the read (a logging or sealing Proxy): not an error, the provider's setting stands in.
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
if (!options || typeof options !== 'object') return null;
|
|
363
|
+
return options.pauseCameraInBackground === true;
|
|
364
|
+
}
|
|
365
|
+
//# sourceMappingURL=native-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_react2","_native","_errors","_audio","_localMedia","_visibility","_common","NOT_DECLARED","Object","freeze","declared","running","types","CallServices","wants","Map","inFlight","again","applied","failed","watching","state","listeners","Set","set","key","want","report","undefined","delete","reconcile","changed","subscribe","listener","add","snapshot","module","nativeModule","nativeConstants","callServiceDeclared","status","getCallServiceStatus","err","logError","publish","now","next","join","live","w","callServiceFailed","describeError","reportErr","push","watch","length","run","options","merged","JSON","stringify","safeVisible","what","call","stopCallService","startCallService","updateCallService","then","error","finally","on","visibility","nativeVisibility","stops","visible","listen","onCallServiceEvent","event","onEvent","type","message","stop","leave","isAppVisible","text","reverse","pick","field","find","title","leaveLabel","pauseCamera","some","cameraPublished","micPublished","sharing","callServices","useCallService","useSyncExternalStore","NativeSession","audio","callService","onError","client","useVoltkitClient","manage","speakerphone","wantsService","useMemo","latest","useRef","useEffect","current","localSessionOf","hold","audioHoldOf","retain","sync","connectionState","acquire","speakerPreference","release","off","unretain","wantOf","update","offs","map","local","localStream","getAudioTracks","getVideoTracks","screen","pausesCameraInBackground","close","pauseCameraInBackground"],"sourceRoot":"../../src","sources":["native-session.tsx"],"mappings":";;;;;;;AAcA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,WAAA,GAAAN,OAAA;AACA,IAAAO,OAAA,GAAAP,OAAA;AAvBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;;AAUA;;AAQA;;AAuBA,MAAMQ,YAA8B,GAAGC,MAAM,CAACC,MAAM,CAAC;EAAEC,QAAQ,EAAE,KAAK;EAAEC,OAAO,EAAE,KAAK;EAAEC,KAAK,EAAEJ,MAAM,CAACC,MAAM,CAAC,EAAE;AAAyB,CAAC,CAAC;AAE1I,MAAMI,YAAY,CAAC;EACjB;AACF;AACA;AACA;EACmBC,KAAK,GAAG,IAAIC,GAAG,CAA+D,CAAC;EACxFJ,OAAO,GAAG,KAAK;EACvB;EACQK,QAAQ,GAAuC,IAAI;EACnDC,KAAK,GAAG,KA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CAAC,MAAM;IACN;IACA,OAAO,IAAI;EACb;EACA,IAAI,CAACA,OAAO,IAAI,OAAOA,OAAO,KAAK,QAAQ,EAAE,OAAO,IAAI;EACxD,OAAQA,OAAO,CAAmB8E,uBAAuB,KAAK,IAAI;AACpE","ignoreList":[]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SDK_VERSION = void 0;
|
|
7
|
+
exports.listen = listen;
|
|
8
|
+
exports.nativeConstants = nativeConstants;
|
|
9
|
+
exports.nativeModule = nativeModule;
|
|
10
|
+
exports.requireNative = requireNative;
|
|
11
|
+
exports.resetNativeForTests = resetNativeForTests;
|
|
12
|
+
exports.toMediaDevice = toMediaDevice;
|
|
13
|
+
var _reactNative = require("react-native");
|
|
14
|
+
var _NativeVoltkitRtc = _interopRequireDefault(require("./specs/NativeVoltkitRtc.js"));
|
|
15
|
+
var _errors = require("./errors.js");
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
/**
|
|
18
|
+
* This package's native module (src/specs/NativeVoltkitRtc.ts), read only through here: it is null on iOS (JavaScript
|
|
19
|
+
* only in 0.1.0), in Expo Go and wherever the app was not rebuilt after installing the package. Everything that can do
|
|
20
|
+
* without it does (JavaScript timers, AppState); what cannot raises `media-unavailable` (errors.ts).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** The version of this package: what getDiagnostics() reports, and what the native side was built from. */
|
|
24
|
+
const SDK_VERSION = exports.SDK_VERSION = '0.1.1';
|
|
25
|
+
|
|
26
|
+
/** The native module, or null where there is none (iOS, Expo Go, an app not rebuilt). */
|
|
27
|
+
function nativeModule() {
|
|
28
|
+
if (_reactNative.Platform.OS !== 'android') return null;
|
|
29
|
+
return _NativeVoltkitRtc.default ?? null;
|
|
30
|
+
}
|
|
31
|
+
let constants = null;
|
|
32
|
+
let staleWarned = false;
|
|
33
|
+
|
|
34
|
+
/** The module's constants, read once: the audio mode, screen sharing, the call service as the manifest declares them. */
|
|
35
|
+
function nativeConstants() {
|
|
36
|
+
const module = nativeModule();
|
|
37
|
+
if (!module) return null;
|
|
38
|
+
if (constants?.module === module) return constants.value;
|
|
39
|
+
let value;
|
|
40
|
+
try {
|
|
41
|
+
value = module.getConstants();
|
|
42
|
+
} catch (err) {
|
|
43
|
+
(0, _errors.logError)('could not read the native module\'s constants', err);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
constants = {
|
|
47
|
+
module,
|
|
48
|
+
value
|
|
49
|
+
};
|
|
50
|
+
if (!staleWarned && value.nativeVersion && value.nativeVersion !== SDK_VERSION) {
|
|
51
|
+
staleWarned = true;
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
console.warn(`[voltkit-rtc] the app's native code is @voltkit-rtc/react-native ${value.nativeVersion} but its JavaScript is ${SDK_VERSION}: rebuild the app`);
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The native module for `feature`, or the error that says why there is none. */
|
|
59
|
+
function requireNative(feature) {
|
|
60
|
+
if (_reactNative.Platform.OS === 'ios') throw (0, _errors.iosUnsupported)(feature);
|
|
61
|
+
const module = nativeModule();
|
|
62
|
+
if (!module) throw (0, _errors.nativeMissing)(feature);
|
|
63
|
+
return module;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Subscribe to one of the module's events; a listener that throws is logged and the others still run. */
|
|
67
|
+
function listen(emitter, name, listener) {
|
|
68
|
+
if (typeof emitter !== 'function') return () => undefined;
|
|
69
|
+
const subscription = emitter(value => {
|
|
70
|
+
try {
|
|
71
|
+
listener(value);
|
|
72
|
+
} catch (err) {
|
|
73
|
+
(0, _errors.logError)(`listener for ${name} threw`, err);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return () => subscription.remove();
|
|
77
|
+
}
|
|
78
|
+
const AUDIO_TYPES = ['speaker', 'earpiece', 'wiredHeadset', 'bluetooth', 'usb', 'builtinMic', 'other'];
|
|
79
|
+
const KINDS = ['audioinput', 'audiooutput', 'videoinput'];
|
|
80
|
+
|
|
81
|
+
/** A native audio device as the client's MediaDevice. */
|
|
82
|
+
function toMediaDevice(device) {
|
|
83
|
+
const type = AUDIO_TYPES.includes(device.type) ? device.type : 'other';
|
|
84
|
+
const kind = KINDS.includes(device.kind) ? device.kind : 'audiooutput';
|
|
85
|
+
return {
|
|
86
|
+
deviceId: device.deviceId,
|
|
87
|
+
groupId: device.groupId ?? '',
|
|
88
|
+
kind,
|
|
89
|
+
label: device.label,
|
|
90
|
+
type
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** For tests: forget the cached constants. */
|
|
95
|
+
function resetNativeForTests() {
|
|
96
|
+
constants = null;
|
|
97
|
+
staleWarned = false;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_NativeVoltkitRtc","_interopRequireDefault","_errors","e","__esModule","default","SDK_VERSION","exports","nativeModule","Platform","OS","NativeVoltkitRtc","constants","staleWarned","nativeConstants","module","value","getConstants","err","logError","nativeVersion","console","warn","requireNative","feature","iosUnsupported","nativeMissing","listen","emitter","name","listener","undefined","subscription","remove","AUDIO_TYPES","KINDS","toMediaDevice","device","type","includes","kind","deviceId","groupId","label","resetNativeForTests"],"sourceRoot":"../../src","sources":["native.ts"],"mappings":";;;;;;;;;;;;AAKA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,iBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAAmE,SAAAE,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AARnE;AAC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|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkMediaPermissions = checkMediaPermissions;
|
|
7
|
+
exports.requestMediaPermissions = requestMediaPermissions;
|
|
8
|
+
exports.usePermissions = usePermissions;
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
var _globals = require("./globals.js");
|
|
12
|
+
var _errors = require("./errors.js");
|
|
13
|
+
/**
|
|
14
|
+
* Camera, microphone and notification permissions.
|
|
15
|
+
*
|
|
16
|
+
* Android: PermissionsAndroid. `blocked` is Android's "never ask again" (the user refused twice, or chose "Don't ask
|
|
17
|
+
* again"): only the app's settings can grant it now. The notification permission (Android 13+, POST_NOTIFICATIONS,
|
|
18
|
+
* for the call service's notification) is asked only when asked for; below Android 13 there is none to ask.
|
|
19
|
+
*
|
|
20
|
+
* iOS (preview): react-native-webrtc's permissions module. iOS asks once: a refusal is `blocked` from then on.
|
|
21
|
+
*
|
|
22
|
+
* useLocalMedia().publish() asks for what it needs before any device opens, so a refusal is a `media-unavailable`
|
|
23
|
+
* error with `{ permission, status }` and the camera light never comes on. The SDK's own captures afterwards (a
|
|
24
|
+
* reconnect, a switch) only check, never ask: a dialog must not open in the background.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/** What can be asked for. */
|
|
28
|
+
|
|
29
|
+
/** `granted`; `denied` (not granted yet: asking may still show the dialog); `blocked` (only the settings can grant it). */
|
|
30
|
+
|
|
31
|
+
const ANDROID = {
|
|
32
|
+
camera: 'android.permission.CAMERA',
|
|
33
|
+
microphone: 'android.permission.RECORD_AUDIO',
|
|
34
|
+
notifications: 'android.permission.POST_NOTIFICATIONS'
|
|
35
|
+
};
|
|
36
|
+
const unique = kinds => [...new Set(kinds)];
|
|
37
|
+
|
|
38
|
+
/** Android 13 and later have a notification permission; below, notifications need none. */
|
|
39
|
+
const notificationsNeedAsking = () => _reactNative.Platform.OS === 'android' && Number(_reactNative.Platform.Version) >= 33;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Ask for these permissions, showing the system's dialogs for those not granted yet. Resolves with each one's status;
|
|
43
|
+
* never rejects.
|
|
44
|
+
*/
|
|
45
|
+
async function requestMediaPermissions(kinds) {
|
|
46
|
+
const wanted = unique(kinds);
|
|
47
|
+
const out = {};
|
|
48
|
+
if (wanted.length === 0) return out;
|
|
49
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
50
|
+
const ask = wanted.filter(k => k !== 'notifications' || notificationsNeedAsking());
|
|
51
|
+
for (const kind of wanted) if (!ask.includes(kind)) out[kind] = 'granted';
|
|
52
|
+
if (ask.length === 0) return out;
|
|
53
|
+
let results = {};
|
|
54
|
+
try {
|
|
55
|
+
results = await _reactNative.PermissionsAndroid.requestMultiple(ask.map(k => ANDROID[k]));
|
|
56
|
+
} catch (err) {
|
|
57
|
+
(0, _errors.logError)('could not ask for permissions', err);
|
|
58
|
+
}
|
|
59
|
+
for (const kind of ask) out[kind] = androidStatus(results[ANDROID[kind]]);
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
for (const kind of wanted) out[kind] = await requestIos(kind);
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Each permission's status now, without asking. Never rejects. */
|
|
67
|
+
async function checkMediaPermissions(kinds) {
|
|
68
|
+
const wanted = unique(kinds);
|
|
69
|
+
const out = {};
|
|
70
|
+
for (const kind of wanted) {
|
|
71
|
+
if (_reactNative.Platform.OS === 'android') {
|
|
72
|
+
if (kind === 'notifications' && !notificationsNeedAsking()) {
|
|
73
|
+
out[kind] = 'granted';
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
out[kind] = (await _reactNative.PermissionsAndroid.check(ANDROID[kind])) ? 'granted' : 'denied';
|
|
78
|
+
} catch (err) {
|
|
79
|
+
(0, _errors.logError)('could not check a permission', err);
|
|
80
|
+
out[kind] = 'denied';
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
out[kind] = await queryIos(kind);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
function androidStatus(result) {
|
|
89
|
+
if (result === 'granted') return 'granted';
|
|
90
|
+
if (result === 'never_ask_again') return 'blocked';
|
|
91
|
+
return 'denied';
|
|
92
|
+
}
|
|
93
|
+
async function queryIos(kind) {
|
|
94
|
+
// The SDK shows no notification of its own on iOS: nothing to ask.
|
|
95
|
+
if (kind === 'notifications') return 'granted';
|
|
96
|
+
const webrtc = (0, _globals.loadWebRTC)();
|
|
97
|
+
if (!webrtc) return 'denied';
|
|
98
|
+
try {
|
|
99
|
+
const result = await webrtc.permissions.query({
|
|
100
|
+
name: kind
|
|
101
|
+
});
|
|
102
|
+
if (result === 'granted') return 'granted';
|
|
103
|
+
return result === 'denied' ? 'blocked' : 'denied';
|
|
104
|
+
} catch (err) {
|
|
105
|
+
(0, _errors.logError)('could not check a permission', err);
|
|
106
|
+
return 'denied';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function requestIos(kind) {
|
|
110
|
+
const now = await queryIos(kind);
|
|
111
|
+
if (now !== 'denied') return now;
|
|
112
|
+
const webrtc = (0, _globals.loadWebRTC)();
|
|
113
|
+
if (!webrtc) return 'denied';
|
|
114
|
+
try {
|
|
115
|
+
return (await webrtc.permissions.request({
|
|
116
|
+
name: kind
|
|
117
|
+
})) ? 'granted' : 'blocked';
|
|
118
|
+
} catch (err) {
|
|
119
|
+
(0, _errors.logError)('could not ask for a permission', err);
|
|
120
|
+
return 'denied';
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The status of these permissions, checked on mount and whenever the app returns to the front (the user may have
|
|
125
|
+
* changed them in the settings), with `request()` to ask for them.
|
|
126
|
+
*/
|
|
127
|
+
function usePermissions(kinds) {
|
|
128
|
+
const key = unique(kinds).sort().join(',');
|
|
129
|
+
const wanted = (0, _react.useMemo)(() => key ? key.split(',') : [], [key]);
|
|
130
|
+
const [statuses, setStatuses] = (0, _react.useState)(null);
|
|
131
|
+
const live = (0, _react.useRef)(true);
|
|
132
|
+
const refresh = (0, _react.useCallback)(async () => {
|
|
133
|
+
const next = await checkMediaPermissions(wanted);
|
|
134
|
+
if (live.current) setStatuses(previous => same(previous, next) ? previous : next);
|
|
135
|
+
return next;
|
|
136
|
+
}, [wanted]);
|
|
137
|
+
const request = (0, _react.useCallback)(async () => {
|
|
138
|
+
const next = await requestMediaPermissions(wanted);
|
|
139
|
+
if (live.current) setStatuses(previous => same(previous, next) ? previous : next);
|
|
140
|
+
return next;
|
|
141
|
+
}, [wanted]);
|
|
142
|
+
(0, _react.useEffect)(() => {
|
|
143
|
+
live.current = true;
|
|
144
|
+
void refresh();
|
|
145
|
+
const subscription = _reactNative.AppState.addEventListener('change', state => {
|
|
146
|
+
if (state === 'active') void refresh();
|
|
147
|
+
});
|
|
148
|
+
return () => {
|
|
149
|
+
live.current = false;
|
|
150
|
+
subscription?.remove();
|
|
151
|
+
};
|
|
152
|
+
}, [refresh]);
|
|
153
|
+
const granted = statuses !== null && wanted.every(k => statuses[k] === 'granted');
|
|
154
|
+
return (0, _react.useMemo)(() => ({
|
|
155
|
+
statuses,
|
|
156
|
+
granted,
|
|
157
|
+
request,
|
|
158
|
+
refresh
|
|
159
|
+
}), [statuses, granted, request, refresh]);
|
|
160
|
+
}
|
|
161
|
+
function same(a, b) {
|
|
162
|
+
if (!a) return false;
|
|
163
|
+
const keys = Object.keys(b);
|
|
164
|
+
return keys.length === Object.keys(a).length && keys.every(k => a[k] === b[k]);
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=permissions.js.map
|