voice-react-native-sdk 1.6.2-fork.4

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 (227) hide show
  1. package/LICENSE +206 -0
  2. package/README.md +179 -0
  3. package/android/build.gradle +113 -0
  4. package/android/gradle.properties +29 -0
  5. package/android/src/main/AndroidManifest.xml +30 -0
  6. package/android/src/main/java/com/twiliovoicereactnative/AudioSwitchManager.java +141 -0
  7. package/android/src/main/java/com/twiliovoicereactnative/CallListenerProxy.java +186 -0
  8. package/android/src/main/java/com/twiliovoicereactnative/CallMessageListenerProxy.java +103 -0
  9. package/android/src/main/java/com/twiliovoicereactnative/CallRecordDatabase.java +183 -0
  10. package/android/src/main/java/com/twiliovoicereactnative/CommonConstants.java +195 -0
  11. package/android/src/main/java/com/twiliovoicereactnative/ConfigurationProperties.java +41 -0
  12. package/android/src/main/java/com/twiliovoicereactnative/Constants.java +23 -0
  13. package/android/src/main/java/com/twiliovoicereactnative/ExpoActivityLifecycleListener.java +27 -0
  14. package/android/src/main/java/com/twiliovoicereactnative/ExpoApplicationLifecycleListener.java +14 -0
  15. package/android/src/main/java/com/twiliovoicereactnative/ExpoModule.kt +36 -0
  16. package/android/src/main/java/com/twiliovoicereactnative/ExpoPackage.java +20 -0
  17. package/android/src/main/java/com/twiliovoicereactnative/JSEventEmitter.java +98 -0
  18. package/android/src/main/java/com/twiliovoicereactnative/MediaPlayerManager.java +58 -0
  19. package/android/src/main/java/com/twiliovoicereactnative/NotificationUtility.java +363 -0
  20. package/android/src/main/java/com/twiliovoicereactnative/ReactNativeArgumentsSerializer.java +276 -0
  21. package/android/src/main/java/com/twiliovoicereactnative/SDKLog.java +74 -0
  22. package/android/src/main/java/com/twiliovoicereactnative/StatsListenerProxy.java +178 -0
  23. package/android/src/main/java/com/twiliovoicereactnative/TwilioVoiceReactNativeModule.java +778 -0
  24. package/android/src/main/java/com/twiliovoicereactnative/TwilioVoiceReactNativePackage.java +28 -0
  25. package/android/src/main/java/com/twiliovoicereactnative/VoiceActivityProxy.java +101 -0
  26. package/android/src/main/java/com/twiliovoicereactnative/VoiceApplicationProxy.java +133 -0
  27. package/android/src/main/java/com/twiliovoicereactnative/VoiceFirebaseMessagingService.java +88 -0
  28. package/android/src/main/java/com/twiliovoicereactnative/VoiceService.java +403 -0
  29. package/android/src/main/res/drawable/answered_call_small_icon.png +0 -0
  30. package/android/src/main/res/drawable/ic_launcher_round.png +0 -0
  31. package/android/src/main/res/drawable/ic_launcher_sdk.png +0 -0
  32. package/android/src/main/res/drawable/incoming_call_small_icon.png +0 -0
  33. package/android/src/main/res/drawable/outgoing_call_small_icon.png +0 -0
  34. package/android/src/main/res/raw/disconnect.wav +0 -0
  35. package/android/src/main/res/raw/incoming.wav +0 -0
  36. package/android/src/main/res/raw/outgoing.wav +0 -0
  37. package/android/src/main/res/raw/ringtone.wav +0 -0
  38. package/android/src/main/res/raw/silent.wav +0 -0
  39. package/android/src/main/res/values/colors.xml +11 -0
  40. package/android/src/main/res/values/config.xml +5 -0
  41. package/android/src/main/res/values/dimens.xml +7 -0
  42. package/android/src/main/res/values/strings.xml +25 -0
  43. package/android/src/main/res/values/styles.xml +10 -0
  44. package/android/src/main/res/values-night/colors.xml +11 -0
  45. package/expo-config-plugin/android.js +191 -0
  46. package/expo-config-plugin/ios.js +22 -0
  47. package/expo-module.config.json +6 -0
  48. package/ios/TwilioVoicePushRegistry.h +19 -0
  49. package/ios/TwilioVoicePushRegistry.m +72 -0
  50. package/ios/TwilioVoiceReactNative+CallInvite.m +56 -0
  51. package/ios/TwilioVoiceReactNative+CallKit.m +533 -0
  52. package/ios/TwilioVoiceReactNative+CallMessage.m +81 -0
  53. package/ios/TwilioVoiceReactNative.h +74 -0
  54. package/ios/TwilioVoiceReactNative.m +1046 -0
  55. package/ios/TwilioVoiceReactNative.xcodeproj/project.pbxproj +328 -0
  56. package/ios/TwilioVoiceReactNativeConstants.h +200 -0
  57. package/ios/Utilities/TwilioVoiceStatsReport.h +175 -0
  58. package/lib/commonjs/AudioDevice.js +101 -0
  59. package/lib/commonjs/AudioDevice.js.map +1 -0
  60. package/lib/commonjs/Call.js +765 -0
  61. package/lib/commonjs/Call.js.map +1 -0
  62. package/lib/commonjs/CallInvite.js +452 -0
  63. package/lib/commonjs/CallInvite.js.map +1 -0
  64. package/lib/commonjs/CallMessage/CallMessage.js +54 -0
  65. package/lib/commonjs/CallMessage/CallMessage.js.map +1 -0
  66. package/lib/commonjs/CallMessage/IncomingCallMessage.js +120 -0
  67. package/lib/commonjs/CallMessage/IncomingCallMessage.js.map +1 -0
  68. package/lib/commonjs/CallMessage/OutgoingCallMessage.js +148 -0
  69. package/lib/commonjs/CallMessage/OutgoingCallMessage.js.map +1 -0
  70. package/lib/commonjs/ExpoModule.js +69 -0
  71. package/lib/commonjs/ExpoModule.js.map +1 -0
  72. package/lib/commonjs/Voice.js +611 -0
  73. package/lib/commonjs/Voice.js.map +1 -0
  74. package/lib/commonjs/common.js +26 -0
  75. package/lib/commonjs/common.js.map +1 -0
  76. package/lib/commonjs/constants.js +158 -0
  77. package/lib/commonjs/constants.js.map +1 -0
  78. package/lib/commonjs/error/InvalidArgumentError.js +32 -0
  79. package/lib/commonjs/error/InvalidArgumentError.js.map +1 -0
  80. package/lib/commonjs/error/InvalidStateError.js +33 -0
  81. package/lib/commonjs/error/InvalidStateError.js.map +1 -0
  82. package/lib/commonjs/error/TwilioError.js +38 -0
  83. package/lib/commonjs/error/TwilioError.js.map +1 -0
  84. package/lib/commonjs/error/UnsupportedPlatformError.js +33 -0
  85. package/lib/commonjs/error/UnsupportedPlatformError.js.map +1 -0
  86. package/lib/commonjs/error/generated.js +2343 -0
  87. package/lib/commonjs/error/generated.js.map +1 -0
  88. package/lib/commonjs/error/index.js +112 -0
  89. package/lib/commonjs/error/index.js.map +1 -0
  90. package/lib/commonjs/error/utility.js +37 -0
  91. package/lib/commonjs/error/utility.js.map +1 -0
  92. package/lib/commonjs/index.js +95 -0
  93. package/lib/commonjs/index.js.map +1 -0
  94. package/lib/commonjs/type/AudioDevice.js +6 -0
  95. package/lib/commonjs/type/AudioDevice.js.map +1 -0
  96. package/lib/commonjs/type/Call.js +6 -0
  97. package/lib/commonjs/type/Call.js.map +1 -0
  98. package/lib/commonjs/type/CallInvite.js +6 -0
  99. package/lib/commonjs/type/CallInvite.js.map +1 -0
  100. package/lib/commonjs/type/CallKit.js +30 -0
  101. package/lib/commonjs/type/CallKit.js.map +1 -0
  102. package/lib/commonjs/type/CallMessage.js +6 -0
  103. package/lib/commonjs/type/CallMessage.js.map +1 -0
  104. package/lib/commonjs/type/Error.js +6 -0
  105. package/lib/commonjs/type/Error.js.map +1 -0
  106. package/lib/commonjs/type/NativeModule.js +6 -0
  107. package/lib/commonjs/type/NativeModule.js.map +1 -0
  108. package/lib/commonjs/type/RTCStats.js +29 -0
  109. package/lib/commonjs/type/RTCStats.js.map +1 -0
  110. package/lib/commonjs/type/Voice.js +6 -0
  111. package/lib/commonjs/type/Voice.js.map +1 -0
  112. package/lib/commonjs/type/common.js +2 -0
  113. package/lib/commonjs/type/common.js.map +1 -0
  114. package/lib/module/AudioDevice.js +97 -0
  115. package/lib/module/AudioDevice.js.map +1 -0
  116. package/lib/module/Call.js +766 -0
  117. package/lib/module/Call.js.map +1 -0
  118. package/lib/module/CallInvite.js +450 -0
  119. package/lib/module/CallInvite.js.map +1 -0
  120. package/lib/module/CallMessage/CallMessage.js +51 -0
  121. package/lib/module/CallMessage/CallMessage.js.map +1 -0
  122. package/lib/module/CallMessage/IncomingCallMessage.js +116 -0
  123. package/lib/module/CallMessage/IncomingCallMessage.js.map +1 -0
  124. package/lib/module/CallMessage/OutgoingCallMessage.js +154 -0
  125. package/lib/module/CallMessage/OutgoingCallMessage.js.map +1 -0
  126. package/lib/module/ExpoModule.js +58 -0
  127. package/lib/module/ExpoModule.js.map +1 -0
  128. package/lib/module/Voice.js +598 -0
  129. package/lib/module/Voice.js.map +1 -0
  130. package/lib/module/common.js +11 -0
  131. package/lib/module/common.js.map +1 -0
  132. package/lib/module/constants.js +151 -0
  133. package/lib/module/constants.js.map +1 -0
  134. package/lib/module/error/InvalidArgumentError.js +23 -0
  135. package/lib/module/error/InvalidArgumentError.js.map +1 -0
  136. package/lib/module/error/InvalidStateError.js +24 -0
  137. package/lib/module/error/InvalidStateError.js.map +1 -0
  138. package/lib/module/error/TwilioError.js +29 -0
  139. package/lib/module/error/TwilioError.js.map +1 -0
  140. package/lib/module/error/UnsupportedPlatformError.js +24 -0
  141. package/lib/module/error/UnsupportedPlatformError.js.map +1 -0
  142. package/lib/module/error/generated.js +2315 -0
  143. package/lib/module/error/generated.js.map +1 -0
  144. package/lib/module/error/index.js +6 -0
  145. package/lib/module/error/index.js.map +1 -0
  146. package/lib/module/error/utility.js +27 -0
  147. package/lib/module/error/utility.js.map +1 -0
  148. package/lib/module/index.js +23 -0
  149. package/lib/module/index.js.map +1 -0
  150. package/lib/module/type/AudioDevice.js +2 -0
  151. package/lib/module/type/AudioDevice.js.map +1 -0
  152. package/lib/module/type/Call.js +2 -0
  153. package/lib/module/type/Call.js.map +1 -0
  154. package/lib/module/type/CallInvite.js +2 -0
  155. package/lib/module/type/CallInvite.js.map +1 -0
  156. package/lib/module/type/CallKit.js +22 -0
  157. package/lib/module/type/CallKit.js.map +1 -0
  158. package/lib/module/type/CallMessage.js +2 -0
  159. package/lib/module/type/CallMessage.js.map +1 -0
  160. package/lib/module/type/Error.js +2 -0
  161. package/lib/module/type/Error.js.map +1 -0
  162. package/lib/module/type/NativeModule.js +2 -0
  163. package/lib/module/type/NativeModule.js.map +1 -0
  164. package/lib/module/type/RTCStats.js +21 -0
  165. package/lib/module/type/RTCStats.js.map +1 -0
  166. package/lib/module/type/Voice.js +2 -0
  167. package/lib/module/type/Voice.js.map +1 -0
  168. package/lib/module/type/common.js +2 -0
  169. package/lib/module/type/common.js.map +1 -0
  170. package/lib/typescript/AudioDevice.d.ts +74 -0
  171. package/lib/typescript/Call.d.ts +874 -0
  172. package/lib/typescript/CallInvite.d.ts +484 -0
  173. package/lib/typescript/CallMessage/CallMessage.d.ts +53 -0
  174. package/lib/typescript/CallMessage/IncomingCallMessage.d.ts +75 -0
  175. package/lib/typescript/CallMessage/OutgoingCallMessage.d.ts +198 -0
  176. package/lib/typescript/ExpoModule.d.ts +13 -0
  177. package/lib/typescript/Voice.d.ts +620 -0
  178. package/lib/typescript/common.d.ts +11 -0
  179. package/lib/typescript/constants.d.ts +148 -0
  180. package/lib/typescript/error/InvalidArgumentError.d.ts +11 -0
  181. package/lib/typescript/error/InvalidStateError.d.ts +12 -0
  182. package/lib/typescript/error/TwilioError.d.ts +14 -0
  183. package/lib/typescript/error/UnsupportedPlatformError.d.ts +12 -0
  184. package/lib/typescript/error/generated.d.ts +1558 -0
  185. package/lib/typescript/error/index.d.ts +5 -0
  186. package/lib/typescript/error/utility.d.ts +12 -0
  187. package/lib/typescript/index.d.ts +18 -0
  188. package/lib/typescript/type/AudioDevice.d.ts +15 -0
  189. package/lib/typescript/type/Call.d.ts +59 -0
  190. package/lib/typescript/type/CallInvite.d.ts +40 -0
  191. package/lib/typescript/type/CallKit.d.ts +60 -0
  192. package/lib/typescript/type/CallMessage.d.ts +20 -0
  193. package/lib/typescript/type/Error.d.ts +9 -0
  194. package/lib/typescript/type/NativeModule.d.ts +59 -0
  195. package/lib/typescript/type/RTCStats.d.ts +91 -0
  196. package/lib/typescript/type/Voice.d.ts +16 -0
  197. package/lib/typescript/type/common.d.ts +15 -0
  198. package/package.json +167 -0
  199. package/src/AudioDevice.tsx +88 -0
  200. package/src/Call.tsx +1343 -0
  201. package/src/CallInvite.tsx +757 -0
  202. package/src/CallMessage/CallMessage.ts +83 -0
  203. package/src/CallMessage/IncomingCallMessage.ts +104 -0
  204. package/src/CallMessage/OutgoingCallMessage.ts +308 -0
  205. package/src/ExpoModule.ts +59 -0
  206. package/src/Voice.tsx +1010 -0
  207. package/src/common.ts +16 -0
  208. package/src/constants.ts +193 -0
  209. package/src/error/InvalidArgumentError.ts +19 -0
  210. package/src/error/InvalidStateError.ts +19 -0
  211. package/src/error/TwilioError.ts +22 -0
  212. package/src/error/UnsupportedPlatformError.ts +19 -0
  213. package/src/error/generated.ts +2277 -0
  214. package/src/error/index.ts +18 -0
  215. package/src/error/utility.ts +36 -0
  216. package/src/index.tsx +24 -0
  217. package/src/type/AudioDevice.ts +18 -0
  218. package/src/type/Call.ts +102 -0
  219. package/src/type/CallInvite.ts +59 -0
  220. package/src/type/CallKit.ts +61 -0
  221. package/src/type/CallMessage.ts +31 -0
  222. package/src/type/Error.ts +11 -0
  223. package/src/type/NativeModule.ts +93 -0
  224. package/src/type/RTCStats.ts +99 -0
  225. package/src/type/Voice.ts +31 -0
  226. package/src/type/common.ts +16 -0
  227. package/twilio-voice-react-native.podspec +22 -0
