livevoice-sdk-react-native 2.0.0 → 3.0.0

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 (221) hide show
  1. package/README.md +158 -7
  2. package/android/build.gradle +18 -6
  3. package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +121 -221
  4. package/android/src/main/java/io/livevoice/react/__SDK.kt +17 -3
  5. package/ios/LiveVoiceRNBridge.swift +362 -0
  6. package/ios/LiveVoiceSdkReactNative.mm +247 -145
  7. package/ios/__SDK.h +16 -2
  8. package/ios/livevoice_spm_backport.rb +202 -0
  9. package/lib/module/components/BrandingView.js +71 -50
  10. package/lib/module/components/BrandingView.js.map +1 -1
  11. package/lib/module/components/ChannelView.js +368 -54
  12. package/lib/module/components/ChannelView.js.map +1 -1
  13. package/lib/module/components/ErrorView.js +17 -16
  14. package/lib/module/components/ErrorView.js.map +1 -1
  15. package/lib/module/components/LiveVoiceSpinner.js +81 -0
  16. package/lib/module/components/LiveVoiceSpinner.js.map +1 -0
  17. package/lib/module/components/LiveVoiceView.js +351 -104
  18. package/lib/module/components/LiveVoiceView.js.map +1 -1
  19. package/lib/module/components/PasswordPrompt.js +165 -0
  20. package/lib/module/components/PasswordPrompt.js.map +1 -0
  21. package/lib/module/components/PlayButtonView.js +192 -254
  22. package/lib/module/components/PlayButtonView.js.map +1 -1
  23. package/lib/module/components/ReconnectingView.js +43 -62
  24. package/lib/module/components/ReconnectingView.js.map +1 -1
  25. package/lib/module/components/WarningView.js +12 -10
  26. package/lib/module/components/WarningView.js.map +1 -1
  27. package/lib/module/icons/branding-ios.png +0 -0
  28. package/lib/module/icons/camera-off-android.png +0 -0
  29. package/lib/module/icons/camera-off-android@2x.png +0 -0
  30. package/lib/module/icons/camera-off-android@3x.png +0 -0
  31. package/lib/module/icons/cpu-android.png +0 -0
  32. package/lib/module/icons/cpu-android@2x.png +0 -0
  33. package/lib/module/icons/cpu-android@3x.png +0 -0
  34. package/lib/module/icons/cpu-ios.png +0 -0
  35. package/lib/module/icons/cpu-ios@2x.png +0 -0
  36. package/lib/module/icons/cpu-ios@3x.png +0 -0
  37. package/lib/module/icons/lock-android.png +0 -0
  38. package/lib/module/icons/lock-android@2x.png +0 -0
  39. package/lib/module/icons/lock-android@3x.png +0 -0
  40. package/lib/module/icons/lock-ios.png +0 -0
  41. package/lib/module/icons/lock-ios@2x.png +0 -0
  42. package/lib/module/icons/lock-ios@3x.png +0 -0
  43. package/lib/module/icons/mic-off-android.png +0 -0
  44. package/lib/module/icons/mic-off-android@2x.png +0 -0
  45. package/lib/module/icons/mic-off-android@3x.png +0 -0
  46. package/lib/module/icons/mic-slash-ios.png +0 -0
  47. package/lib/module/icons/mic-slash-ios@2x.png +0 -0
  48. package/lib/module/icons/mic-slash-ios@3x.png +0 -0
  49. package/lib/module/icons/video-slash-ios.png +0 -0
  50. package/lib/module/icons/video-slash-ios@2x.png +0 -0
  51. package/lib/module/icons/video-slash-ios@3x.png +0 -0
  52. package/lib/module/index.js +24 -225
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/sdk/Bridge.js +236 -0
  55. package/lib/module/sdk/Bridge.js.map +1 -0
  56. package/lib/module/sdk/Event.js +160 -0
  57. package/lib/module/sdk/Event.js.map +1 -0
  58. package/lib/module/sdk/Lifecycle.js +331 -0
  59. package/lib/module/sdk/Lifecycle.js.map +1 -0
  60. package/lib/module/sdk/LiveVoiceSdk.js +365 -0
  61. package/lib/module/sdk/LiveVoiceSdk.js.map +1 -0
  62. package/lib/module/sdk/LiveVoiceState.js +234 -0
  63. package/lib/module/sdk/LiveVoiceState.js.map +1 -0
  64. package/lib/module/sdk/LogEntries.js +99 -0
  65. package/lib/module/sdk/LogEntries.js.map +1 -0
  66. package/lib/module/sdk/Models.js +2 -0
  67. package/lib/module/{util/UIState.js.map → sdk/Models.js.map} +1 -1
  68. package/lib/module/sdk/NativeSdkVersions.js +24 -0
  69. package/lib/module/sdk/NativeSdkVersions.js.map +1 -0
  70. package/lib/module/sdk/Observables.js +391 -0
  71. package/lib/module/sdk/Observables.js.map +1 -0
  72. package/lib/module/sdk/Passwords.js +298 -0
  73. package/lib/module/sdk/Passwords.js.map +1 -0
  74. package/lib/module/sdk/Playback.js +35 -0
  75. package/lib/module/sdk/Playback.js.map +1 -0
  76. package/lib/module/specs/NativeLiveVoiceSdk.js +12 -10
  77. package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
  78. package/lib/module/util/Colors.js +14 -11
  79. package/lib/module/util/Colors.js.map +1 -1
  80. package/lib/module/util/Translations.js +46 -21
  81. package/lib/module/util/Translations.js.map +1 -1
  82. package/lib/module/util/freeze.js +26 -0
  83. package/lib/module/util/freeze.js.map +1 -0
  84. package/lib/module/util/logger.js +114 -0
  85. package/lib/module/util/logger.js.map +1 -0
  86. package/lib/typescript/src/components/BrandingView.d.ts +4 -0
  87. package/lib/typescript/src/components/BrandingView.d.ts.map +1 -1
  88. package/lib/typescript/src/components/ChannelView.d.ts +29 -3
  89. package/lib/typescript/src/components/ChannelView.d.ts.map +1 -1
  90. package/lib/typescript/src/components/ErrorView.d.ts +5 -3
  91. package/lib/typescript/src/components/ErrorView.d.ts.map +1 -1
  92. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts +16 -0
  93. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts.map +1 -0
  94. package/lib/typescript/src/components/LiveVoiceView.d.ts +85 -3
  95. package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -1
  96. package/lib/typescript/src/components/PasswordPrompt.d.ts +13 -0
  97. package/lib/typescript/src/components/PasswordPrompt.d.ts.map +1 -0
  98. package/lib/typescript/src/components/PlayButtonView.d.ts +12 -329
  99. package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -1
  100. package/lib/typescript/src/components/ReconnectingView.d.ts +6 -3
  101. package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -1
  102. package/lib/typescript/src/components/WarningView.d.ts.map +1 -1
  103. package/lib/typescript/src/index.d.ts +15 -144
  104. package/lib/typescript/src/index.d.ts.map +1 -1
  105. package/lib/typescript/src/sdk/Bridge.d.ts +36 -0
  106. package/lib/typescript/src/sdk/Bridge.d.ts.map +1 -0
  107. package/lib/typescript/src/sdk/Event.d.ts +97 -0
  108. package/lib/typescript/src/sdk/Event.d.ts.map +1 -0
  109. package/lib/typescript/src/sdk/Lifecycle.d.ts +191 -0
  110. package/lib/typescript/src/sdk/Lifecycle.d.ts.map +1 -0
  111. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts +215 -0
  112. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -0
  113. package/lib/typescript/src/sdk/LiveVoiceState.d.ts +80 -0
  114. package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -0
  115. package/lib/typescript/src/sdk/LogEntries.d.ts +28 -0
  116. package/lib/typescript/src/sdk/LogEntries.d.ts.map +1 -0
  117. package/lib/typescript/src/sdk/Models.d.ts +114 -0
  118. package/lib/typescript/src/sdk/Models.d.ts.map +1 -0
  119. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts +6 -0
  120. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts.map +1 -0
  121. package/lib/typescript/src/sdk/Observables.d.ts +123 -0
  122. package/lib/typescript/src/sdk/Observables.d.ts.map +1 -0
  123. package/lib/typescript/src/sdk/Passwords.d.ts +72 -0
  124. package/lib/typescript/src/sdk/Passwords.d.ts.map +1 -0
  125. package/lib/typescript/src/sdk/Playback.d.ts +9 -0
  126. package/lib/typescript/src/sdk/Playback.d.ts.map +1 -0
  127. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts +35 -29
  128. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -1
  129. package/lib/typescript/src/util/Colors.d.ts.map +1 -1
  130. package/lib/typescript/src/util/Translations.d.ts +30 -8
  131. package/lib/typescript/src/util/Translations.d.ts.map +1 -1
  132. package/lib/typescript/src/util/freeze.d.ts +6 -0
  133. package/lib/typescript/src/util/freeze.d.ts.map +1 -0
  134. package/lib/typescript/src/util/logger.d.ts +33 -0
  135. package/lib/typescript/src/util/logger.d.ts.map +1 -0
  136. package/livevoice-sdk-react-native.podspec +41 -16
  137. package/package.json +26 -14
  138. package/src/components/BrandingView.tsx +55 -66
  139. package/src/components/ChannelView.tsx +342 -48
  140. package/src/components/ErrorView.tsx +21 -22
  141. package/src/components/LiveVoiceSpinner.tsx +87 -0
  142. package/src/components/LiveVoiceView.tsx +360 -151
  143. package/src/components/PasswordPrompt.tsx +144 -0
  144. package/src/components/PlayButtonView.tsx +177 -279
  145. package/src/components/ReconnectingView.tsx +40 -86
  146. package/src/components/WarningView.tsx +12 -10
  147. package/src/icons/branding-ios.png +0 -0
  148. package/src/icons/camera-off-android.png +0 -0
  149. package/src/icons/camera-off-android@2x.png +0 -0
  150. package/src/icons/camera-off-android@3x.png +0 -0
  151. package/src/icons/cpu-android.png +0 -0
  152. package/src/icons/cpu-android@2x.png +0 -0
  153. package/src/icons/cpu-android@3x.png +0 -0
  154. package/src/icons/cpu-ios.png +0 -0
  155. package/src/icons/cpu-ios@2x.png +0 -0
  156. package/src/icons/cpu-ios@3x.png +0 -0
  157. package/src/icons/lock-android.png +0 -0
  158. package/src/icons/lock-android@2x.png +0 -0
  159. package/src/icons/lock-android@3x.png +0 -0
  160. package/src/icons/lock-ios.png +0 -0
  161. package/src/icons/lock-ios@2x.png +0 -0
  162. package/src/icons/lock-ios@3x.png +0 -0
  163. package/src/icons/mic-off-android.png +0 -0
  164. package/src/icons/mic-off-android@2x.png +0 -0
  165. package/src/icons/mic-off-android@3x.png +0 -0
  166. package/src/icons/mic-slash-ios.png +0 -0
  167. package/src/icons/mic-slash-ios@2x.png +0 -0
  168. package/src/icons/mic-slash-ios@3x.png +0 -0
  169. package/src/icons/video-slash-ios.png +0 -0
  170. package/src/icons/video-slash-ios@2x.png +0 -0
  171. package/src/icons/video-slash-ios@3x.png +0 -0
  172. package/src/index.tsx +105 -252
  173. package/src/sdk/Bridge.ts +259 -0
  174. package/src/sdk/Event.ts +187 -0
  175. package/src/sdk/Lifecycle.ts +366 -0
  176. package/src/sdk/LiveVoiceSdk.ts +384 -0
  177. package/src/sdk/LiveVoiceState.ts +259 -0
  178. package/src/sdk/LogEntries.ts +88 -0
  179. package/src/sdk/Models.ts +129 -0
  180. package/src/sdk/NativeSdkVersions.ts +21 -0
  181. package/src/sdk/Observables.ts +414 -0
  182. package/src/sdk/Passwords.ts +286 -0
  183. package/src/sdk/Playback.ts +30 -0
  184. package/src/specs/NativeLiveVoiceSdk.ts +56 -46
  185. package/src/util/Colors.ts +14 -11
  186. package/src/util/Translations.ts +46 -22
  187. package/src/util/freeze.ts +23 -0
  188. package/src/util/logger.ts +119 -0
  189. package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeLiveVoiceSdkSpec.java +0 -186
  190. package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +0 -28
  191. package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec-generated.cpp +0 -235
  192. package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec.h +0 -31
  193. package/android/app/build/generated/source/codegen/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI.h +0 -341
  194. package/android/src/main/java/io/livevoice/react/Mappings.kt +0 -85
  195. package/android/src/main/java/io/livevoice/react/NativeModels.kt +0 -79
  196. package/lib/module/components/AudioOutputSwitchView.js +0 -138
  197. package/lib/module/components/AudioOutputSwitchView.js.map +0 -1
  198. package/lib/module/components/index.js +0 -22
  199. package/lib/module/components/index.js.map +0 -1
  200. package/lib/module/icons/mic.png +0 -0
  201. package/lib/module/util/ForegroundServiceConfig.js +0 -28
  202. package/lib/module/util/ForegroundServiceConfig.js.map +0 -1
  203. package/lib/module/util/PlayingState.js +0 -21
  204. package/lib/module/util/PlayingState.js.map +0 -1
  205. package/lib/module/util/UIState.js +0 -4
  206. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts +0 -6
  207. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +0 -1
  208. package/lib/typescript/src/components/index.d.ts +0 -9
  209. package/lib/typescript/src/components/index.d.ts.map +0 -1
  210. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +0 -12
  211. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +0 -1
  212. package/lib/typescript/src/util/PlayingState.d.ts +0 -7
  213. package/lib/typescript/src/util/PlayingState.d.ts.map +0 -1
  214. package/lib/typescript/src/util/UIState.d.ts +0 -66
  215. package/lib/typescript/src/util/UIState.d.ts.map +0 -1
  216. package/src/components/AudioOutputSwitchView.tsx +0 -146
  217. package/src/components/index.tsx +0 -19
  218. package/src/icons/mic.png +0 -0
  219. package/src/util/ForegroundServiceConfig.tsx +0 -32
  220. package/src/util/PlayingState.ts +0 -18
  221. package/src/util/UIState.ts +0 -89
