@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.
Files changed (225) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1608 -2
  4. package/android/build.gradle +70 -0
  5. package/android/consumer-rules.pro +21 -0
  6. package/android/src/main/AndroidManifest.xml +25 -0
  7. package/android/src/main/java/com/voltkit/rtc/reactnative/AppVisibility.kt +67 -0
  8. package/android/src/main/java/com/voltkit/rtc/reactnative/AudioDevices.kt +67 -0
  9. package/android/src/main/java/com/voltkit/rtc/reactnative/AudioRouter.kt +487 -0
  10. package/android/src/main/java/com/voltkit/rtc/reactnative/CallServiceTypes.kt +120 -0
  11. package/android/src/main/java/com/voltkit/rtc/reactnative/NativeTimers.kt +106 -0
  12. package/android/src/main/java/com/voltkit/rtc/reactnative/NetworkWatch.kt +120 -0
  13. package/android/src/main/java/com/voltkit/rtc/reactnative/OutputChoice.kt +65 -0
  14. package/android/src/main/java/com/voltkit/rtc/reactnative/RtcConfig.kt +83 -0
  15. package/android/src/main/java/com/voltkit/rtc/reactnative/ScoLink.kt +61 -0
  16. package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitCallService.kt +287 -0
  17. package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitRtcInitProvider.kt +215 -0
  18. package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitRtcModule.kt +313 -0
  19. package/android/src/main/java/com/voltkit/rtc/reactnative/VoltkitRtcPackage.kt +30 -0
  20. package/android/src/main/res/drawable/voltkit_rtc_default_call_icon.xml +15 -0
  21. package/android/src/main/res/raw/voltkit_rtc_keep.xml +7 -0
  22. package/app.plugin.js +17 -0
  23. package/lib/commonjs/audio.js +215 -0
  24. package/lib/commonjs/audio.js.map +1 -0
  25. package/lib/commonjs/components.js +207 -0
  26. package/lib/commonjs/components.js.map +1 -0
  27. package/lib/commonjs/create-client.js +47 -0
  28. package/lib/commonjs/create-client.js.map +1 -0
  29. package/lib/commonjs/errors.js +99 -0
  30. package/lib/commonjs/errors.js.map +1 -0
  31. package/lib/commonjs/globals.js +61 -0
  32. package/lib/commonjs/globals.js.map +1 -0
  33. package/lib/commonjs/index.js +234 -0
  34. package/lib/commonjs/index.js.map +1 -0
  35. package/lib/commonjs/local-media.js +392 -0
  36. package/lib/commonjs/local-media.js.map +1 -0
  37. package/lib/commonjs/native-session.js +365 -0
  38. package/lib/commonjs/native-session.js.map +1 -0
  39. package/lib/commonjs/native.js +99 -0
  40. package/lib/commonjs/native.js.map +1 -0
  41. package/lib/commonjs/package.json +1 -0
  42. package/lib/commonjs/permissions.js +166 -0
  43. package/lib/commonjs/permissions.js.map +1 -0
  44. package/lib/commonjs/platform/android.js +126 -0
  45. package/lib/commonjs/platform/android.js.map +1 -0
  46. package/lib/commonjs/platform/common.js +138 -0
  47. package/lib/commonjs/platform/common.js.map +1 -0
  48. package/lib/commonjs/platform/devices.js +151 -0
  49. package/lib/commonjs/platform/devices.js.map +1 -0
  50. package/lib/commonjs/platform/index.js +35 -0
  51. package/lib/commonjs/platform/index.js.map +1 -0
  52. package/lib/commonjs/platform/ios.js +54 -0
  53. package/lib/commonjs/platform/ios.js.map +1 -0
  54. package/lib/commonjs/platform/streams.js +273 -0
  55. package/lib/commonjs/platform/streams.js.map +1 -0
  56. package/lib/commonjs/platform/timers.js +71 -0
  57. package/lib/commonjs/platform/timers.js.map +1 -0
  58. package/lib/commonjs/platform/visibility.js +60 -0
  59. package/lib/commonjs/platform/visibility.js.map +1 -0
  60. package/lib/commonjs/preflight.js +77 -0
  61. package/lib/commonjs/preflight.js.map +1 -0
  62. package/lib/commonjs/provider.js +75 -0
  63. package/lib/commonjs/provider.js.map +1 -0
  64. package/lib/commonjs/specs/NativeVoltkitRtc.js +29 -0
  65. package/lib/commonjs/specs/NativeVoltkitRtc.js.map +1 -0
  66. package/lib/module/audio.js +207 -0
  67. package/lib/module/audio.js.map +1 -0
  68. package/lib/module/components.js +200 -0
  69. package/lib/module/components.js.map +1 -0
  70. package/lib/module/create-client.js +42 -0
  71. package/lib/module/create-client.js.map +1 -0
  72. package/lib/module/errors.js +87 -0
  73. package/lib/module/errors.js.map +1 -0
  74. package/lib/module/globals.js +53 -0
  75. package/lib/module/globals.js.map +1 -0
  76. package/lib/module/index.js +33 -0
  77. package/lib/module/index.js.map +1 -0
  78. package/lib/module/local-media.js +387 -0
  79. package/lib/module/local-media.js.map +1 -0
  80. package/lib/module/native-session.js +360 -0
  81. package/lib/module/native-session.js.map +1 -0
  82. package/lib/module/native.js +87 -0
  83. package/lib/module/native.js.map +1 -0
  84. package/lib/module/package.json +1 -0
  85. package/lib/module/permissions.js +160 -0
  86. package/lib/module/permissions.js.map +1 -0
  87. package/lib/module/platform/android.js +122 -0
  88. package/lib/module/platform/android.js.map +1 -0
  89. package/lib/module/platform/common.js +128 -0
  90. package/lib/module/platform/common.js.map +1 -0
  91. package/lib/module/platform/devices.js +142 -0
  92. package/lib/module/platform/devices.js.map +1 -0
  93. package/lib/module/platform/index.js +24 -0
  94. package/lib/module/platform/index.js.map +1 -0
  95. package/lib/module/platform/ios.js +49 -0
  96. package/lib/module/platform/ios.js.map +1 -0
  97. package/lib/module/platform/streams.js +268 -0
  98. package/lib/module/platform/streams.js.map +1 -0
  99. package/lib/module/platform/timers.js +67 -0
  100. package/lib/module/platform/timers.js.map +1 -0
  101. package/lib/module/platform/visibility.js +54 -0
  102. package/lib/module/platform/visibility.js.map +1 -0
  103. package/lib/module/preflight.js +72 -0
  104. package/lib/module/preflight.js.map +1 -0
  105. package/lib/module/provider.js +70 -0
  106. package/lib/module/provider.js.map +1 -0
  107. package/lib/module/specs/NativeVoltkitRtc.js +37 -0
  108. package/lib/module/specs/NativeVoltkitRtc.js.map +1 -0
  109. package/lib/typescript/commonjs/audio.d.ts +58 -0
  110. package/lib/typescript/commonjs/audio.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/components.d.ts +58 -0
  112. package/lib/typescript/commonjs/components.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/create-client.d.ts +35 -0
  114. package/lib/typescript/commonjs/create-client.d.ts.map +1 -0
  115. package/lib/typescript/commonjs/errors.d.ts +34 -0
  116. package/lib/typescript/commonjs/errors.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/globals.d.ts +16 -0
  118. package/lib/typescript/commonjs/globals.d.ts.map +1 -0
  119. package/lib/typescript/commonjs/index.d.ts +24 -0
  120. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  121. package/lib/typescript/commonjs/local-media.d.ts +86 -0
  122. package/lib/typescript/commonjs/local-media.d.ts.map +1 -0
  123. package/lib/typescript/commonjs/native-session.d.ts +38 -0
  124. package/lib/typescript/commonjs/native-session.d.ts.map +1 -0
  125. package/lib/typescript/commonjs/native.d.ts +18 -0
  126. package/lib/typescript/commonjs/native.d.ts.map +1 -0
  127. package/lib/typescript/commonjs/package.json +1 -0
  128. package/lib/typescript/commonjs/permissions.d.ts +30 -0
  129. package/lib/typescript/commonjs/permissions.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/platform/android.d.ts +4 -0
  131. package/lib/typescript/commonjs/platform/android.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/platform/common.d.ts +101 -0
  133. package/lib/typescript/commonjs/platform/common.d.ts.map +1 -0
  134. package/lib/typescript/commonjs/platform/devices.d.ts +42 -0
  135. package/lib/typescript/commonjs/platform/devices.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/platform/index.d.ts +6 -0
  137. package/lib/typescript/commonjs/platform/index.d.ts.map +1 -0
  138. package/lib/typescript/commonjs/platform/ios.d.ts +4 -0
  139. package/lib/typescript/commonjs/platform/ios.d.ts.map +1 -0
  140. package/lib/typescript/commonjs/platform/streams.d.ts +82 -0
  141. package/lib/typescript/commonjs/platform/streams.d.ts.map +1 -0
  142. package/lib/typescript/commonjs/platform/timers.d.ts +19 -0
  143. package/lib/typescript/commonjs/platform/timers.d.ts.map +1 -0
  144. package/lib/typescript/commonjs/platform/visibility.d.ts +11 -0
  145. package/lib/typescript/commonjs/platform/visibility.d.ts.map +1 -0
  146. package/lib/typescript/commonjs/preflight.d.ts +19 -0
  147. package/lib/typescript/commonjs/preflight.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/provider.d.ts +35 -0
  149. package/lib/typescript/commonjs/provider.d.ts.map +1 -0
  150. package/lib/typescript/commonjs/specs/NativeVoltkitRtc.d.ts +157 -0
  151. package/lib/typescript/commonjs/specs/NativeVoltkitRtc.d.ts.map +1 -0
  152. package/lib/typescript/module/audio.d.ts +58 -0
  153. package/lib/typescript/module/audio.d.ts.map +1 -0
  154. package/lib/typescript/module/components.d.ts +58 -0
  155. package/lib/typescript/module/components.d.ts.map +1 -0
  156. package/lib/typescript/module/create-client.d.ts +35 -0
  157. package/lib/typescript/module/create-client.d.ts.map +1 -0
  158. package/lib/typescript/module/errors.d.ts +34 -0
  159. package/lib/typescript/module/errors.d.ts.map +1 -0
  160. package/lib/typescript/module/globals.d.ts +16 -0
  161. package/lib/typescript/module/globals.d.ts.map +1 -0
  162. package/lib/typescript/module/index.d.ts +24 -0
  163. package/lib/typescript/module/index.d.ts.map +1 -0
  164. package/lib/typescript/module/local-media.d.ts +86 -0
  165. package/lib/typescript/module/local-media.d.ts.map +1 -0
  166. package/lib/typescript/module/native-session.d.ts +38 -0
  167. package/lib/typescript/module/native-session.d.ts.map +1 -0
  168. package/lib/typescript/module/native.d.ts +18 -0
  169. package/lib/typescript/module/native.d.ts.map +1 -0
  170. package/lib/typescript/module/package.json +1 -0
  171. package/lib/typescript/module/permissions.d.ts +30 -0
  172. package/lib/typescript/module/permissions.d.ts.map +1 -0
  173. package/lib/typescript/module/platform/android.d.ts +4 -0
  174. package/lib/typescript/module/platform/android.d.ts.map +1 -0
  175. package/lib/typescript/module/platform/common.d.ts +101 -0
  176. package/lib/typescript/module/platform/common.d.ts.map +1 -0
  177. package/lib/typescript/module/platform/devices.d.ts +42 -0
  178. package/lib/typescript/module/platform/devices.d.ts.map +1 -0
  179. package/lib/typescript/module/platform/index.d.ts +6 -0
  180. package/lib/typescript/module/platform/index.d.ts.map +1 -0
  181. package/lib/typescript/module/platform/ios.d.ts +4 -0
  182. package/lib/typescript/module/platform/ios.d.ts.map +1 -0
  183. package/lib/typescript/module/platform/streams.d.ts +82 -0
  184. package/lib/typescript/module/platform/streams.d.ts.map +1 -0
  185. package/lib/typescript/module/platform/timers.d.ts +19 -0
  186. package/lib/typescript/module/platform/timers.d.ts.map +1 -0
  187. package/lib/typescript/module/platform/visibility.d.ts +11 -0
  188. package/lib/typescript/module/platform/visibility.d.ts.map +1 -0
  189. package/lib/typescript/module/preflight.d.ts +19 -0
  190. package/lib/typescript/module/preflight.d.ts.map +1 -0
  191. package/lib/typescript/module/provider.d.ts +35 -0
  192. package/lib/typescript/module/provider.d.ts.map +1 -0
  193. package/lib/typescript/module/specs/NativeVoltkitRtc.d.ts +157 -0
  194. package/lib/typescript/module/specs/NativeVoltkitRtc.d.ts.map +1 -0
  195. package/package.json +140 -4
  196. package/plugin/build/android.d.ts +36 -0
  197. package/plugin/build/android.js +265 -0
  198. package/plugin/build/index.d.ts +9 -0
  199. package/plugin/build/index.js +54 -0
  200. package/plugin/build/ios.d.ts +4 -0
  201. package/plugin/build/ios.js +43 -0
  202. package/plugin/build/options.d.ts +93 -0
  203. package/plugin/build/options.js +140 -0
  204. package/react-native.config.js +11 -0
  205. package/src/audio.ts +221 -0
  206. package/src/components.tsx +233 -0
  207. package/src/create-client.ts +53 -0
  208. package/src/errors.ts +81 -0
  209. package/src/globals.ts +54 -0
  210. package/src/index.ts +95 -0
  211. package/src/local-media.ts +420 -0
  212. package/src/native-session.tsx +384 -0
  213. package/src/native.ts +84 -0
  214. package/src/permissions.ts +173 -0
  215. package/src/platform/android.ts +128 -0
  216. package/src/platform/common.ts +157 -0
  217. package/src/platform/devices.ts +148 -0
  218. package/src/platform/index.ts +22 -0
  219. package/src/platform/ios.ts +48 -0
  220. package/src/platform/streams.ts +285 -0
  221. package/src/platform/timers.ts +72 -0
  222. package/src/platform/visibility.ts +59 -0
  223. package/src/preflight.ts +60 -0
  224. package/src/provider.tsx +88 -0
  225. package/src/specs/NativeVoltkitRtc.ts +180 -0
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StreamBook = void 0;
7
+ exports.streamBook = streamBook;
8
+ var _globals = require("../globals.js");
9
+ var _errors = require("../errors.js");
10
+ /**
11
+ * Every native MediaStream this package makes, and the order in which streams and tracks are let go.
12
+ *
13
+ * In react-native-webrtc a MediaStream is a native object that holds its tracks. Releasing a stream after one of its
14
+ * tracks was disposed -- a local track released, or a remote one whose peer connection closed -- kills the app:
15
+ * `mediaStreamRemoveTrack` cannot find the track, so it stays in the native stream, and disposing the stream throws
16
+ * `IllegalStateException: MediaStreamTrack has been disposed` on the module's thread (Phase 0 finding 1, seen on a
17
+ * reconnect, a room closing and a plain release in the wrong order). So:
18
+ *
19
+ * - Views (VideoTrack) show a track through a wrapper stream made only here: one per track, shared by every view of it,
20
+ * released (`release(false)`, never the track) when the last view goes.
21
+ * - Before the client closes what receives remote tracks (a consumer, the receive transport, the session) it calls the
22
+ * platform's `detachTracks`: their wrappers are released then, while the peer connection still exists, and no new
23
+ * one is made for them.
24
+ * - `stop(track)` (the platform's stopTrack) releases the track's wrappers and takes it out of every other stream made
25
+ * here before it disposes the track; a capture stream left empty is released too. A stream the app got from
26
+ * getUserMedia through this package can therefore never be left holding a disposed track.
27
+ * - A stream the app gave the client (`client.publish(stream)` with a stream the app captured itself) is the app's: the
28
+ * client stops and releases its tracks but never the stream. Once told of it (`adoptAppStream`), `stop(track)` takes
29
+ * the track out of it too while the track is alive, so the app can still release it afterwards; this package never
30
+ * releases it. @voltkit-rtc/client 0.9.12's publish() and publishScreen({ stream }) call that hook.
31
+ * - A stream that would still be released while holding a disposed track (a remote track already ended, a track
32
+ * released elsewhere) is left alone instead: a small native leak, never a crash. A view wrapper whose track ended
33
+ * before the view let go is left the same way: only the end shows that an app released the track itself.
34
+ */
35
+
36
+ /** What this module needs of a track: react-native-webrtc's MediaStreamTrack, or a test's stand-in. */
37
+
38
+ /** What this module needs of a stream: react-native-webrtc's MediaStream. */
39
+
40
+ /**
41
+ * Why a stream is kept: a capture (getUserMedia, getDisplayMedia), the client's own (createStream), a view, or the
42
+ * app's own that the client publishes (adoptAppStream: tracks taken out of it, never released here).
43
+ */
44
+
45
+ /** One view's hold on a track's wrapper stream. */
46
+
47
+ class StreamBook {
48
+ live = new Set();
49
+ entries = new WeakMap();
50
+ views = new Map();
51
+ /** Local tracks this package disposed (released). */
52
+ disposed = new WeakSet();
53
+ /** Remote tracks whose connection is closing: no new view, their wrappers already released. */
54
+ detached = new WeakSet();
55
+ stopped = new WeakSet();
56
+ screens = new WeakSet();
57
+ /** Streams left unreleased because releasing them would have crashed the app. */
58
+ leaked = 0;
59
+ /** Called after a screen track is stopped and released (react-native-webrtc's MediaProjectionService then stops). */
60
+ onScreenStopped = null;
61
+ constructor(makeStream) {
62
+ this.makeStream = makeStream;
63
+ }
64
+
65
+ /** Keep `stream`, one the platform made (or the app's, `app`), to let go of in the right order. */
66
+ adopt(stream, role) {
67
+ const known = this.entries.get(stream);
68
+ if (known) {
69
+ // The app's stream given again (published once more): watched again.
70
+ if (known.role === 'app' && !known.released) this.live.add(known);
71
+ return;
72
+ }
73
+ const entry = {
74
+ stream,
75
+ role,
76
+ released: false
77
+ };
78
+ this.entries.set(stream, entry);
79
+ this.live.add(entry);
80
+ }
81
+
82
+ /** A stream of these tracks for the client's own use (ClientPlatform.createStream). */
83
+ create(tracks) {
84
+ const stream = this.makeStream(tracks);
85
+ this.adopt(stream, 'client');
86
+ return stream;
87
+ }
88
+
89
+ /** The tracks of `stream` are a screen capture's. */
90
+ markScreen(stream) {
91
+ for (const track of stream.getTracks()) this.screens.add(track);
92
+ }
93
+
94
+ /** Release `stream` without its tracks (ClientPlatform.releaseStream). Again does nothing. */
95
+ release(stream) {
96
+ let entry = this.entries.get(stream);
97
+ if (!entry) {
98
+ // Not one made here: released the same careful way.
99
+ entry = {
100
+ stream,
101
+ role: 'client',
102
+ released: false
103
+ };
104
+ this.entries.set(stream, entry);
105
+ }
106
+ this.releaseEntry(entry);
107
+ }
108
+
109
+ /**
110
+ * Stop and release `track` (ClientPlatform.stopTrack): its view wrappers are released and it leaves every stream
111
+ * kept here first (made here, or the app's adopted), while the native track still exists. Again does nothing. A
112
+ * remote track is only let go of: its connection owns it.
113
+ */
114
+ stop(track) {
115
+ if (this.stopped.has(track)) return;
116
+ this.stopped.add(track);
117
+ this.dropViews(track);
118
+ const safe = !this.unsafe(track);
119
+ for (const entry of [...this.live]) {
120
+ if (entry.role === 'view' || !entry.stream.getTracks().includes(track)) continue;
121
+ // A track the native side can no longer find stays where it is: the stream is then left, never released.
122
+ if (safe) {
123
+ try {
124
+ entry.stream.removeTrack(track);
125
+ } catch (err) {
126
+ (0, _errors.logError)('could not take a track out of a stream', err);
127
+ }
128
+ }
129
+ if (entry.stream.getTracks().length > 0) continue;
130
+ if (entry.role === 'capture') this.releaseEntry(entry);
131
+ // The app's, now empty: nothing in it can crash its release, which is the app's to do.
132
+ else if (entry.role === 'app') this.live.delete(entry);
133
+ }
134
+ if (track.remote) return;
135
+ try {
136
+ track.stop();
137
+ } catch (err) {
138
+ (0, _errors.logError)('could not stop a track', err);
139
+ }
140
+ try {
141
+ track.release?.();
142
+ } catch (err) {
143
+ (0, _errors.logError)('could not release a track', err);
144
+ }
145
+ this.disposed.add(track);
146
+ if (this.screens.has(track)) {
147
+ try {
148
+ this.onScreenStopped?.();
149
+ } catch (err) {
150
+ (0, _errors.logError)('could not stop the screen-share service', err);
151
+ }
152
+ }
153
+ }
154
+
155
+ /**
156
+ * The client is about to close what receives these remote tracks (ClientPlatform.detachTracks): release their
157
+ * wrappers now, while their peer connection still exists, and make no new ones.
158
+ */
159
+ detach(tracks) {
160
+ for (const track of tracks) {
161
+ this.dropViews(track);
162
+ this.detached.add(track);
163
+ }
164
+ }
165
+
166
+ /** A view of `track` (VideoTrack), or null when it cannot be shown: ended, stopped or detached. */
167
+ view(track) {
168
+ if (this.stopped.has(track) || this.detached.has(track) || this.unsafe(track) || track.readyState === 'ended') return null;
169
+ let view = this.views.get(track);
170
+ if (!view) {
171
+ let stream;
172
+ try {
173
+ stream = this.makeStream([track]);
174
+ } catch (err) {
175
+ (0, _errors.logError)('could not make a stream to show a track', err);
176
+ return null;
177
+ }
178
+ const entry = {
179
+ stream,
180
+ role: 'view',
181
+ released: false
182
+ };
183
+ this.entries.set(stream, entry);
184
+ this.live.add(entry);
185
+ view = {
186
+ entry,
187
+ refs: 0,
188
+ ended: new Set()
189
+ };
190
+ this.views.set(track, view);
191
+ }
192
+ view.refs += 1;
193
+ const held = view;
194
+ let done = false;
195
+ return {
196
+ url: held.entry.stream.toURL(),
197
+ onEnd: listener => {
198
+ held.ended.add(listener);
199
+ return () => {
200
+ held.ended.delete(listener);
201
+ };
202
+ },
203
+ release: () => {
204
+ if (done) return;
205
+ done = true;
206
+ held.refs -= 1;
207
+ if (held.refs > 0 || this.views.get(track) !== held) return;
208
+ this.views.delete(track);
209
+ this.releaseEntry(held.entry);
210
+ }
211
+ };
212
+ }
213
+
214
+ /** How many streams made here are not released yet, how many tracks have views, and how many were left unreleased. */
215
+ stats() {
216
+ return {
217
+ live: this.live.size,
218
+ views: this.views.size,
219
+ leaked: this.leaked
220
+ };
221
+ }
222
+
223
+ /** A track the native side may no longer have: disposed here, or remote and ended (its connection closed). */
224
+ unsafe(track) {
225
+ return this.disposed.has(track) || track.remote === true && track.readyState === 'ended';
226
+ }
227
+ dropViews(track) {
228
+ const view = this.views.get(track);
229
+ if (!view) return;
230
+ this.views.delete(track);
231
+ this.releaseEntry(view.entry);
232
+ for (const listener of [...view.ended]) {
233
+ try {
234
+ listener();
235
+ } catch (err) {
236
+ (0, _errors.logError)('listener for viewEnded threw', err);
237
+ }
238
+ }
239
+ }
240
+ releaseEntry(entry) {
241
+ if (entry.released) return;
242
+ entry.released = true;
243
+ this.live.delete(entry);
244
+ // A view's track that ended may have been released outside this package (an app's own stop() and release()),
245
+ // which only its end shows: its wrapper is left too. Views of live tracks are let go while their tracks live.
246
+ const hazard = entry.role === 'view' ? track => this.unsafe(track) || track.readyState === 'ended' : track => this.unsafe(track);
247
+ if (entry.stream.getTracks().some(hazard)) {
248
+ // Released, it would dispose a native stream that still holds a disposed track, and the app would die.
249
+ this.leaked += 1;
250
+ return;
251
+ }
252
+ try {
253
+ entry.stream.release(false);
254
+ } catch (err) {
255
+ (0, _errors.logError)('could not release a media stream', err);
256
+ }
257
+ }
258
+ }
259
+ exports.StreamBook = StreamBook;
260
+ let shared = null;
261
+
262
+ /** The process's book of streams (one for every client and view). */
263
+ function streamBook() {
264
+ if (!shared) {
265
+ shared = new StreamBook(tracks => {
266
+ const webrtc = (0, _globals.loadWebRTC)();
267
+ if (!webrtc) throw (0, _errors.webrtcMissing)();
268
+ return new webrtc.MediaStream(tracks);
269
+ });
270
+ }
271
+ return shared;
272
+ }
273
+ //# sourceMappingURL=streams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_globals","require","_errors","StreamBook","live","Set","entries","WeakMap","views","Map","disposed","WeakSet","detached","stopped","screens","leaked","onScreenStopped","constructor","makeStream","adopt","stream","role","known","get","released","add","entry","set","create","tracks","markScreen","track","getTracks","release","releaseEntry","stop","has","dropViews","safe","unsafe","includes","removeTrack","err","logError","length","delete","remote","detach","view","readyState","refs","ended","held","done","url","toURL","onEnd","listener","stats","size","hazard","some","exports","shared","streamBook","webrtc","loadWebRTC","webrtcMissing","MediaStream"],"sourceRoot":"../../../src","sources":["platform/streams.ts"],"mappings":";;;;;;;AA0BA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AA3BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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ACA,OAAOkC,MAAM;AACf","ignoreList":[]}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.jsTimers = void 0;
7
+ exports.nativeTimers = nativeTimers;
8
+ var _native = require("../native.js");
9
+ var _errors = require("../errors.js");
10
+ /**
11
+ * The timers the client's own work runs on (reconnect backoff, socket liveness, request deadlines, sampling).
12
+ *
13
+ * React Native's JavaScript timers run on Choreographer frames, which stop when the app leaves the foreground, when
14
+ * the screen goes off even with the app in front, and while a permission dialog is open (Phase 0 S5): a call whose
15
+ * timers stop cannot notice a dead socket or reconnect. On Android they wait natively instead (the module's
16
+ * timerStart/timerStop on a thread of their own) and fire back through its onTimer event, which reaches JavaScript
17
+ * whether frames run or not. Without the native module (iOS, Expo Go) they are JavaScript's own.
18
+ */
19
+
20
+ /** JavaScript's own timers, looked up at each call (a test's fake clock replaces them, and is used). */
21
+ const jsTimers = exports.jsTimers = Object.freeze({
22
+ setTimeout: (fn, ms) => setTimeout(fn, ms),
23
+ clearTimeout: handle => clearTimeout(handle),
24
+ setInterval: (fn, ms) => setInterval(fn, ms),
25
+ clearInterval: handle => clearInterval(handle)
26
+ });
27
+ /**
28
+ * Timers that wait natively. Ids are this side's and never reused, so a fire already on its way for a timer stopped
29
+ * since is recognised and ignored. One onTimer subscription for the whole process.
30
+ */
31
+ function nativeTimers(module) {
32
+ const pending = new Map();
33
+ let next = 0;
34
+ let subscribed = false;
35
+ const fire = id => {
36
+ const timer = pending.get(id);
37
+ if (!timer) return;
38
+ if (!timer.repeat) pending.delete(id);
39
+ try {
40
+ timer.fn();
41
+ } catch (err) {
42
+ (0, _errors.logError)('a timer callback threw', err);
43
+ }
44
+ };
45
+ const start = (fn, ms, repeat) => {
46
+ if (!subscribed) {
47
+ subscribed = true;
48
+ (0, _native.listen)(module.onTimer, 'onTimer', fire);
49
+ }
50
+ next += 1;
51
+ const id = next;
52
+ pending.set(id, {
53
+ fn,
54
+ repeat
55
+ });
56
+ const delay = typeof ms === 'number' && Number.isFinite(ms) && ms > 0 ? ms : 0;
57
+ module.timerStart(id, delay, repeat);
58
+ return id;
59
+ };
60
+ const stop = handle => {
61
+ if (typeof handle !== 'number' || !pending.delete(handle)) return;
62
+ module.timerStop(handle);
63
+ };
64
+ return Object.freeze({
65
+ setTimeout: (fn, ms) => start(fn, ms, false),
66
+ clearTimeout: stop,
67
+ setInterval: (fn, ms) => start(fn, ms, true),
68
+ clearInterval: stop
69
+ });
70
+ }
71
+ //# sourceMappingURL=timers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_native","require","_errors","jsTimers","exports","Object","freeze","setTimeout","fn","ms","clearTimeout","handle","setInterval","clearInterval","nativeTimers","module","pending","Map","next","subscribed","fire","id","timer","get","repeat","delete","err","logError","start","listen","onTimer","set","delay","Number","isFinite","timerStart","stop","timerStop"],"sourceRoot":"../../../src","sources":["platform/timers.ts"],"mappings":";;;;;;;AAWA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACO,MAAME,QAAwB,GAAAC,OAAA,CAAAD,QAAA,GAAGE,MAAM,CAACC,MAAM,CAAC;EACpDC,UAAU,EAAEA,CAACC,EAAc,EAAEC,EAAU,KAAcF,UAAU,CAACC,EAAE,EAAEC,EAAE,CAAC;EACvEC,YAAY,EAAGC,MAAe,IAAWD,YAAY,CAACC,MAAuC,CAAC;EAC9FC,WAAW,EAAEA,CAACJ,EAAc,EAAEC,EAAU,KAAcG,WAAW,CAACJ,EAAE,EAAEC,EAAE,CAAC;EACzEI,aAAa,EAAGF,MAAe,IAAWE,aAAa,CAACF,MAAwC;AAClG,CAAC,CAAC;AAOF;AACA;AACA;AACA;AACO,SAASG,YAAYA,CAACC,MAAY,EAAkB;EACzD,MAAMC,OAAO,GAAG,IAAIC,GAAG,CAAkB,CAAC;EAC1C,IAAIC,I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AAM,CAAC;IACnBC,UAAU,EAAEA,CAACC,EAAc,EAAEC,EAAU,KAAcmB,KAAK,CAACpB,EAAE,EAAEC,EAAE,EAAE,KAAK,CAAC;IACzEC,YAAY,EAAE0B,IAAI;IAClBxB,WAAW,EAAEA,CAACJ,EAAc,EAAEC,EAAU,KAAcmB,KAAK,CAACpB,EAAE,EAAEC,EAAE,EAAE,IAAI,CAAC;IACzEI,aAAa,EAAEuB;EACjB,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.appStateVisibility = appStateVisibility;
7
+ exports.nativeVisibility = nativeVisibility;
8
+ var _reactNative = require("react-native");
9
+ var _native = require("../native.js");
10
+ var _errors = require("../errors.js");
11
+ /**
12
+ * Whether the app can be seen, for the background pause, adaptive stream and the call service.
13
+ *
14
+ * Android: from the process lifecycle (the native module's isAppVisible / onAppVisibilityChanged, ProcessLifecycleOwner):
15
+ * the app is visible while any of its activities is started. React Native's AppState is not used there: it says
16
+ * `background` while a permission dialog or the screen-share consent is open over the app (Phase 0 S8), which would
17
+ * pause the camera for a dialog.
18
+ *
19
+ * iOS (preview) and Android without the native module: AppState, with `inactive` (a call banner, the app switcher
20
+ * opening) counted as visible.
21
+ */
22
+
23
+ const shown = state => state !== 'background';
24
+
25
+ /** From the process lifecycle (Android). */
26
+ function nativeVisibility(module) {
27
+ return {
28
+ visible: () => {
29
+ try {
30
+ return module.isAppVisible();
31
+ } catch (err) {
32
+ (0, _errors.logError)('could not read the app\'s visibility', err);
33
+ return true;
34
+ }
35
+ },
36
+ subscribe: listener => (0, _native.listen)(module.onAppVisibilityChanged, 'onAppVisibilityChanged', e => listener(e.visible))
37
+ };
38
+ }
39
+
40
+ /** From AppState: `active` and `inactive` are visible, `background` is not. */
41
+ function appStateVisibility() {
42
+ return {
43
+ visible: () => shown(_reactNative.AppState.currentState),
44
+ subscribe: listener => {
45
+ let last = shown(_reactNative.AppState.currentState);
46
+ const subscription = _reactNative.AppState.addEventListener('change', state => {
47
+ const now = shown(state);
48
+ if (now === last) return;
49
+ last = now;
50
+ try {
51
+ listener(now);
52
+ } catch (err) {
53
+ (0, _errors.logError)('listener for appVisibility threw', err);
54
+ }
55
+ });
56
+ return () => subscription?.remove();
57
+ }
58
+ };
59
+ }
60
+ //# sourceMappingURL=visibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_native","_errors","shown","state","nativeVisibility","module","visible","isAppVisible","err","logError","subscribe","listener","listen","onAppVisibilityChanged","e","appStateVisibility","AppState","currentState","last","subscription","addEventListener","now","remove"],"sourceRoot":"../../../src","sources":["platform/visibility.ts"],"mappings":";;;;;;;AAWA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAdA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,MAAMG,KAAK,GAAIC,KAAiD,IAAcA,KAAK,KAAK,YAAY;;AAEpG;AACO,SAASC,gBAAgBA,CAACC,MAAY,EAAc;EACzD,OAAO;IACLC,OAAO,EAAEA,CAAA,KAAM;MACb,IAAI;QACF,OAAOD,MAAM,CAACE,YAAY,CAAC,CAAC;MAC9B,CAAC,CAAC,OAAOC,GAAG,EAAE;QACZ,IAAAC,gBAAQ,EAAC,sCAAsC,EAAED,GAAG,CAAC;QACrD,OAAO,IAAI;MACb;IACF,CAAC;IACDE,SAAS,EAAGC,QAAQ,IAAK,IAAAC,cAAM,EAACP,MAAM,CAACQ,sBAAsB,EAAE,wBAAwB,EAAGC,CAAC,IAAKH,QAAQ,CAACG,CAAC,CAACR,OAAO,CAAC;EACrH,CAAC;AACH;;AAEA;AACO,SAASS,kBAAkBA,CAAA,EAAe;EAC/C,OAAO;IACLT,OAAO,EAAEA,CAAA,KAAMJ,KAAK,CAACc,qBAAQ,CAACC,YAAY,CAAC;IAC3CP,SAAS,EAAGC,QAAQ,IAAK;MACvB,IAAIO,IAAI,GAAGhB,KAAK,CAACc,qBAAQ,CAACC,YAAY,CAAC;MACvC,MAAME,YAAY,GAAGH,qBAAQ,CAACI,gBAAgB,CAAC,QAAQ,EAAGjB,KAAK,IAAK;QAClE,MAAMkB,GAAG,GAAGnB,KAAK,CAACC,KAAK,CAAC;QACxB,IAAIkB,GAAG,KAAKH,IAAI,EAAE;QAClBA,IAAI,GAAGG,GAAG;QACV,IAAI;UACFV,QAAQ,CAACU,GAAG,CAAC;QACf,CAAC,CAAC,OAAOb,GAAG,EAAE;UACZ,IAAAC,gBAAQ,EAAC,kCAAkC,EAAED,GAAG,CAAC;QACnD;MACF,CAAC,CAAC;MACF,OAAO,MAAMW,YAAY,EAAEG,MAAM,CAAC,CAAC;IACrC;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.preflight = preflight;
7
+ var _client = require("@voltkit-rtc/client");
8
+ var _globals = require("./globals.js");
9
+ var _errors = require("./errors.js");
10
+ var _createClient = require("./create-client.js");
11
+ /**
12
+ * The pre-call check on React Native: @voltkit-rtc/client's preflight with this package's platform. It joins the room
13
+ * the token names, publishes for a few seconds, measures and leaves, and never rejects: offline, a refused permission,
14
+ * a bad token or a missing native module all give a report whose steps say what failed.
15
+ *
16
+ * React Native cannot make a test tone or picture. Without `options.media` the check publishes the microphone, which
17
+ * it captures itself once joined (so nothing opens the microphone for a join that fails) and releases at the end. It
18
+ * never asks for the permission: where it is not granted, the join is still tested and the media step says why.
19
+ * Android shows its microphone indicator for those seconds.
20
+ */
21
+
22
+ /** A report for a check that could not even start. */
23
+ function failed(error) {
24
+ return {
25
+ ok: false,
26
+ steps: [{
27
+ name: 'join',
28
+ ok: false,
29
+ ms: null,
30
+ error: (0, _errors.describeError)(error)
31
+ }],
32
+ path: null,
33
+ rttMs: null,
34
+ lossPct: null,
35
+ uploadKbps: null,
36
+ level: null,
37
+ warnings: []
38
+ };
39
+ }
40
+
41
+ /**
42
+ * What the client's check reads from `options.media` on a platform that cannot copy tracks: which devices to capture
43
+ * again once joined (it never publishes the app's own tracks, which its close would stop). One microphone, the default
44
+ * one, and no camera; nothing native behind it.
45
+ */
46
+ const MICROPHONE_TRACK = Object.freeze({
47
+ kind: 'audio',
48
+ getSettings: () => ({})
49
+ });
50
+ const MICROPHONE_FOR_TEST = Object.freeze({
51
+ getTracks: () => [MICROPHONE_TRACK],
52
+ getAudioTracks: () => [MICROPHONE_TRACK],
53
+ getVideoTracks: () => []
54
+ });
55
+
56
+ /** Test the connection and the media path before a call. Never rejects. */
57
+ async function preflight(wsUrl, token, options = {}) {
58
+ if (!(0, _globals.registerVoltkitGlobals)()) return failed((0, _errors.webrtcMissing)());
59
+ const {
60
+ background,
61
+ clientOptions,
62
+ ...rest
63
+ } = options;
64
+ try {
65
+ return await _client.StreamClient.preflight(wsUrl, token, {
66
+ ...rest,
67
+ media: rest.media ?? MICROPHONE_FOR_TEST,
68
+ clientOptions: (0, _createClient.reactNativeClientOptions)({
69
+ background,
70
+ clientOptions
71
+ })
72
+ });
73
+ } catch (err) {
74
+ return failed(err);
75
+ }
76
+ }
77
+ //# sourceMappingURL=preflight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_client","require","_globals","_errors","_createClient","failed","error","ok","steps","name","ms","describeError","path","rttMs","lossPct","uploadKbps","level","warnings","MICROPHONE_TRACK","Object","freeze","kind","getSettings","MICROPHONE_FOR_TEST","getTracks","getAudioTracks","getVideoTracks","preflight","wsUrl","token","options","registerVoltkitGlobals","webrtcMissing","background","clientOptions","rest","StreamClient","media","reactNativeClientOptions","err"],"sourceRoot":"../../src","sources":["preflight.ts"],"mappings":";;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,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I;MACPE,KAAK,EAAEF,IAAI,CAACE,KAAK,IAAKd,mBAA4D;MAClFW,aAAa,EAAE,IAAAI,sCAAwB,EAAC;QAAEL,UAAU;QAAEC;MAAc,CAAC;IACvE,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOK,GAAG,EAAE;IACZ,OAAOlC,MAAM,CAACkC,GAAG,CAAC;EACpB;AACF","ignoreList":[]}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VoltkitProvider = VoltkitProvider;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _react2 = require("@voltkit-rtc/react");
10
+ var _globals = require("./globals.js");
11
+ var _native = require("./native.js");
12
+ var _errors = require("./errors.js");
13
+ var _createClient = require("./create-client.js");
14
+ var _nativeSession = require("./native-session.js");
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ /**
17
+ * VoltkitProvider for React Native: @voltkit-rtc/react's provider (the same props, token hand-over and StrictMode
18
+ * behaviour, so every re-exported hook works below it) making its client with this package's platform, plus what a call
19
+ * needs from the device: the call audio, the call service and the background pause.
20
+ *
21
+ * In Expo Go, or an app not rebuilt after installing react-native-webrtc, no client is made: onError gets
22
+ * `media-unavailable` with `{ reason: 'webrtc-missing' }` (it needs a development build) and the hooks keep their
23
+ * defaults. Nothing throws.
24
+ */
25
+
26
+ /** One StreamClient for the components below, with the device's audio, the call service and the background pause. */
27
+ function VoltkitProvider({
28
+ audio,
29
+ background,
30
+ callService,
31
+ clientOptions,
32
+ client,
33
+ wsUrl,
34
+ token,
35
+ onError,
36
+ children,
37
+ ...rest
38
+ }) {
39
+ const webrtc = (0, _react.useMemo)(() => (0, _globals.registerVoltkitGlobals)(), []);
40
+ const errors = (0, _react.useRef)(onError);
41
+ (0, _react.useEffect)(() => {
42
+ errors.current = onError;
43
+ });
44
+ const wanted = Boolean(client || wsUrl && token);
45
+ (0, _react.useEffect)(() => {
46
+ if (!wanted) return;
47
+ if (!webrtc) errors.current?.((0, _errors.webrtcMissing)());else if (_reactNative.Platform.OS === 'android' && !(0, _native.nativeModule)()) errors.current?.((0, _errors.nativeMissing)('Background calls, audio routing and native timers'));
48
+ }, [webrtc, wanted]);
49
+
50
+ // Read when the provider makes a client, as @voltkit-rtc/react reads clientOptions: a later change does not remake it.
51
+ const options = (0, _react.useMemo)(() => webrtc ? (0, _createClient.reactNativeClientOptions)({
52
+ background,
53
+ clientOptions
54
+ }) : undefined,
55
+ // eslint-disable-next-line react-hooks/exhaustive-deps
56
+ [webrtc, wsUrl, token]);
57
+ // The call service reads the setting from the client it runs for (an app-made client has its own); this stands in
58
+ // when the client's options cannot be read.
59
+ const pauseCamera = options?.pauseCameraInBackground === true;
60
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react2.VoltkitProvider, {
61
+ ...rest,
62
+ wsUrl: webrtc ? wsUrl : undefined,
63
+ token: webrtc ? token : undefined,
64
+ client: webrtc ? client : null,
65
+ clientOptions: options,
66
+ onError: onError,
67
+ children: [webrtc ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_nativeSession.NativeSession, {
68
+ audio: audio,
69
+ callService: callService,
70
+ pauseCamera: pauseCamera,
71
+ onError: errors
72
+ }) : null, children]
73
+ });
74
+ }
75
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_react2","_globals","_native","_errors","_createClient","_nativeSession","_jsxRuntime","VoltkitProvider","audio","background","callService","clientOptions","client","wsUrl","token","onError","children","rest","webrtc","useMemo","registerVoltkitGlobals","errors","useRef","useEffect","current","wanted","Boolean","webrtcMissing","Platform","OS","nativeModule","nativeMissing","options","reactNativeClientOptions","undefined","pauseCamera","pauseCameraInBackground","jsxs","jsx","NativeSession"],"sourceRoot":"../../src","sources":["provider.tsx"],"mappings":";;;;;;AASA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE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AAEE;EAAc,CAAC,CAAC,GAAGuB,SAAU;EACpF;EACA,CAAChB,MAAM,EAAEL,KAAK,EAAEC,KAAK,CACvB,CAAC;EACD;EACA;EACA,MAAMqB,WAAW,GAAGH,OAAO,EAAEI,uBAAuB,KAAK,IAAI;EAE7D,oBACE,IAAA9B,WAAA,CAAA+B,IAAA,EAACrC,OAAA,CAAAO,eAAoB;IAAA,GACfU,IAAI;IACRJ,KAAK,EAAEK,MAAM,GAAGL,KAAK,GAAGqB,SAAU;IAClCpB,KAAK,EAAEI,MAAM,GAAGJ,KAAK,GAAGoB,SAAU;IAClCtB,MAAM,EAAEM,MAAM,GAAGN,MAAM,GAAG,IAAK;IAC/BD,aAAa,EAAEqB,OAAQ;IACvBjB,OAAO,EAAEA,OAAQ;IAAAC,QAAA,GAEhBE,MAAM,gBAAG,IAAAZ,WAAA,CAAAgC,GAAA,EAACjC,cAAA,CAAAkC,aAAa;MAAC/B,KAAK,EAAEA,KAAM;MAACE,WAAW,EAAEA,WAAY;MAACyB,WAAW,EAAEA,WAAY;MAACpB,OAAO,EAAEM;IAAO,CAAE,CAAC,GAAG,IAAI,EACpHL,QAAQ;EAAA,CACW,CAAC;AAE3B","ignoreList":[]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactNative = require("react-native");
8
+ /**
9
+ * The native side of @voltkit-rtc/react-native on Android, as one codegen TurboModule (plan §5.1): audio routing
10
+ * (ported from the Android SDK's AudioRouter), the call service, native timers, app visibility from the process
11
+ * lifecycle, the network, and stopping react-native-webrtc's screen-share service. iOS has no native module in 0.1.0.
12
+ *
13
+ * Read it through src/native.ts, never directly: this module is null in Expo Go, on iOS and wherever the app was not
14
+ * rebuilt after installing the package, and native.ts turns that into a typed error.
15
+ *
16
+ * Strings that hold one of a few values are typed `string` here, as codegen needs; the values are listed beside each.
17
+ */
18
+ /** An audio input or output, as the Android SDK lists it (`MediaDevice`). */
19
+ /** Devices came or went while a client held the audio (a headset plugged in, Bluetooth connected). */
20
+ /** Where call audio plays now; null once the last client let the audio go. */
21
+ /** Audio focus, while a client holds the audio: `gain` | `loss` | `lossTransient` | `lossTransientCanDuck`. */
22
+ /** The audio device module could not open or keep the microphone. */
23
+ /** The app went to the foreground (any activity started) or the background, from ProcessLifecycleOwner. */
24
+ /** The network came back (`handover` false) or the default network changed, say Wi-Fi to mobile data (true). */
25
+ /** What the call service shows and the call it runs for: its foreground service types are worked out from these. */
26
+ /** The call service: whether the app declares it, and whether it runs, with which foreground service types. */
27
+ /** `started` | `updated` | `stopped` | `leave` (the notification's action) | `taskRemoved` | `failed`. */
28
+ var _default = exports.default = _reactNative.TurboModuleRegistry.get('VoltkitRtc');
29
+ //# sourceMappingURL=NativeVoltkitRtc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","get"],"sourceRoot":"../../../src","sources":["specs/NativeVoltkitRtc.ts"],"mappings":";;;;;;AAWA,IAAAA,YAAA,GAAAC,OAAA;AAXA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AAcA;AAOA;AAKA;AAKA;AAKA;AAKA;AAKA;AAeA;AAQA;AAAA,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAiGeC,gCAAmB,CAACC,GAAG,CAAO,YAAY,CAAC","ignoreList":[]}