@@ -0,0 +1,598 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /**
4
+ * Copyright © 2022 Twilio, Inc. All rights reserved. Licensed under the Twilio
5
+ * license.
6
+ *
7
+ * See LICENSE in the project root for license information.
8
+ */
9
+ import { EventEmitter } from 'eventemitter3';
10
+ import { AudioDevice } from './AudioDevice';
11
+ import { Call } from './Call';
12
+ import { CallInvite } from './CallInvite';
13
+ import { NativeEventEmitter, NativeModule, Platform } from './common';
14
+ import { Constants } from './constants';
15
+ import { InvalidArgumentError } from './error/InvalidArgumentError';
16
+ import { UnsupportedPlatformError } from './error/UnsupportedPlatformError';
17
+ import { constructTwilioError } from './error/utility';
18
+
19
+ /**
20
+ * Main entry-point of the Voice SDK. Provides access to the entire feature-set
21
+ * of the library.
22
+ *
23
+ * @example
24
+ * Usage:
25
+ * ```
26
+ * const token = '...';
27
+ *
28
+ * const voice = new Voice();
29
+ *
30
+ * voice.on(Voice.Event.CallInvite, (callInvite: CallInvite) => {
31
+ * callInvite.accept();
32
+ * });
33
+ *
34
+ * voice.register(token);
35
+ * ```
36
+ *
37
+ * @remarks
38
+ * - See also the {@link (Voice:namespace).Event} enum for events emitted by
39
+ * `Voice` objects.
40
+ * - See also the {@link (Voice:interface) | Voice interface} for events
41
+ * emitted by this class and associated types.
42
+ * - See also the {@link (Voice:namespace) | Voice namespace} for types and
43
+ * enumerations used by this class.
44
+ *
45
+ * @public
46
+ */
47
+ export class Voice extends EventEmitter {
48
+ /**
49
+ * Handlers for native voice events. Set upon construction so we can
50
+ * dynamically bind events to handlers.
51
+ *
52
+ * @privateRemarks
53
+ * This is done by the constructor so this mapping isn't made every time the
54
+ * {@link (Voice:class)._handleNativeEvent} function is invoked.
55
+ */
56
+
57
+ /**
58
+ * Main entry-point of the Voice SDK. Provides access to the entire
59
+ * feature-set of the library.
60
+ */
61
+ constructor() {
62
+ super();
63
+
64
+ _defineProperty(this, "_nativeEventHandler", void 0);
65
+
66
+ _defineProperty(this, "_handleNativeEvent", nativeVoiceEvent => {
67
+ const {
68
+ type
69
+ } = nativeVoiceEvent;
70
+ const handler = this._nativeEventHandler[type];
71
+
72
+ if (typeof handler === 'undefined') {
73
+ throw new Error(`Unknown voice event type received from the native layer: "${type}".`);
74
+ }
75
+
76
+ handler(nativeVoiceEvent);
77
+ });
78
+
79
+ _defineProperty(this, "_handleCallInvite", nativeVoiceEvent => {
80
+ if (nativeVoiceEvent.type !== Constants.VoiceEventTypeValueIncomingCallInvite) {
81
+ throw new Error('Incorrect "voice#callInvite" handler called for type ' + `"${nativeVoiceEvent.type}".`);
82
+ }
83
+
84
+ const {
85
+ callInvite: callInviteInfo
86
+ } = nativeVoiceEvent;
87
+ const callInvite = new CallInvite(callInviteInfo, CallInvite.State.Pending);
88
+ this.emit(Voice.Event.CallInvite, callInvite);
89
+ });
90
+
91
+ _defineProperty(this, "_handleError", nativeVoiceEvent => {
92
+ if (nativeVoiceEvent.type !== Constants.VoiceEventError) {
93
+ throw new Error('Incorrect "voice#error" handler called for type ' + `"${nativeVoiceEvent.type}".`);
94
+ }
95
+
96
+ const {
97
+ error: {
98
+ code,
99
+ message
100
+ }
101
+ } = nativeVoiceEvent;
102
+ const error = constructTwilioError(message, code);
103
+ this.emit(Voice.Event.Error, error);
104
+ });
105
+
106
+ _defineProperty(this, "_handleRegistered", nativeVoiceEvent => {
107
+ if (nativeVoiceEvent.type !== Constants.VoiceEventRegistered) {
108
+ throw new Error('Incorrect "voice#error" handler called for type ' + `"${nativeVoiceEvent.type}".`);
109
+ }
110
+
111
+ this.emit(Voice.Event.Registered);
112
+ });
113
+
114
+ _defineProperty(this, "_handleUnregistered", nativeVoiceEvent => {
115
+ if (nativeVoiceEvent.type !== Constants.VoiceEventUnregistered) {
116
+ throw new Error('Incorrect "voice#error" handler called for type ' + `"${nativeVoiceEvent.type}".`);
117
+ }
118
+
119
+ this.emit(Voice.Event.Unregistered);
120
+ });
121
+
122
+ _defineProperty(this, "_handleAudioDevicesUpdated", nativeVoiceEvent => {
123
+ if (nativeVoiceEvent.type !== Constants.VoiceEventAudioDevicesUpdated) {
124
+ throw new Error('Incorrect "voice#audioDevicesUpdated" handler called for type ' + `"${nativeVoiceEvent.type}".`);
125
+ }
126
+
127
+ const {
128
+ audioDevices: audioDeviceInfos,
129
+ selectedDevice: selectedDeviceInfo
130
+ } = nativeVoiceEvent;
131
+ const audioDevices = audioDeviceInfos.map(audioDeviceInfo => new AudioDevice(audioDeviceInfo));
132
+ const selectedDevice = typeof selectedDeviceInfo !== 'undefined' && selectedDeviceInfo !== null ? new AudioDevice(selectedDeviceInfo) : undefined;
133
+ this.emit(Voice.Event.AudioDevicesUpdated, audioDevices, selectedDevice);
134
+ });
135
+
136
+ this._nativeEventHandler = {
137
+ /**
138
+ * Common
139
+ */
140
+ [Constants.VoiceEventError]: this._handleError,
141
+
142
+ /**
143
+ * Call Invite
144
+ */
145
+ [Constants.VoiceEventTypeValueIncomingCallInvite]: this._handleCallInvite,
146
+
147
+ /**
148
+ * Registration
149
+ */
150
+ [Constants.VoiceEventRegistered]: this._handleRegistered,
151
+ [Constants.VoiceEventUnregistered]: this._handleUnregistered,
152
+
153
+ /**
154
+ * Audio Devices
155
+ */
156
+ [Constants.VoiceEventAudioDevicesUpdated]: this._handleAudioDevicesUpdated
157
+ };
158
+ NativeEventEmitter.addListener(Constants.ScopeVoice, this._handleNativeEvent);
159
+ }
160
+ /**
161
+ * Connect for devices on Android platforms.
162
+ */
163
+
164
+
165
+ async _connect_android(token, params, notificationDisplayName) {
166
+ const connectResult = await NativeModule.voice_connect_android(token, params, notificationDisplayName).then(callInfo => {
167
+ return {
168
+ type: 'ok',
169
+ callInfo
170
+ };
171
+ }).catch(error => {
172
+ const code = error.userInfo.code;
173
+ const message = error.userInfo.message;
174
+ return {
175
+ type: 'err',
176
+ message,
177
+ code
178
+ };
179
+ });
180
+
181
+ if (connectResult.type === 'err') {
182
+ throw constructTwilioError(connectResult.message, connectResult.code);
183
+ }
184
+
185
+ return new Call(connectResult.callInfo);
186
+ }
187
+ /**
188
+ * Connect for devices on iOS platforms.
189
+ */
190
+
191
+
192
+ async _connect_ios(token, params, contactHandle) {
193
+ const parsedContactHandle = contactHandle === '' ? 'Default Contact' : contactHandle;
194
+ const callInfo = await NativeModule.voice_connect_ios(token, params, parsedContactHandle);
195
+ return new Call(callInfo);
196
+ }
197
+ /**
198
+ * Intermediary event handler for `Voice`-level events. Ensures that the type
199
+ * of the incoming event is expected and invokes the proper event listener.
200
+ * @param nativeVoiceEvent - A `Voice` event directly from the native layer.
201
+ */
202
+
203
+
204
+ /**
205
+ * Create an outgoing call.
206
+ *
207
+ * @remarks
208
+ * Note that the resolution of the returned `Promise` does not imply any call
209
+ * event occurring, such as answered or rejected.
210
+ * The `contactHandle` parameter is only required for iOS apps. Currently the
211
+ * parameter does have any effect on Android apps and can be ignored.
212
+ * `Default Contact` will appear in the iOS call history if the value is empty
213
+ * or not provided.
214
+ *
215
+ * @param token - A Twilio Access Token, usually minted by an
216
+ * authentication-gated endpoint using a Twilio helper library.
217
+ * @param options - Connect options.
218
+ * See {@link (Voice:namespace).ConnectOptions}.
219
+ *
220
+ * @returns
221
+ * A `Promise` that
222
+ * - Resolves with a call when the call is created.
223
+ * - Rejects:
224
+ * * When a call is not able to be created on the native layer.
225
+ * * With an {@link TwilioErrors.InvalidArgumentError} when invalid
226
+ * arguments are passed.
227
+ */
228
+ async connect(token, {
229
+ contactHandle = 'Default Contact',
230
+ notificationDisplayName = undefined,
231
+ params = {}
232
+ } = {}) {
233
+ if (typeof token !== 'string') {
234
+ throw new InvalidArgumentError('Argument "token" must be of type "string".');
235
+ }
236
+
237
+ if (typeof contactHandle !== 'string') {
238
+ throw new InvalidArgumentError('Optional argument "contactHandle" must be undefined or of type' + ' "string".');
239
+ }
240
+
241
+ if (typeof params !== 'object') {
242
+ throw new InvalidArgumentError('Optional argument "params" must be undefined or of type "object".');
243
+ }
244
+
245
+ for (const [key, value] of Object.entries(params)) {
246
+ if (typeof value !== 'string') {
247
+ throw new InvalidArgumentError(`Voice.ConnectOptions.params["${key}"] must be of type string`);
248
+ }
249
+ }
250
+
251
+ switch (Platform.OS) {
252
+ case 'ios':
253
+ return this._connect_ios(token, params, contactHandle);
254
+
255
+ case 'android':
256
+ return this._connect_android(token, params, notificationDisplayName);
257
+
258
+ default:
259
+ throw new UnsupportedPlatformError(`Unsupported platform "${Platform.OS}". Expected "android" or "ios".`);
260
+ }
261
+ }
262
+ /**
263
+ * Get the version of the native SDK. Note that this is not the version of the
264
+ * React Native SDK, this is the version of the mobile SDK that the RN SDK is
265
+ * utilizing.
266
+ * @returns
267
+ * A `Promise` that
268
+ * - Resolves with a string representing the version of the native SDK.
269
+ */
270
+
271
+
272
+ getVersion() {
273
+ return NativeModule.voice_getVersion();
274
+ }
275
+ /**
276
+ * Get the Device token from the native layer.
277
+ * @returns a Promise that resolves with a string representing the Device
278
+ * token.
279
+ */
280
+
281
+
282
+ getDeviceToken() {
283
+ return NativeModule.voice_getDeviceToken();
284
+ }
285
+ /**
286
+ * Get a list of existing calls, ongoing and pending. This will not return any
287
+ * call that has finished.
288
+ * @returns
289
+ * A `Promise` that
290
+ * - Resolves with a mapping of `Uuid`s to {@link (Call:class)}s.
291
+ */
292
+
293
+
294
+ async getCalls() {
295
+ const callInfos = await NativeModule.voice_getCalls();
296
+ const callsMap = new Map(callInfos.map(callInfo => [callInfo.uuid, new Call(callInfo)]));
297
+ return callsMap;
298
+ }
299
+ /**
300
+ * Get a list of pending call invites.
301
+ *
302
+ * @remarks
303
+ * This list will not contain any call invites that have been "settled"
304
+ * (answered or rejected).
305
+ *
306
+ * @returns
307
+ * A `Promise` that
308
+ * - Resolves with a mapping of `Uuid`s to {@link (CallInvite:class)}s.
309
+ */
310
+
311
+
312
+ async getCallInvites() {
313
+ const callInviteInfos = await NativeModule.voice_getCallInvites();
314
+ const callInvitesMap = new Map(callInviteInfos.map(callInviteInfo => [callInviteInfo.uuid, new CallInvite(callInviteInfo, CallInvite.State.Pending)]));
315
+ return callInvitesMap;
316
+ }
317
+ /**
318
+ * Handle Firebase messages from an out-of-band Firebase messaging service.
319
+ *
320
+ * @remarks
321
+ *
322
+ * Note that this method only works on Android platforms, and will only work
323
+ * when the built-in Firebase messaging service as been opted-out.
324
+ *
325
+ * Unsupported platforms:
326
+ * - iOS
327
+ *
328
+ * @returns
329
+ * A `Promise` that
330
+ * - Resolves with a boolean. This boolean is `true` if the Firebase message
331
+ * was handled properly, `false` otherwise.
332
+ * - Rejects if an error occurred when parsing the Firebase message, or if
333
+ * the app is incorrectly configured. This method will also reject if used
334
+ * on an unsupported platform.
335
+ */
336
+
337
+
338
+ async handleFirebaseMessage(remoteMessage) {
339
+ switch (Platform.OS) {
340
+ case 'android':
341
+ break;
342
+
343
+ default:
344
+ throw new UnsupportedPlatformError(`Unsupported platform "${Platform.OS}". This method is only supported on Android.`);
345
+ }
346
+
347
+ return await NativeModule.voice_handleEvent(remoteMessage);
348
+ }
349
+ /**
350
+ * Register this device for incoming calls.
351
+ * @param token - A Twilio Access Token.
352
+ * @returns
353
+ * A `Promise` that
354
+ * - Resolves when the device has been registered.
355
+ */
356
+
357
+
358
+ register(token) {
359
+ return NativeModule.voice_register(token);
360
+ }
361
+ /**
362
+ * Unregister this device for incoming calls.
363
+ * @param token - A Twilio Access Token.
364
+ * @returns
365
+ * A `Promise` that
366
+ * - Resolves when the device has been unregistered.
367
+ */
368
+
369
+
370
+ unregister(token) {
371
+ return NativeModule.voice_unregister(token);
372
+ }
373
+ /**
374
+ * Get audio device information from the native layer.
375
+ * @returns
376
+ * A `Promise` that
377
+ * - Resolves with a list of the native device's audio devices and the
378
+ * currently selected device.
379
+ */
380
+
381
+
382
+ async getAudioDevices() {
383
+ const {
384
+ audioDevices: audioDeviceInfos,
385
+ selectedDevice: selectedDeviceInfo
386
+ } = await NativeModule.voice_getAudioDevices();
387
+ const audioDevices = audioDeviceInfos.map(audioDeviceInfo => new AudioDevice(audioDeviceInfo));
388
+ const selectedDevice = typeof selectedDeviceInfo !== 'undefined' ? new AudioDevice(selectedDeviceInfo) : undefined;
389
+ return selectedDevice ? {
390
+ audioDevices,
391
+ selectedDevice
392
+ } : {
393
+ audioDevices
394
+ };
395
+ }
396
+ /**
397
+ * Show the native AV route picker.
398
+ *
399
+ * @remarks
400
+ * Unsupported platforms:
401
+ * - Android
402
+ *
403
+ * This API is specific to iOS and unavailable in Android. If this API is
404
+ * invoked on Android, there will be no operation and the returned `Promise`
405
+ * will immediately resolve with `null`.
406
+ *
407
+ * @returns
408
+ * A `Promise` that
409
+ * - Resolves when the AV Route Picker View is shown.
410
+ */
411
+
412
+
413
+ showAvRoutePickerView() {
414
+ return NativeModule.voice_showNativeAvRoutePicker();
415
+ }
416
+ /**
417
+ * Initialize a Push Registry instance inside the SDK for handling
418
+ * PushKit device token updates and receiving push notifications.
419
+ *
420
+ * @remarks
421
+ * Unsupported platforms:
422
+ * - Android
423
+ *
424
+ * This API is specific to iOS and unavailable in Android.
425
+ * Use this method if the application does not have an iOS PushKit
426
+ * module and wishes to delegate the event handling to the SDK.
427
+ * Call this method upon launching the app to guarantee that incoming
428
+ * call push notifications will be surfaced to the users, especially when
429
+ * the app is not running in the foreground.
430
+ *
431
+ * @returns
432
+ * A `Promise` that
433
+ * - Resolves when the initialization is done.
434
+ */
435
+
436
+
437
+ async initializePushRegistry() {
438
+ switch (Platform.OS) {
439
+ case 'ios':
440
+ return NativeModule.voice_initializePushRegistry();
441
+
442
+ default:
443
+ throw new UnsupportedPlatformError(`Unsupported platform "${Platform.OS}". This method is only supported on iOS.`);
444
+ }
445
+ }
446
+ /**
447
+ * Custom iOS CallKit configuration.
448
+ *
449
+ * @param configuration - iOS CallKit configuration options.
450
+ *
451
+ * @remarks
452
+ * Unsupported platforms:
453
+ * - Android
454
+ *
455
+ * See {@link CallKit} for more information.
456
+ *
457
+ * @returns
458
+ * A `Promise` that
459
+ * - Resolves when the configuration has been applied.
460
+ * - Rejects if the configuration is unable to be applied.
461
+ */
462
+
463
+
464
+ async setCallKitConfiguration(configuration) {
465
+ switch (Platform.OS) {
466
+ case 'ios':
467
+ return NativeModule.voice_setCallKitConfiguration(configuration);
468
+
469
+ default:
470
+ throw new UnsupportedPlatformError(`Unsupported platform "${Platform.OS}". This method is only supported on iOS.`);
471
+ }
472
+ }
473
+ /**
474
+ * Set the native call contact handle template.
475
+ *
476
+ * This method is used to customize the displayed contact for Android
477
+ * notifications and the contact handle displayed in iOS CallKit UIs.
478
+ *
479
+ * @example
480
+ * ```ts
481
+ * await voice.setIncomingCallContactHandleTemplate('Foo ${DisplayName}');
482
+ * ```
483
+ * If an incoming call is made and there is a Twiml Parameter with key
484
+ * "DisplayName" and value "Bar", then the notification title or CallKit
485
+ * handle will display as "Foo Bar".
486
+ *
487
+ * @example
488
+ * ```ts
489
+ * await voice.setIncomingCallContactHandleTemplate();
490
+ * ```
491
+ * When invoking this method without any parameters, the template will be
492
+ * unset and the default notification and contact handle behavior is restored.
493
+ *
494
+ * @param template - The string to set the notification and contact handle
495
+ * template to. Note that this value is optional, if the method is invoked
496
+ * with an implicit undefined (no parameter) then the template will be unset
497
+ * and the default notification and contact handle behavior will be restored.
498
+ * Empty string values will be considered as the same as passing `undefined`.
499
+ *
500
+ * @returns
501
+ * A `Promise` that
502
+ * - Resolves with `undefined` if the template were set.
503
+ * - Rejects if the template was unable to be set.
504
+ */
505
+
506
+
507
+ async setIncomingCallContactHandleTemplate(template) {
508
+ await NativeModule.voice_setIncomingCallContactHandleTemplate(template);
509
+ }
510
+ /**
511
+ * Returns a boolean representing whether or not Android Full Screen
512
+ * notifications are enabled.
513
+ *
514
+ * @remarks
515
+ * Unsupported platforms:
516
+ * - iOS
517
+ *
518
+ * @returns
519
+ * A `Promise` that
520
+ * - Resolves `false` if either of the following is true:
521
+ * - Full Screen Notifications are disabled in your app's configuration.
522
+ * See `docs/disable-full-screen-notifications.md` for more info.
523
+ * - The app was not granted Full Screen Notification permissions by the
524
+ * operating system.
525
+ * - Resolves `true` if none of the above is true.
526
+ * - Rejects if the Android layer encountered an error.
527
+ */
528
+
529
+
530
+ async isFullScreenNotificationEnabled() {
531
+ switch (Platform.OS) {
532
+ case 'ios':
533
+ {
534
+ throw new UnsupportedPlatformError(`Unsupported platform "${Platform.OS}". This method is only supported on Android.`);
535
+ }
536
+ }
537
+
538
+ return NativeModule.system_isFullScreenNotificationEnabled();
539
+ }
540
+ /**
541
+ * Opens the Android System Settings app to attempt to request Full Screen
542
+ * Notification permissions.
543
+ *
544
+ * @remarks
545
+ * Unsupported platforms:
546
+ * - iOS
547
+ *
548
+ * @returns
549
+ * A `Promise` that
550
+ * - Resolves `void` if the Android System Settings app was opened.
551
+ * - Rejects if the Android system encountered an error while trying to open
552
+ * the System Settings app.
553
+ */
554
+
555
+
556
+ async requestFullScreenNotificationPermission() {
557
+ switch (Platform.OS) {
558
+ case 'ios':
559
+ {
560
+ throw new UnsupportedPlatformError(`Unsupported platform "${Platform.OS}". This method is only supported on Android.`);
561
+ }
562
+ }
563
+
564
+ return NativeModule.system_requestFullScreenNotificationPermission();
565
+ }
566
+
567
+ }
568
+ /**
569
+ * Provides enumerations and types used by {@link (Voice:class)
570
+ * | Voice objects}.
571
+ *
572
+ * @remarks
573
+ * - See also the {@link (Voice:class) | Voice class}.
574
+ * - See also the {@link (Voice:interface) | Voice interface}.
575
+ *
576
+ * @public
577
+ */
578
+
579
+ (function (_Voice) {
580
+ /**
581
+ * Options to pass to the {@link (Voice:class).connect} method.
582
+ */
583
+ let Event;
584
+
585
+ (function (Event) {
586
+ Event["AudioDevicesUpdated"] = "audioDevicesUpdated";
587
+ Event["CallInvite"] = "callInvite";
588
+ Event["Error"] = "error";
589
+ Event["Registered"] = "registered";
590
+ Event["Unregistered"] = "unregistered";
591
+ })(Event || (Event = {}));
592
+
593
+ _Voice.Event = Event;
594
+ let Listener;
595
+
596
+ (function (_Listener) {})(Listener || (Listener = _Voice.Listener || (_Voice.Listener = {})));
597
+ })(Voice || (Voice = {}));
598
+ //# sourceMappingURL=Voice.js.map