@@ -0,0 +1,331 @@
1
+ "use strict";
2
+
3
+ //===----------------------------------------------------------------------===//
4
+ //
5
+ // This source file is part of the LiveVoice SDK project
6
+ //
7
+ // Copyright (c) LiveVoice GmbH
8
+ // Licensed under the MIT license
9
+ //
10
+ // See LICENSE for license information
11
+ //
12
+ // SPDX-License-Identifier: MIT
13
+ //
14
+ //===----------------------------------------------------------------------===//
15
+
16
+ import Native from "../specs/NativeLiveVoiceSdk.js";
17
+ import { logDecodeError, logInfo, LiveVoiceLogEvent, writeLogEntry } from "../util/logger.js";
18
+ import { awaitRevisions, errorMessage, isInitialized, record as object } from "./Bridge.js";
19
+
20
+ /** Every {@link LiveVoiceErrorCode}, for example to check a value at runtime. */
21
+ export const liveVoiceErrorCodes = ['not_initialized', 'not_joined', 'invalid_argument', 'superseded', 'cancelled', 'timed_out', 'leave_incomplete', 'command_in_progress', 'api_key_invalid', 'event_not_found', 'event_inactive', 'wrong_password', 'listener_limit_reached', 'network_failed', 'no_network', 'generic', 'password_required', 'unsupported_sdk', 'channel_password_required', 'channel_wrong_password', 'channel_limit_reached', 'channel_unavailable', 'channel_forbidden', 'channel_offline'];
22
+
23
+ /**
24
+ * What went wrong, the same codes on every platform. Each call names the codes specific to it.
25
+ *
26
+ * Commands:
27
+ * - `not_initialized`: a call that needs `initialize()` was made before it resolved. Reading
28
+ * values, adding listeners and some setters work before it.
29
+ * - `invalid_argument`: an argument is malformed, or not allowed in the current state.
30
+ * - `not_joined`: the connection is not in a state the call allows; most calls need `ready`.
31
+ * - `superseded`: a newer call replaced a `joinEvent`, `reconnect` or `switchToLinkedEvent`. No
32
+ * other call fails with it.
33
+ * - `cancelled`: a leave, a newer command or a new join ended the call. Like `superseded` it
34
+ * needs no message to the user.
35
+ * - `timed_out`: no result within 30 seconds (join, switch, reconnect) or 10 seconds (a start or
36
+ * stop of playback, a subtitle start, the language calls).
37
+ * - `leave_incomplete`: local cleanup or an earlier stop has not finished within its deadline of
38
+ * 5 seconds. It comes from a leave (the event is left all the same), from a stop of playback
39
+ * while joining or failed, and from a start waiting behind an unfinished stop, which can be a
40
+ * stop in the current event. The cleanup is never abandoned; it continues.
41
+ * - `command_in_progress`: the same command is still running: an identical subtitle start, or
42
+ * the request a cancellation is meant to withdraw.
43
+ *
44
+ * Joining: `api_key_invalid` (also when the key does not permit custom UI, for a custom cell,
45
+ * `switchToLinkedEvent` and the language calls), `event_not_found`, `event_inactive`,
46
+ * `password_required` (no password was given), `wrong_password` (one was given and rejected),
47
+ * `listener_limit_reached`, `network_failed` (the connection failed or was lost, also before a
48
+ * call could reach the server), `no_network`, `unsupported_sdk` (the server requires a newer SDK,
49
+ * or the installed native SDK is not the version this package was built for), `generic` (see
50
+ * `detail.reason`).
51
+ *
52
+ * Channels and subtitles: `channel_password_required`, `channel_wrong_password`,
53
+ * `channel_limit_reached` (`detail.limitReason` is `participant` or `viewer`), `channel_offline`
54
+ * (a start of playback only; an offline channel's subtitles can be started),
55
+ * `channel_unavailable` (not part of the event, without audio, or a start of playback while
56
+ * reconnecting), `channel_forbidden`.
57
+ */
58
+
59
+ /** Optional details of an error. */
60
+
61
+ /** The codes worth trying again: the cause can go away by itself or with the user's help. */
62
+ const retryableCodes = new Set(['timed_out', 'event_inactive', 'wrong_password', 'password_required', 'listener_limit_reached', 'network_failed', 'no_network', 'channel_password_required', 'channel_wrong_password', 'channel_limit_reached', 'channel_offline']);
63
+ function knownCode(value) {
64
+ return typeof value === 'string' && liveVoiceErrorCodes.includes(value);
65
+ }
66
+ function typedDetail(value) {
67
+ if (!object(value)) return {};
68
+ const detail = {};
69
+ if (typeof value.httpStatus === 'number') detail.httpStatus = value.httpStatus;
70
+ if (typeof value.platformCode === 'number') detail.platformCode = value.platformCode;
71
+ if (typeof value.limitReason === 'string') detail.limitReason = value.limitReason;
72
+ if (typeof value.reason === 'string') detail.reason = value.reason;
73
+ return detail;
74
+ }
75
+ function wireError(value) {
76
+ if (!object(value) || !knownCode(value.code)) {
77
+ return new LiveVoiceError('generic', {
78
+ detail: {
79
+ reason: 'unknown_native_error'
80
+ }
81
+ });
82
+ }
83
+ return new LiveVoiceError(value.code, {
84
+ detail: typedDetail(value.detail),
85
+ message: typeof value.message === 'string' ? value.message : null
86
+ });
87
+ }
88
+
89
+ /**
90
+ * The error every LiveVoice call rejects with, and the one a `failed` connection carries. Its
91
+ * `message` is localised text to show as is. Codes only a developer can fix (`invalid_argument`,
92
+ * `not_initialized`, `api_key_invalid`, `unsupported_sdk`) share a generic text; the SDK log
93
+ * explains them.
94
+ */
95
+ export class LiveVoiceError extends Error {
96
+ /** What went wrong; stable, for your own handling. */
97
+
98
+ /** Whether trying again can succeed; it follows from the code. */
99
+
100
+ /** Optional details, `{}` when there are none. */
101
+
102
+ /**
103
+ * Creates an error, for tests and previews.
104
+ *
105
+ * @param code - What went wrong; `isRetryable` follows from it.
106
+ * @param options - `detail`: extra information for some codes. `message`: the text to show;
107
+ * leave it out or pass `null` for the code's localised text.
108
+ */
109
+ constructor(code, options = {}) {
110
+ super(options?.message ?? (errorMessage(code) || code));
111
+ this.name = 'LiveVoiceError';
112
+ this.code = code;
113
+ this.isRetryable = retryableCodes.has(code);
114
+ this.detail = Object.freeze(typedDetail(options?.detail));
115
+ }
116
+ }
117
+
118
+ /** When the next reconnect attempt runs. */
119
+
120
+ /**
121
+ * The connection to the event:
122
+ * - `idle`: nothing is joined or joining; also before `initialize()`.
123
+ * - `joining`: a join, a switch to a linked event, or the retry of a failed join is in progress.
124
+ * - `ready`: the event `eventId` is joined.
125
+ * - `reconnecting`: the connection was lost and is recovering; see `retry`. A `reconnect()` that
126
+ * times out leaves it here, and recovery continues.
127
+ * - `leaving`: a leave is running.
128
+ * - `failed`: a join, a switch or the retry of a join failed, or the joined event ended, with
129
+ * `error`. The join is kept: `reconnect()` retries it if the error is retryable, and
130
+ * `stopChannel` and `stopSubtitles` still work. It stays until that retry, a new join or a
131
+ * leave.
132
+ *
133
+ * Use it for display. To know that a call completed, await the call.
134
+ */
135
+
136
+ /** What `joinEvent` joins with. */
137
+
138
+ /**
139
+ * The joined event `joinEvent` returns. It follows a completed switch to a linked event.
140
+ *
141
+ * Its `leave()` leaves only the join this came from, including a linked event it switched to; it
142
+ * can never leave a newer join. If a newer join replaced its join, it does nothing and resolves at
143
+ * once. Otherwise it resolves as `leaveEvent` does: the event's local cleanup has ended, and the
144
+ * observed connection is `idle` unless a newer join exists. If its join was already left, it
145
+ * waits for that leave's cleanup.
146
+ *
147
+ * `leave()` rejects with a {@link LiveVoiceError} `leave_incomplete` when the cleanup has not
148
+ * finished within 5 seconds; the event is left all the same and the cleanup continues. Another
149
+ * leave then waits for the same cleanup and can fail with `leave_incomplete` again.
150
+ */
151
+
152
+ export function normalizeError(error) {
153
+ if (error instanceof LiveVoiceError) return error;
154
+ const native = object(error) ? error : {};
155
+ try {
156
+ const wire = JSON.parse(typeof native.message === 'string' ? native.message : '');
157
+ if (object(wire) && typeof wire.code === 'string') return wireError(wire);
158
+ } catch {/* Non-SDK failures retain a stable fallback. */}
159
+ return wireError(native);
160
+ }
161
+
162
+ /**
163
+ * A developer-only error the wrapper throws itself (bridge.md 3.6): its message is the generic
164
+ * text, and its explanation, a fixed sentence without argument values, goes to the SDK log as
165
+ * `LV_USAGE_ERROR`.
166
+ */
167
+ export function usageError(code, operation, explanation) {
168
+ writeLogEntry('LV_USAGE_ERROR', 'error', {
169
+ code,
170
+ operation,
171
+ explanation
172
+ });
173
+ return new LiveVoiceError(code);
174
+ }
175
+
176
+ /** The public call behind each command, for the log. */
177
+ const operations = {
178
+ join: 'joinEvent',
179
+ leave: 'leaveEvent'
180
+ };
181
+
182
+ /**
183
+ * Runs `command` natively. Before `initialize()` it fails with `not_initialized` without reaching
184
+ * native, the only error the wrapper owns (bridge.md 3.1). A reply that is not JSON resolves as
185
+ * `undefined`: native succeeded, so the call does too.
186
+ */
187
+ export async function invoke(command, args = {}) {
188
+ if (!isInitialized()) {
189
+ throw usageError('not_initialized', operations[command] ?? command, 'Call initialize() and await it first.');
190
+ }
191
+ let reply;
192
+ try {
193
+ reply = await Native.execute(command, JSON.stringify(args));
194
+ } catch (error) {
195
+ throw normalizeError(error);
196
+ }
197
+ try {
198
+ return JSON.parse(reply);
199
+ } catch {
200
+ logDecodeError('reply', command);
201
+ return undefined;
202
+ }
203
+ }
204
+ export async function join(request) {
205
+ if (!request || typeof request.joinCode !== 'string' || !request.joinCode.trim() || typeof request.apiKey !== 'string' || !request.apiKey.trim() || request.password != null && typeof request.password !== 'string') {
206
+ throw usageError('invalid_argument', 'joinEvent', 'The join request needs a non-empty join code and API key, and a password that is a string or null.');
207
+ }
208
+ logInfo(LiveVoiceLogEvent.joinRequest, {
209
+ joinCode: request.joinCode,
210
+ hasPassword: request.password != null
211
+ });
212
+ const result = await invoke('join', {
213
+ joinCode: request.joinCode,
214
+ password: request.password,
215
+ apiKey: request.apiKey
216
+ });
217
+ if (!object(result) || typeof result.entryId !== 'string' || !result.entryId.trim()) {
218
+ logDecodeError('reply', 'join');
219
+ throw new LiveVoiceError('generic', {
220
+ detail: {
221
+ reason: 'invalid_join_receipt'
222
+ }
223
+ });
224
+ }
225
+ const {
226
+ entryId
227
+ } = result;
228
+ // When joinEvent() resolves, the values already show the joined event (18 item 110).
229
+ await awaitRevisions(result.revisions);
230
+ let leaving;
231
+ return Object.freeze({
232
+ // When leave() resolves, the values already show what it left behind, as after a join.
233
+ leave: () => leaving ??= invoke('leave', {
234
+ entryId
235
+ }).then(reply => awaitRevisions(object(reply) ? reply.revisions : undefined), error => {
236
+ leaving = undefined;
237
+ throw error;
238
+ })
239
+ });
240
+ }
241
+ export function channelId(id, operation) {
242
+ if (!Number.isSafeInteger(id) || id <= 0) {
243
+ throw usageError('invalid_argument', operation, 'A channel id is a positive safe integer.');
244
+ }
245
+ return id;
246
+ }
247
+
248
+ /** A retry as the cache keeps it: the time in milliseconds, so every delivery gets its own `Date`. */
249
+
250
+ /** The connection as the cache keeps it, with the retry time in milliseconds. */
251
+
252
+ /** The wire's retry, or `undefined` when it is malformed. */
253
+ export function decodeRetry(wire) {
254
+ if (object(wire) && wire.kind === 'inProgress') return {
255
+ kind: 'inProgress'
256
+ };
257
+ if (object(wire) && wire.kind === 'scheduled' && typeof wire.at === 'number' && Number.isSafeInteger(wire.at)) {
258
+ return {
259
+ kind: 'scheduled',
260
+ at: wire.at
261
+ };
262
+ }
263
+ return undefined;
264
+ }
265
+
266
+ /** A public retry, with a `Date` of its own. */
267
+ export function publicRetry(retry) {
268
+ return retry.kind === 'scheduled' ? {
269
+ kind: 'scheduled',
270
+ at: new Date(retry.at)
271
+ } : {
272
+ kind: 'inProgress'
273
+ };
274
+ }
275
+
276
+ /** The wire's error as a `LiveVoiceError`; anything else becomes `generic`. */
277
+ export function decodeError(wire) {
278
+ return wireError(wire);
279
+ }
280
+
281
+ /** The wire's connection (bridge.md 2.3); throws for one it cannot read. */
282
+ export function decodeConnection(wire) {
283
+ if (!object(wire)) throw new LiveVoiceError('generic');
284
+ switch (wire.status) {
285
+ case 'idle':
286
+ case 'joining':
287
+ case 'leaving':
288
+ return {
289
+ status: wire.status
290
+ };
291
+ case 'ready':
292
+ case 'reconnecting':
293
+ {
294
+ const eventId = wire.eventId;
295
+ if (typeof eventId !== 'number' || !Number.isSafeInteger(eventId) || eventId <= 0) throw new LiveVoiceError('generic');
296
+ if (wire.status === 'ready') return {
297
+ status: 'ready',
298
+ eventId
299
+ };
300
+ const retry = decodeRetry(wire.retry);
301
+ if (retry === undefined) throw new LiveVoiceError('generic');
302
+ return {
303
+ status: 'reconnecting',
304
+ eventId,
305
+ retry
306
+ };
307
+ }
308
+ case 'failed':
309
+ return {
310
+ status: 'failed',
311
+ error: wireError(wire.error)
312
+ };
313
+ default:
314
+ throw new LiveVoiceError('generic');
315
+ }
316
+ }
317
+
318
+ /**
319
+ * The public connection. A scheduled retry gets a `Date` of its own on every call, so changing one
320
+ * changes no other; every other connection is the cached value itself.
321
+ */
322
+ export function publicConnection(value) {
323
+ if (value.status === 'reconnecting' && value.retry.kind === 'scheduled') {
324
+ return Object.freeze({
325
+ ...value,
326
+ retry: Object.freeze(publicRetry(value.retry))
327
+ });
328
+ }
329
+ return value;
330
+ }
331
+ //# sourceMappingURL=Lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Native","logDecodeError","logInfo","LiveVoiceLogEvent","writeLogEntry","awaitRevisions","errorMessage","isInitialized","record","object","liveVoiceErrorCodes","retryableCodes","Set","knownCode","value","includes","typedDetail","detail","httpStatus","platformCode","limitReason","reason","wireError","code","LiveVoiceError","message","Error","constructor","options","name","isRetryable","has","Object","freeze","normalizeError","error","native","wire","JSON","parse","usageError","operation","explanation","operations","join","leave","invoke","command","args","reply","execute","stringify","undefined","request","joinCode","trim","apiKey","password","joinRequest","hasPassword","result","entryId","revisions","leaving","then","channelId","id","Number","isSafeInteger","decodeRetry","kind","at","publicRetry","retry","Date","decodeError","decodeConnection","status","eventId","publicConnection"],"sourceRoot":"../../../src","sources":["sdk/Lifecycle.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,M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