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
package/src/Voice.tsx ADDED
@@ -0,0 +1,1010 @@
1
+ /**
2
+ * Copyright © 2022 Twilio, Inc. All rights reserved. Licensed under the Twilio
3
+ * license.
4
+ *
5
+ * See LICENSE in the project root for license information.
6
+ */
7
+
8
+ import { EventEmitter } from 'eventemitter3';
9
+ import { AudioDevice } from './AudioDevice';
10
+ import { Call } from './Call';
11
+ import { CallInvite } from './CallInvite';
12
+ import { NativeEventEmitter, NativeModule, Platform } from './common';
13
+ import { Constants } from './constants';
14
+ import { InvalidArgumentError } from './error/InvalidArgumentError';
15
+ import type { TwilioError } from './error/TwilioError';
16
+ import { UnsupportedPlatformError } from './error/UnsupportedPlatformError';
17
+ import { constructTwilioError } from './error/utility';
18
+ import type { NativeAudioDeviceInfo } from './type/AudioDevice';
19
+ import type { NativeCallInfo } from './type/Call';
20
+ import type { NativeCallInviteInfo } from './type/CallInvite';
21
+ import type { CallKit } from './type/CallKit';
22
+ import type { CustomParameters, Uuid } from './type/common';
23
+ import type { NativeVoiceEvent, NativeVoiceEventType } from './type/Voice';
24
+
25
+ /**
26
+ * Defines strict typings for all events emitted by {@link (Voice:class)
27
+ * | Voice objects}.
28
+ *
29
+ * @remarks
30
+ * Note that the `on` function is an alias for the `addListener` function.
31
+ * They share identical functionality and either may be used interchangeably.
32
+ *
33
+ * - See also the {@link (Voice:class) | Voice class}.
34
+ * - See also the {@link (Voice:namespace) | Voice namespace}.
35
+ *
36
+ * @public
37
+ */
38
+ export declare interface Voice {
39
+ /**
40
+ * ------------
41
+ * Emit Typings
42
+ * ------------
43
+ */
44
+
45
+ /** @internal */
46
+ emit(
47
+ voiceEvent: Voice.Event.AudioDevicesUpdated,
48
+ audioDevices: AudioDevice[],
49
+ selectedDevice?: AudioDevice
50
+ ): boolean;
51
+
52
+ /** @internal */
53
+ emit(voiceEvent: Voice.Event.CallInvite, callInvite: CallInvite): boolean;
54
+
55
+ /** @internal */
56
+ emit(voiceEvent: Voice.Event.Error, error: TwilioError): boolean;
57
+
58
+ /** @internal */
59
+ emit(voiceEvent: Voice.Event.Registered): boolean;
60
+
61
+ /** @internal */
62
+ emit(voiceEvent: Voice.Event.Unregistered): boolean;
63
+
64
+ /** @internal */
65
+ emit(voiceEvent: Voice.Event, ...args: any[]): boolean;
66
+
67
+ /**
68
+ * ----------------
69
+ * Listener Typings
70
+ * ----------------
71
+ */
72
+
73
+ /**
74
+ * Audio devices updated event. Raised when the list of audio devices changes.
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * voice.addListener(Voice.Event.AudioDevicesUpdated, () => {
79
+ * // the list of available audio devices has changed and/or the selected
80
+ * // audio device has been changed
81
+ * });
82
+ * ```
83
+ *
84
+ * @param audioDevicesUpdatedEvent - The raised event string.
85
+ * @param listener - A listener function that will be invoked when the event
86
+ * is raised.
87
+ * @returns - The call object.
88
+ */
89
+ addListener(
90
+ audioDevicesUpdatedEvent: Voice.Event.AudioDevicesUpdated,
91
+ listener: Voice.Listener.AudioDevicesUpdated
92
+ ): this;
93
+ /** {@inheritDoc (Voice:interface).(addListener:1)} */
94
+ on(
95
+ audioDevicesUpdatedEvent: Voice.Event.AudioDevicesUpdated,
96
+ listener: Voice.Listener.AudioDevicesUpdated
97
+ ): this;
98
+
99
+ /**
100
+ * Call invite event. Raised when an incoming call invite is received.
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * voice.addListener(Voice.Event.CallInvite, (callInvite: CallInvite) => {
105
+ * // handle the incoming call invite
106
+ * });
107
+ * ```
108
+ *
109
+ * @param callInviteEvent - The raised event string.
110
+ * @param listener - A listener function that will be invoked when the event
111
+ * is raised.
112
+ * @returns - The call object.
113
+ */
114
+ addListener(
115
+ callInviteEvent: Voice.Event.CallInvite,
116
+ listener: Voice.Listener.CallInvite
117
+ ): this;
118
+ /** {@inheritDoc (Voice:interface).(addListener:2)} */
119
+ on(
120
+ callInviteEvent: Voice.Event.CallInvite,
121
+ listener: Voice.Listener.CallInvite
122
+ ): this;
123
+
124
+ /**
125
+ * Error event. Raised when the SDK encounters an error.
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * voice.addListener(Voice.Event.Error, (error: TwilioError.GenericError) => {
130
+ * // handle a generic Voice SDK error
131
+ * });
132
+ * ```
133
+ *
134
+ * @param errorEvent - The raised event string.
135
+ * @param listener - A listener function that will be invoked when the event
136
+ * is raised.
137
+ * @returns - The call object.
138
+ */
139
+ addListener(
140
+ errorEvent: Voice.Event.Error,
141
+ listener: Voice.Listener.Error
142
+ ): this;
143
+ /** {@inheritDoc (Voice:interface).(addListener:3)} */
144
+ on(errorEvent: Voice.Event.Error, listener: Voice.Listener.Error): this;
145
+
146
+ /**
147
+ * Registered event. Raised when the SDK is registered for incoming calls.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * voice.addListener(Voice.Event.Registered, () => {
152
+ * // handle successful registration for incoming calls
153
+ * });
154
+ * ```
155
+ *
156
+ * @param registeredEvent - The raised event string.
157
+ * @param listener - A listener function that will be invoked when the event
158
+ * is raised.
159
+ * @returns - The call object.
160
+ */
161
+ addListener(
162
+ registeredEvent: Voice.Event.Registered,
163
+ listener: Voice.Listener.Registered
164
+ ): this;
165
+ /** {@inheritDoc (Voice:interface).(addListener:4)} */
166
+ on(
167
+ registeredEvent: Voice.Event.Registered,
168
+ listener: Voice.Listener.Registered
169
+ ): this;
170
+
171
+ /**
172
+ * Unregistered event. Raised when the SDK is unregistered for incoming calls.
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * voice.addListener(Voice.Event.Unregistered, () => {
177
+ * // handle successful unregistration for incoming calls
178
+ * });
179
+ * ```
180
+ *
181
+ * @param unregisteredEvent - The raised event string.
182
+ * @param listener - A listener function that will be invoked when the event
183
+ * is raised.
184
+ * @returns - The call object.
185
+ */
186
+ addListener(
187
+ unregisteredEvent: Voice.Event.Unregistered,
188
+ listener: Voice.Listener.Unregistered
189
+ ): this;
190
+ /** {@inheritDoc (Voice:interface).(addListener:5)} */
191
+ on(
192
+ unregisteredEvent: Voice.Event.Unregistered,
193
+ listener: Voice.Listener.Unregistered
194
+ ): this;
195
+
196
+ /**
197
+ * Generic event listener typings.
198
+ * @param voiceEvent - The raised event string.
199
+ * @param listener - A listener function that will be invoked when the event
200
+ * is raised.
201
+ * @returns - The call object.
202
+ */
203
+ addListener(voiceEvent: Voice.Event, listener: Voice.Listener.Generic): this;
204
+ /** {@inheritDoc (Voice:interface).(addListener:6)} */
205
+ on(voiceEvent: Voice.Event, listener: Voice.Listener.Generic): this;
206
+ }
207
+
208
+ /**
209
+ * Main entry-point of the Voice SDK. Provides access to the entire feature-set
210
+ * of the library.
211
+ *
212
+ * @example
213
+ * Usage:
214
+ * ```
215
+ * const token = '...';
216
+ *
217
+ * const voice = new Voice();
218
+ *
219
+ * voice.on(Voice.Event.CallInvite, (callInvite: CallInvite) => {
220
+ * callInvite.accept();
221
+ * });
222
+ *
223
+ * voice.register(token);
224
+ * ```
225
+ *
226
+ * @remarks
227
+ * - See also the {@link (Voice:namespace).Event} enum for events emitted by
228
+ * `Voice` objects.
229
+ * - See also the {@link (Voice:interface) | Voice interface} for events
230
+ * emitted by this class and associated types.
231
+ * - See also the {@link (Voice:namespace) | Voice namespace} for types and
232
+ * enumerations used by this class.
233
+ *
234
+ * @public
235
+ */
236
+ export class Voice extends EventEmitter {
237
+ /**
238
+ * Handlers for native voice events. Set upon construction so we can
239
+ * dynamically bind events to handlers.
240
+ *
241
+ * @privateRemarks
242
+ * This is done by the constructor so this mapping isn't made every time the
243
+ * {@link (Voice:class)._handleNativeEvent} function is invoked.
244
+ */
245
+ private _nativeEventHandler: Record<
246
+ NativeVoiceEventType,
247
+ (voiceEvent: NativeVoiceEvent) => void
248
+ >;
249
+
250
+ /**
251
+ * Main entry-point of the Voice SDK. Provides access to the entire
252
+ * feature-set of the library.
253
+ */
254
+ constructor() {
255
+ super();
256
+
257
+ this._nativeEventHandler = {
258
+ /**
259
+ * Common
260
+ */
261
+ [Constants.VoiceEventError]: this._handleError,
262
+
263
+ /**
264
+ * Call Invite
265
+ */
266
+ [Constants.VoiceEventTypeValueIncomingCallInvite]: this._handleCallInvite,
267
+
268
+ /**
269
+ * Registration
270
+ */
271
+ [Constants.VoiceEventRegistered]: this._handleRegistered,
272
+ [Constants.VoiceEventUnregistered]: this._handleUnregistered,
273
+
274
+ /**
275
+ * Audio Devices
276
+ */
277
+ [Constants.VoiceEventAudioDevicesUpdated]:
278
+ this._handleAudioDevicesUpdated,
279
+ };
280
+
281
+ NativeEventEmitter.addListener(
282
+ Constants.ScopeVoice,
283
+ this._handleNativeEvent
284
+ );
285
+ }
286
+
287
+ /**
288
+ * Connect for devices on Android platforms.
289
+ */
290
+ private async _connect_android(
291
+ token: string,
292
+ params: CustomParameters,
293
+ notificationDisplayName: string | undefined
294
+ ) {
295
+ const connectResult = await NativeModule.voice_connect_android(
296
+ token,
297
+ params,
298
+ notificationDisplayName
299
+ )
300
+ .then((callInfo) => {
301
+ return { type: 'ok', callInfo } as const;
302
+ })
303
+ .catch((error) => {
304
+ const code = error.userInfo.code;
305
+ const message = error.userInfo.message;
306
+ return { type: 'err', message, code } as const;
307
+ });
308
+
309
+ if (connectResult.type === 'err') {
310
+ throw constructTwilioError(connectResult.message, connectResult.code);
311
+ }
312
+
313
+ return new Call(connectResult.callInfo);
314
+ }
315
+
316
+ /**
317
+ * Connect for devices on iOS platforms.
318
+ */
319
+ private async _connect_ios(
320
+ token: string,
321
+ params: CustomParameters,
322
+ contactHandle: string
323
+ ) {
324
+ const parsedContactHandle =
325
+ contactHandle === '' ? 'Default Contact' : contactHandle;
326
+ const callInfo = await NativeModule.voice_connect_ios(
327
+ token,
328
+ params,
329
+ parsedContactHandle
330
+ );
331
+ return new Call(callInfo);
332
+ }
333
+
334
+ /**
335
+ * Intermediary event handler for `Voice`-level events. Ensures that the type
336
+ * of the incoming event is expected and invokes the proper event listener.
337
+ * @param nativeVoiceEvent - A `Voice` event directly from the native layer.
338
+ */
339
+ private _handleNativeEvent = (nativeVoiceEvent: NativeVoiceEvent) => {
340
+ const { type } = nativeVoiceEvent;
341
+
342
+ const handler = this._nativeEventHandler[type];
343
+ if (typeof handler === 'undefined') {
344
+ throw new Error(
345
+ `Unknown voice event type received from the native layer: "${type}".`
346
+ );
347
+ }
348
+
349
+ handler(nativeVoiceEvent);
350
+ };
351
+
352
+ /**
353
+ * Call invite handler. Creates a {@link (CallInvite:class)} from the info
354
+ * raised by the native layer and emits it.
355
+ * @param nativeVoiceEvent - A `Voice` event directly from the native layer.
356
+ */
357
+ private _handleCallInvite = (nativeVoiceEvent: NativeVoiceEvent) => {
358
+ if (
359
+ nativeVoiceEvent.type !== Constants.VoiceEventTypeValueIncomingCallInvite
360
+ ) {
361
+ throw new Error(
362
+ 'Incorrect "voice#callInvite" handler called for type ' +
363
+ `"${nativeVoiceEvent.type}".`
364
+ );
365
+ }
366
+
367
+ const { callInvite: callInviteInfo } = nativeVoiceEvent;
368
+
369
+ const callInvite = new CallInvite(callInviteInfo, CallInvite.State.Pending);
370
+
371
+ this.emit(Voice.Event.CallInvite, callInvite);
372
+ };
373
+
374
+ /**
375
+ * Error event handler. Creates an error from the namespace
376
+ * {@link TwilioErrors} from the info raised by the native layer and emits it.
377
+ * @param nativeVoiceEvent - A `Voice` event directly from the native layer.
378
+ */
379
+ private _handleError = (nativeVoiceEvent: NativeVoiceEvent) => {
380
+ if (nativeVoiceEvent.type !== Constants.VoiceEventError) {
381
+ throw new Error(
382
+ 'Incorrect "voice#error" handler called for type ' +
383
+ `"${nativeVoiceEvent.type}".`
384
+ );
385
+ }
386
+
387
+ const {
388
+ error: { code, message },
389
+ } = nativeVoiceEvent;
390
+ const error = constructTwilioError(message, code);
391
+ this.emit(Voice.Event.Error, error);
392
+ };
393
+
394
+ /**
395
+ * Registered event handler. Emits a
396
+ * {@link (Voice:namespace).Event.Registered} event.
397
+ */
398
+ private _handleRegistered = (nativeVoiceEvent: NativeVoiceEvent) => {
399
+ if (nativeVoiceEvent.type !== Constants.VoiceEventRegistered) {
400
+ throw new Error(
401
+ 'Incorrect "voice#error" handler called for type ' +
402
+ `"${nativeVoiceEvent.type}".`
403
+ );
404
+ }
405
+
406
+ this.emit(Voice.Event.Registered);
407
+ };
408
+
409
+ /**
410
+ * Unregistered event handler. Emits a
411
+ * {@link (Voice:namespace).Event.Unregistered} event.
412
+ */
413
+ private _handleUnregistered = (nativeVoiceEvent: NativeVoiceEvent) => {
414
+ if (nativeVoiceEvent.type !== Constants.VoiceEventUnregistered) {
415
+ throw new Error(
416
+ 'Incorrect "voice#error" handler called for type ' +
417
+ `"${nativeVoiceEvent.type}".`
418
+ );
419
+ }
420
+
421
+ this.emit(Voice.Event.Unregistered);
422
+ };
423
+
424
+ /**
425
+ * Audio devices updated event handler. Generates a new list of
426
+ * {@link (AudioDevice:class) | AudioDevice objects} and emits it.
427
+ * @param nativeVoiceEvent - A `Voice` event directly from the native layer.
428
+ */
429
+ private _handleAudioDevicesUpdated = (nativeVoiceEvent: NativeVoiceEvent) => {
430
+ if (nativeVoiceEvent.type !== Constants.VoiceEventAudioDevicesUpdated) {
431
+ throw new Error(
432
+ 'Incorrect "voice#audioDevicesUpdated" handler called for type ' +
433
+ `"${nativeVoiceEvent.type}".`
434
+ );
435
+ }
436
+
437
+ const {
438
+ audioDevices: audioDeviceInfos,
439
+ selectedDevice: selectedDeviceInfo,
440
+ } = nativeVoiceEvent;
441
+
442
+ const audioDevices = audioDeviceInfos.map(
443
+ (audioDeviceInfo: NativeAudioDeviceInfo) =>
444
+ new AudioDevice(audioDeviceInfo)
445
+ );
446
+
447
+ const selectedDevice =
448
+ typeof selectedDeviceInfo !== 'undefined' && selectedDeviceInfo !== null
449
+ ? new AudioDevice(selectedDeviceInfo)
450
+ : undefined;
451
+
452
+ this.emit(Voice.Event.AudioDevicesUpdated, audioDevices, selectedDevice);
453
+ };
454
+
455
+ /**
456
+ * Create an outgoing call.
457
+ *
458
+ * @remarks
459
+ * Note that the resolution of the returned `Promise` does not imply any call
460
+ * event occurring, such as answered or rejected.
461
+ * The `contactHandle` parameter is only required for iOS apps. Currently the
462
+ * parameter does have any effect on Android apps and can be ignored.
463
+ * `Default Contact` will appear in the iOS call history if the value is empty
464
+ * or not provided.
465
+ *
466
+ * @param token - A Twilio Access Token, usually minted by an
467
+ * authentication-gated endpoint using a Twilio helper library.
468
+ * @param options - Connect options.
469
+ * See {@link (Voice:namespace).ConnectOptions}.
470
+ *
471
+ * @returns
472
+ * A `Promise` that
473
+ * - Resolves with a call when the call is created.
474
+ * - Rejects:
475
+ * * When a call is not able to be created on the native layer.
476
+ * * With an {@link TwilioErrors.InvalidArgumentError} when invalid
477
+ * arguments are passed.
478
+ */
479
+ async connect(
480
+ token: string,
481
+ {
482
+ contactHandle = 'Default Contact',
483
+ notificationDisplayName = undefined,
484
+ params = {},
485
+ }: Voice.ConnectOptions = {}
486
+ ): Promise<Call> {
487
+ if (typeof token !== 'string') {
488
+ throw new InvalidArgumentError(
489
+ 'Argument "token" must be of type "string".'
490
+ );
491
+ }
492
+
493
+ if (typeof contactHandle !== 'string') {
494
+ throw new InvalidArgumentError(
495
+ 'Optional argument "contactHandle" must be undefined or of type' +
496
+ ' "string".'
497
+ );
498
+ }
499
+
500
+ if (typeof params !== 'object') {
501
+ throw new InvalidArgumentError(
502
+ 'Optional argument "params" must be undefined or of type "object".'
503
+ );
504
+ }
505
+
506
+ for (const [key, value] of Object.entries(params)) {
507
+ if (typeof value !== 'string') {
508
+ throw new InvalidArgumentError(
509
+ `Voice.ConnectOptions.params["${key}"] must be of type string`
510
+ );
511
+ }
512
+ }
513
+
514
+ switch (Platform.OS) {
515
+ case 'ios':
516
+ return this._connect_ios(token, params, contactHandle);
517
+ case 'android':
518
+ return this._connect_android(token, params, notificationDisplayName);
519
+ default:
520
+ throw new UnsupportedPlatformError(
521
+ `Unsupported platform "${Platform.OS}". Expected "android" or "ios".`
522
+ );
523
+ }
524
+ }
525
+
526
+ /**
527
+ * Get the version of the native SDK. Note that this is not the version of the
528
+ * React Native SDK, this is the version of the mobile SDK that the RN SDK is
529
+ * utilizing.
530
+ * @returns
531
+ * A `Promise` that
532
+ * - Resolves with a string representing the version of the native SDK.
533
+ */
534
+ getVersion(): Promise<string> {
535
+ return NativeModule.voice_getVersion();
536
+ }
537
+
538
+ /**
539
+ * Get the Device token from the native layer.
540
+ * @returns a Promise that resolves with a string representing the Device
541
+ * token.
542
+ */
543
+ getDeviceToken(): Promise<string> {
544
+ return NativeModule.voice_getDeviceToken();
545
+ }
546
+
547
+ /**
548
+ * Get a list of existing calls, ongoing and pending. This will not return any
549
+ * call that has finished.
550
+ * @returns
551
+ * A `Promise` that
552
+ * - Resolves with a mapping of `Uuid`s to {@link (Call:class)}s.
553
+ */
554
+ async getCalls(): Promise<ReadonlyMap<Uuid, Call>> {
555
+ const callInfos = await NativeModule.voice_getCalls();
556
+ const callsMap = new Map<Uuid, Call>(
557
+ callInfos.map((callInfo: NativeCallInfo) => [
558
+ callInfo.uuid,
559
+ new Call(callInfo),
560
+ ])
561
+ );
562
+ return callsMap;
563
+ }
564
+
565
+ /**
566
+ * Get a list of pending call invites.
567
+ *
568
+ * @remarks
569
+ * This list will not contain any call invites that have been "settled"
570
+ * (answered or rejected).
571
+ *
572
+ * @returns
573
+ * A `Promise` that
574
+ * - Resolves with a mapping of `Uuid`s to {@link (CallInvite:class)}s.
575
+ */
576
+ async getCallInvites(): Promise<ReadonlyMap<Uuid, CallInvite>> {
577
+ const callInviteInfos = await NativeModule.voice_getCallInvites();
578
+ const callInvitesMap = new Map<Uuid, CallInvite>(
579
+ callInviteInfos.map((callInviteInfo: NativeCallInviteInfo) => [
580
+ callInviteInfo.uuid,
581
+ new CallInvite(callInviteInfo, CallInvite.State.Pending),
582
+ ])
583
+ );
584
+ return callInvitesMap;
585
+ }
586
+
587
+ /**
588
+ * Handle Firebase messages from an out-of-band Firebase messaging service.
589
+ *
590
+ * @remarks
591
+ *
592
+ * Note that this method only works on Android platforms, and will only work
593
+ * when the built-in Firebase messaging service as been opted-out.
594
+ *
595
+ * Unsupported platforms:
596
+ * - iOS
597
+ *
598
+ * @returns
599
+ * A `Promise` that
600
+ * - Resolves with a boolean. This boolean is `true` if the Firebase message
601
+ * was handled properly, `false` otherwise.
602
+ * - Rejects if an error occurred when parsing the Firebase message, or if
603
+ * the app is incorrectly configured. This method will also reject if used
604
+ * on an unsupported platform.
605
+ */
606
+ async handleFirebaseMessage(remoteMessage: Record<string, string>) {
607
+ switch (Platform.OS) {
608
+ case 'android':
609
+ break;
610
+ default:
611
+ throw new UnsupportedPlatformError(
612
+ `Unsupported platform "${Platform.OS}". This method is only supported on Android.`
613
+ );
614
+ }
615
+
616
+ return await NativeModule.voice_handleEvent(remoteMessage);
617
+ }
618
+
619
+ /**
620
+ * Register this device for incoming calls.
621
+ * @param token - A Twilio Access Token.
622
+ * @returns
623
+ * A `Promise` that
624
+ * - Resolves when the device has been registered.
625
+ */
626
+ register(token: string): Promise<void> {
627
+ return NativeModule.voice_register(token);
628
+ }
629
+
630
+ /**
631
+ * Unregister this device for incoming calls.
632
+ * @param token - A Twilio Access Token.
633
+ * @returns
634
+ * A `Promise` that
635
+ * - Resolves when the device has been unregistered.
636
+ */
637
+ unregister(token: string): Promise<void> {
638
+ return NativeModule.voice_unregister(token);
639
+ }
640
+
641
+ /**
642
+ * Get audio device information from the native layer.
643
+ * @returns
644
+ * A `Promise` that
645
+ * - Resolves with a list of the native device's audio devices and the
646
+ * currently selected device.
647
+ */
648
+ async getAudioDevices(): Promise<{
649
+ audioDevices: AudioDevice[];
650
+ selectedDevice?: AudioDevice;
651
+ }> {
652
+ const {
653
+ audioDevices: audioDeviceInfos,
654
+ selectedDevice: selectedDeviceInfo,
655
+ } = await NativeModule.voice_getAudioDevices();
656
+
657
+ const audioDevices = audioDeviceInfos.map(
658
+ (audioDeviceInfo: NativeAudioDeviceInfo) =>
659
+ new AudioDevice(audioDeviceInfo)
660
+ );
661
+
662
+ const selectedDevice =
663
+ typeof selectedDeviceInfo !== 'undefined'
664
+ ? new AudioDevice(selectedDeviceInfo)
665
+ : undefined;
666
+
667
+ return selectedDevice ? { audioDevices, selectedDevice } : { audioDevices };
668
+ }
669
+
670
+ /**
671
+ * Show the native AV route picker.
672
+ *
673
+ * @remarks
674
+ * Unsupported platforms:
675
+ * - Android
676
+ *
677
+ * This API is specific to iOS and unavailable in Android. If this API is
678
+ * invoked on Android, there will be no operation and the returned `Promise`
679
+ * will immediately resolve with `null`.
680
+ *
681
+ * @returns
682
+ * A `Promise` that
683
+ * - Resolves when the AV Route Picker View is shown.
684
+ */
685
+ showAvRoutePickerView(): Promise<void> {
686
+ return NativeModule.voice_showNativeAvRoutePicker();
687
+ }
688
+
689
+ /**
690
+ * Initialize a Push Registry instance inside the SDK for handling
691
+ * PushKit device token updates and receiving push notifications.
692
+ *
693
+ * @remarks
694
+ * Unsupported platforms:
695
+ * - Android
696
+ *
697
+ * This API is specific to iOS and unavailable in Android.
698
+ * Use this method if the application does not have an iOS PushKit
699
+ * module and wishes to delegate the event handling to the SDK.
700
+ * Call this method upon launching the app to guarantee that incoming
701
+ * call push notifications will be surfaced to the users, especially when
702
+ * the app is not running in the foreground.
703
+ *
704
+ * @returns
705
+ * A `Promise` that
706
+ * - Resolves when the initialization is done.
707
+ */
708
+ async initializePushRegistry(): Promise<void> {
709
+ switch (Platform.OS) {
710
+ case 'ios':
711
+ return NativeModule.voice_initializePushRegistry();
712
+ default:
713
+ throw new UnsupportedPlatformError(
714
+ `Unsupported platform "${Platform.OS}". This method is only supported on iOS.`
715
+ );
716
+ }
717
+ }
718
+
719
+ /**
720
+ * Custom iOS CallKit configuration.
721
+ *
722
+ * @param configuration - iOS CallKit configuration options.
723
+ *
724
+ * @remarks
725
+ * Unsupported platforms:
726
+ * - Android
727
+ *
728
+ * See {@link CallKit} for more information.
729
+ *
730
+ * @returns
731
+ * A `Promise` that
732
+ * - Resolves when the configuration has been applied.
733
+ * - Rejects if the configuration is unable to be applied.
734
+ */
735
+ async setCallKitConfiguration(
736
+ configuration: CallKit.ConfigurationOptions
737
+ ): Promise<void> {
738
+ switch (Platform.OS) {
739
+ case 'ios':
740
+ return NativeModule.voice_setCallKitConfiguration(configuration);
741
+ default:
742
+ throw new UnsupportedPlatformError(
743
+ `Unsupported platform "${Platform.OS}". This method is only supported on iOS.`
744
+ );
745
+ }
746
+ }
747
+
748
+ /**
749
+ * Set the native call contact handle template.
750
+ *
751
+ * This method is used to customize the displayed contact for Android
752
+ * notifications and the contact handle displayed in iOS CallKit UIs.
753
+ *
754
+ * @example
755
+ * ```ts
756
+ * await voice.setIncomingCallContactHandleTemplate('Foo ${DisplayName}');
757
+ * ```
758
+ * If an incoming call is made and there is a Twiml Parameter with key
759
+ * "DisplayName" and value "Bar", then the notification title or CallKit
760
+ * handle will display as "Foo Bar".
761
+ *
762
+ * @example
763
+ * ```ts
764
+ * await voice.setIncomingCallContactHandleTemplate();
765
+ * ```
766
+ * When invoking this method without any parameters, the template will be
767
+ * unset and the default notification and contact handle behavior is restored.
768
+ *
769
+ * @param template - The string to set the notification and contact handle
770
+ * template to. Note that this value is optional, if the method is invoked
771
+ * with an implicit undefined (no parameter) then the template will be unset
772
+ * and the default notification and contact handle behavior will be restored.
773
+ * Empty string values will be considered as the same as passing `undefined`.
774
+ *
775
+ * @returns
776
+ * A `Promise` that
777
+ * - Resolves with `undefined` if the template were set.
778
+ * - Rejects if the template was unable to be set.
779
+ */
780
+ async setIncomingCallContactHandleTemplate(template?: string): Promise<void> {
781
+ await NativeModule.voice_setIncomingCallContactHandleTemplate(template);
782
+ }
783
+
784
+ /**
785
+ * Returns a boolean representing whether or not Android Full Screen
786
+ * notifications are enabled.
787
+ *
788
+ * @remarks
789
+ * Unsupported platforms:
790
+ * - iOS
791
+ *
792
+ * @returns
793
+ * A `Promise` that
794
+ * - Resolves `false` if either of the following is true:
795
+ * - Full Screen Notifications are disabled in your app's configuration.
796
+ * See `docs/disable-full-screen-notifications.md` for more info.
797
+ * - The app was not granted Full Screen Notification permissions by the
798
+ * operating system.
799
+ * - Resolves `true` if none of the above is true.
800
+ * - Rejects if the Android layer encountered an error.
801
+ */
802
+ async isFullScreenNotificationEnabled(): Promise<boolean> {
803
+ switch (Platform.OS) {
804
+ case 'ios': {
805
+ throw new UnsupportedPlatformError(
806
+ `Unsupported platform "${Platform.OS}". This method is only supported on Android.`
807
+ );
808
+ }
809
+ }
810
+
811
+ return NativeModule.system_isFullScreenNotificationEnabled();
812
+ }
813
+
814
+ /**
815
+ * Opens the Android System Settings app to attempt to request Full Screen
816
+ * Notification permissions.
817
+ *
818
+ * @remarks
819
+ * Unsupported platforms:
820
+ * - iOS
821
+ *
822
+ * @returns
823
+ * A `Promise` that
824
+ * - Resolves `void` if the Android System Settings app was opened.
825
+ * - Rejects if the Android system encountered an error while trying to open
826
+ * the System Settings app.
827
+ */
828
+ async requestFullScreenNotificationPermission(): Promise<void> {
829
+ switch (Platform.OS) {
830
+ case 'ios': {
831
+ throw new UnsupportedPlatformError(
832
+ `Unsupported platform "${Platform.OS}". This method is only supported on Android.`
833
+ );
834
+ }
835
+ }
836
+
837
+ return NativeModule.system_requestFullScreenNotificationPermission();
838
+ }
839
+ }
840
+
841
+ /**
842
+ * Provides enumerations and types used by {@link (Voice:class)
843
+ * | Voice objects}.
844
+ *
845
+ * @remarks
846
+ * - See also the {@link (Voice:class) | Voice class}.
847
+ * - See also the {@link (Voice:interface) | Voice interface}.
848
+ *
849
+ * @public
850
+ */
851
+ export namespace Voice {
852
+ /**
853
+ * Options to pass to the {@link (Voice:class).connect} method.
854
+ */
855
+ export type ConnectOptions = {
856
+ /**
857
+ * Custom parameters to send to the TwiML Application.
858
+ */
859
+ params?: Record<string, string>;
860
+ /**
861
+ * A CallKit display name that will show in the call history as the contact
862
+ * handle.
863
+ *
864
+ * @remarks
865
+ * Unsupported platforms:
866
+ * - Android
867
+ */
868
+ contactHandle?: string;
869
+ /**
870
+ * The display name that will show in the Android notifications. Passing an
871
+ * empty string will be considered the same as if `undefined` were passed.
872
+ *
873
+ * @remarks
874
+ * Unsupported platforms:
875
+ * - iOS
876
+ */
877
+ notificationDisplayName?: string;
878
+ };
879
+
880
+ /**
881
+ * Enumeration of all event strings emitted by {@link (Voice:class)} objects.
882
+ */
883
+ export enum Event {
884
+ /**
885
+ * Raised when there is a change in available audio devices.
886
+ *
887
+ * @remarks
888
+ *
889
+ * See {@link (Voice:interface).(addListener:1)
890
+ * | Voice.addListener(AudioDevicesUpdated)}.
891
+ */
892
+ 'AudioDevicesUpdated' = 'audioDevicesUpdated',
893
+
894
+ /**
895
+ * Raised when there is an incoming call invite.
896
+ *
897
+ * @remarks
898
+ *
899
+ * See {@link (Voice:interface).(addListener:2)
900
+ * | Voice.addListener(CallInvite)}.
901
+ */
902
+ 'CallInvite' = 'callInvite',
903
+
904
+ /**
905
+ * Raised when the SDK encounters an error.
906
+ *
907
+ * @remarks
908
+ *
909
+ * See {@link (Voice:interface).(addListener:3)
910
+ * | Voice.addListener(Error)}.
911
+ */
912
+ 'Error' = 'error',
913
+
914
+ /**
915
+ * Raised when the SDK is registered for incoming calls.
916
+ *
917
+ * @remarks
918
+ *
919
+ * See {@link (Voice:interface).(addListener:4)
920
+ * | Voice.addListener(Registered)}.
921
+ */
922
+ 'Registered' = 'registered',
923
+
924
+ /**
925
+ * Raised when the SDK is unregistered for incoming calls.
926
+ *
927
+ * @remarks
928
+ *
929
+ * See {@link (Voice:interface).(addListener:5)
930
+ * | Voice.addListener(Unregistered)}.
931
+ */
932
+ 'Unregistered' = 'unregistered',
933
+ }
934
+
935
+ /**
936
+ * Listener types for all events emitted by a {@link (Voice:class)
937
+ * | Voice object.}
938
+ */
939
+ export namespace Listener {
940
+ /**
941
+ * Audio devices updated event listener. This should be the function
942
+ * signature of an event listener bound to the
943
+ * {@link (Voice:namespace).Event.AudioDevicesUpdated} event.
944
+ *
945
+ * @remarks
946
+ *
947
+ * See {@link (Voice:interface).(addListener:1)}.
948
+ */
949
+ export type AudioDevicesUpdated = (
950
+ audioDevices: AudioDevice[],
951
+ selectedDevice?: AudioDevice
952
+ ) => void;
953
+
954
+ /**
955
+ * Call invite event listener. This should be the function signature of an
956
+ * event listener bound to the
957
+ * {@link (Voice:namespace).Event.CallInvite} event.
958
+ *
959
+ * @remarks
960
+ *
961
+ * See {@link (Voice:interface).(addListener:2)}.
962
+ */
963
+ export type CallInvite = (callInvite: CallInvite) => void;
964
+
965
+ /**
966
+ * Error event listener. This should be the function signature of an event
967
+ * listener bound to the
968
+ * {@link (Voice:namespace).Event.Error} event.
969
+ *
970
+ * @remarks
971
+ *
972
+ * See {@link (Voice:interface).(addListener:3)}.
973
+ *
974
+ * See {@link TwilioErrors} for all error classes.
975
+ */
976
+ export type Error = (error: TwilioError) => void;
977
+
978
+ /**
979
+ * Registered event listener. This should be the function signature of an
980
+ * event listener bound to the
981
+ * {@link (Voice:namespace).Event.Registered} event.
982
+ *
983
+ * @remarks
984
+ *
985
+ * See {@link (Voice:interface).(addListener:4)}.
986
+ */
987
+ export type Registered = () => void;
988
+
989
+ /**
990
+ * Unregistered event listener. This should be the function signature of an
991
+ * event listener bound to the
992
+ * {@link (Voice:namespace).Event.Unregistered} event.
993
+ *
994
+ * @remarks
995
+ *
996
+ * See {@link (Voice:interface).(addListener:5)}.
997
+ */
998
+ export type Unregistered = () => void;
999
+
1000
+ /**
1001
+ * Generic event listener. This should be the function signature of any
1002
+ * event listener bound to any voice event.
1003
+ *
1004
+ * @remarks
1005
+ *
1006
+ * See {@link (Voice:interface).(addListener:6)}.
1007
+ */
1008
+ export type Generic = (...args: any[]) => void;
1009
+ }
1010
+ }