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/Call.tsx ADDED
@@ -0,0 +1,1343 @@
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 type { RTCStats } from './';
10
+ import { NativeModule, NativeEventEmitter } from './common';
11
+ import { Constants } from './constants';
12
+ import type {
13
+ NativeCallEvent,
14
+ NativeCallEventType,
15
+ NativeCallInfo,
16
+ NativeCallFeedbackIssue,
17
+ NativeCallFeedbackScore,
18
+ } from './type/Call';
19
+ import type { CustomParameters, Uuid } from './type/common';
20
+ import type { TwilioError } from './error/TwilioError';
21
+ import { InvalidArgumentError } from './error/InvalidArgumentError';
22
+ import { constructTwilioError } from './error/utility';
23
+ import { CallMessage, validateCallMessage } from './CallMessage/CallMessage';
24
+ import { IncomingCallMessage } from './CallMessage/IncomingCallMessage';
25
+ import { OutgoingCallMessage } from './CallMessage/OutgoingCallMessage';
26
+
27
+ /**
28
+ * Defines strict typings for all events emitted by {@link (Call:class)
29
+ * | Call objects}.
30
+ *
31
+ * @remarks
32
+ * Note that the `on` function is an alias for the `addListener` function.
33
+ * They share identical functionality and either may be used interchangeably.
34
+ *
35
+ * - See also the {@link (Call:class) | Call class}.
36
+ * - See also the {@link (Call:namespace) | Call namespace}.
37
+ *
38
+ * @public
39
+ */
40
+ export declare interface Call {
41
+ /**
42
+ * ------------
43
+ * Emit Typings
44
+ * ------------
45
+ */
46
+
47
+ /** @internal */
48
+ emit(connectedEvent: Call.Event.Connected): boolean;
49
+
50
+ /** @internal */
51
+ emit(
52
+ connectFailureEvent: Call.Event.ConnectFailure,
53
+ error: TwilioError
54
+ ): boolean;
55
+
56
+ /** @internal */
57
+ emit(reconnectingEvent: Call.Event.Reconnecting, error: TwilioError): boolean;
58
+
59
+ /** @internal */
60
+ emit(reconnectedEvent: Call.Event.Reconnected): boolean;
61
+
62
+ /** @internal */
63
+ emit(
64
+ disconnectedEvent: Call.Event.Disconnected,
65
+ error?: TwilioError
66
+ ): boolean;
67
+
68
+ /** @internal */
69
+ emit(ringingEvent: Call.Event.Ringing): boolean;
70
+
71
+ /** @internal */
72
+ emit(
73
+ qualityWarningsChangedEvent: Call.Event.QualityWarningsChanged,
74
+ currentQualityWarnings: Call.QualityWarning[],
75
+ previousQualityWarnings: Call.QualityWarning[]
76
+ ): boolean;
77
+
78
+ /** @internal */
79
+ emit(
80
+ messageReceivedEvent: Call.Event.MessageReceived,
81
+ incomingCallMessage: IncomingCallMessage
82
+ ): boolean;
83
+
84
+ /**
85
+ * ----------------
86
+ * Listener Typings
87
+ * ----------------
88
+ */
89
+
90
+ /**
91
+ * Connected event. Raised when the call has successfully connected.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * call.addListener(Call.Event.Connected, () => {
96
+ * // call has been connected
97
+ * });
98
+ * ```
99
+ *
100
+ * @param connectedEvent - The raised event string.
101
+ * @param listener - A listener function that will be invoked when the event
102
+ * is raised.
103
+ * @returns - The call object.
104
+ */
105
+ addListener(
106
+ connectedEvent: Call.Event.Connected,
107
+ listener: Call.Listener.Connected
108
+ ): this;
109
+ /**
110
+ * {@inheritDoc (Call:interface).(addListener:1)}
111
+ */
112
+ on(
113
+ connectedEvent: Call.Event.Connected,
114
+ listener: Call.Listener.Connected
115
+ ): this;
116
+
117
+ /**
118
+ * Connect failure event. Raised when the call has failed to connect.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * call.addListener(Call.Event.ConnectFailure, (error) => {
123
+ * // call was unable to connect, handle error
124
+ * });
125
+ * ```
126
+ *
127
+ * @param connectFailureEvent - The raised event string.
128
+ * @param listener - A listener function that will be invoked when the event
129
+ * is raised.
130
+ * @returns - The call object.
131
+ */
132
+ addListener(
133
+ connectFailureEvent: Call.Event.ConnectFailure,
134
+ listener: Call.Listener.ConnectFailure
135
+ ): this;
136
+ /**
137
+ * {@inheritDoc (Call:interface).(addListener:2)}
138
+ */
139
+ on(
140
+ connectFailureEvent: Call.Event.ConnectFailure,
141
+ listener: Call.Listener.ConnectFailure
142
+ ): this;
143
+
144
+ /**
145
+ * Reconnecting event. Raised when the call is reconnecting.
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * call.addListener(Call.Event.Reconnecting, (error) => {
150
+ * // call is attempting to reconnect, handle error
151
+ * });
152
+ * ```
153
+ *
154
+ * @param reconnectingEvent - The raised event string.
155
+ * @param listener - A listener function that will be invoked when the event
156
+ * is raised.
157
+ * @returns - The call object.
158
+ */
159
+ addListener(
160
+ reconnectingEvent: Call.Event.Reconnecting,
161
+ listener: Call.Listener.Reconnecting
162
+ ): this;
163
+ /**
164
+ * {@inheritDoc (Call:interface).(addListener:3)}
165
+ */
166
+ on(
167
+ reconnectingEvent: Call.Event.Reconnecting,
168
+ listener: Call.Listener.Reconnecting
169
+ ): this;
170
+
171
+ /**
172
+ * Reconnected event. Raised when the call has recovered and reconnected.
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * call.addListener(Call.Event.Reconnected, () => {
177
+ * // call has reconnected
178
+ * });
179
+ * ```
180
+ *
181
+ * @param reconnectedEvent - 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
+ reconnectedEvent: Call.Event.Reconnected,
188
+ listener: Call.Listener.Reconnected
189
+ ): this;
190
+ /**
191
+ * {@inheritDoc (Call:interface).(addListener:4)}
192
+ */
193
+ on(
194
+ reconnectedEvent: Call.Event.Reconnected,
195
+ listener: Call.Listener.Reconnected
196
+ ): this;
197
+
198
+ /**
199
+ * Disconnected event. Raised when the call has disconnected.
200
+ *
201
+ * @remarks
202
+ * This event can occur in "naturally" disconnected calls and calls
203
+ * disconnected from issues such as network problems. If the SDK has detected
204
+ * an issue that has caused the call to disconnect, then the error parameter
205
+ * will be defined, otherwise it will be undefined.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * call.addListener(Call.Event.Disconnected, (error) => {
210
+ * // call has disconnected
211
+ * // if a natural disconnect occurred, then error is `undefined`
212
+ * // if an unnatural disconnect occurred, then error is defined
213
+ * });
214
+ * ```
215
+ *
216
+ * @param disconnectedEvent - The raised event string.
217
+ * @param listener - A listener function that will be invoked when the event
218
+ * is raised.
219
+ * @returns - The call object.
220
+ */
221
+ addListener(
222
+ disconnectedEvent: Call.Event.Disconnected,
223
+ listener: Call.Listener.Disconnected
224
+ ): this;
225
+ /**
226
+ * {@inheritDoc (Call:interface).(addListener:5)}
227
+ */
228
+ on(
229
+ disconnectedEvent: Call.Event.Disconnected,
230
+ listener: Call.Listener.Disconnected
231
+ ): this;
232
+
233
+ /**
234
+ * Ringing event. Raised when the call has begun to ring.
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * call.addListener(Call.Event.Ringing, () => {
239
+ * // call is ringing
240
+ * });
241
+ * ```
242
+ *
243
+ * @param ringingEvent - The raised event string.
244
+ * @param listener - A listener function that will be invoked when the event
245
+ * is raised.
246
+ * @returns - The call object.
247
+ */
248
+ addListener(
249
+ ringingEvent: Call.Event.Ringing,
250
+ listener: Call.Listener.Ringing
251
+ ): this;
252
+ /**
253
+ * {@inheritDoc (Call:interface).(addListener:6)}
254
+ */
255
+ on(ringingEvent: Call.Event.Ringing, listener: Call.Listener.Ringing): this;
256
+
257
+ /**
258
+ * Quality warnings changed event. Raised when a call quality warning is set
259
+ * or unset. All "ongoing" call quality warnings are passed to the invoked
260
+ * listener function.
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * call.addListener(
265
+ * Call.Event.QualityWarningsChanged,
266
+ * (
267
+ * currentWarnings: Call.QualityWarning[],
268
+ * previousWarnings: Call.QualityWarning[]
269
+ * ) => {
270
+ * // call quality warnings have changed
271
+ * }
272
+ * );
273
+ * ```
274
+ *
275
+ * @param qualityWarningsChangedEvent - The raised event string.
276
+ * @param listener - A listener function that will be invoked when the event
277
+ * is raised.
278
+ * @returns - The call object.
279
+ */
280
+ addListener(
281
+ qualityWarningsChangedEvent: Call.Event.QualityWarningsChanged,
282
+ listener: Call.Listener.QualityWarningsChanged
283
+ ): this;
284
+ /**
285
+ * {@inheritDoc (Call:interface).(addListener:7)}
286
+ */
287
+ on(
288
+ qualityWarningsChangedEvent: Call.Event.QualityWarningsChanged,
289
+ listener: Call.Listener.QualityWarningsChanged
290
+ ): this;
291
+
292
+ /**
293
+ * MessageReceived event. Raised when a {@link IncomingCallMessage} is
294
+ * received.
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * call.addListener(Call.Event.MessageReceived, (message) => {
299
+ * // callMessage received
300
+ * })
301
+ * ```
302
+ *
303
+ * @param messageReceivedEvent - The raised event string.
304
+ * @param listener - A listener function that will be invoked when the event
305
+ * is raised.
306
+ * @returns - The callMessage object
307
+ */
308
+ addListener(
309
+ messageReceivedEvent: Call.Event.MessageReceived,
310
+ listener: Call.Listener.MessageReceived
311
+ ): this;
312
+ /** {@inheritDoc (Call:interface).(addListener:8)} */
313
+ on(
314
+ callMessageEvent: Call.Event.MessageReceived,
315
+ listener: Call.Listener.MessageReceived
316
+ ): this;
317
+
318
+ /**
319
+ * Generic event listener typings.
320
+ * @param callEvent - The raised event string.
321
+ * @param listener - A listener function that will be invoked when the event
322
+ * is raised.
323
+ * @returns - The call object.
324
+ */
325
+ addListener(callEvent: Call.Event, listener: Call.Listener.Generic): this;
326
+ /**
327
+ * {@inheritDoc (Call:interface).(addListener:9)}
328
+ */
329
+ on(callEvent: Call.Event, listener: Call.Listener.Generic): this;
330
+ }
331
+
332
+ /**
333
+ * Provides access to information about a call, including the call parameters,
334
+ * and exposes functionality for a call such as disconnecting, muting, and
335
+ * holding.
336
+ *
337
+ * @remarks
338
+ * Note that the call information is fetched as soon as possible from the native
339
+ * layer, but there is no guarantee that all information is immediately
340
+ * available. Methods such as `Call.getFrom()` or `Call.getTo()` may return
341
+ * `undefined`.
342
+ *
343
+ * As call events are received from the native layer, call information will
344
+ * propagate from the native layer to the JS layer and become available.
345
+ * Therefore, it is good practice to read information from the call after an
346
+ * event occurs, or as events occur.
347
+ *
348
+ * - See the {@link (Call:namespace).Event} enum for events emitted by `Call`
349
+ * objects.
350
+ * - See the {@link (Call:interface) | Call interface} for overloaded event
351
+ * listening methods.
352
+ * - See the {@link (Call:namespace) | Call namespace} for types and
353
+ * enumerations used by this class.
354
+ *
355
+ * @public
356
+ */
357
+ export class Call extends EventEmitter {
358
+ /**
359
+ * The `Uuid` of this call. Used to identify calls between the JS and native
360
+ * layer so we can associate events and native functionality between the
361
+ * layers.
362
+ */
363
+ private _uuid: Uuid;
364
+ /**
365
+ * Call custom parameters.
366
+ */
367
+ private _customParameters: CustomParameters;
368
+ /**
369
+ * Call `from` parameter.
370
+ */
371
+ private _from?: string;
372
+ /**
373
+ * Initial `connected` timestamp. Milliseconds since epoch.
374
+ */
375
+ private _initialConnectedTimestamp?: Date;
376
+ /**
377
+ * A boolean representing if the call is currently muted.
378
+ */
379
+ private _isMuted?: boolean;
380
+ /**
381
+ * A boolean representing if the call is currently on hold.
382
+ */
383
+ private _isOnHold?: boolean;
384
+ /**
385
+ * A string representing the SID of this call.
386
+ */
387
+ private _sid?: string;
388
+ /**
389
+ * The current state of the call.
390
+ *
391
+ * @remarks
392
+ * See {@link (Call:namespace).State}.
393
+ */
394
+ private _state: Call.State;
395
+ /**
396
+ * Call `to` parameter.
397
+ */
398
+ private _to?: string;
399
+
400
+ /**
401
+ * Handlers for native call events. Set upon construction so we can
402
+ * dynamically bind events to handlers.
403
+ *
404
+ * @privateRemarks
405
+ * This is done by the constructor so this mapping isn't made every time the
406
+ * {@link (Call:class)._handleNativeEvent} function is invoked.
407
+ */
408
+ private _nativeEventHandler: Record<
409
+ NativeCallEventType,
410
+ (callEvent: NativeCallEvent) => void
411
+ >;
412
+
413
+ /**
414
+ * Constructor for the {@link (Call:class) | Call class}. This should not be
415
+ * invoked by third-party code. All instances of the
416
+ * {@link (Call:class) | Call class} should be made by the SDK and emitted by
417
+ * {@link (Voice:class) | Voice objects}.
418
+ *
419
+ * @param nativeCallInfo - An object containing all of the data from the
420
+ * native layer necessary to fully describe a call, as well as invoke native
421
+ * functionality for the call.
422
+ *
423
+ * @internal
424
+ */
425
+ constructor({
426
+ uuid,
427
+ customParameters,
428
+ from,
429
+ sid,
430
+ state,
431
+ to,
432
+ isMuted,
433
+ isOnHold,
434
+ initialConnectedTimestamp,
435
+ }: NativeCallInfo) {
436
+ super();
437
+
438
+ this._uuid = uuid;
439
+ this._customParameters = { ...customParameters };
440
+ this._from = from;
441
+ this._sid = sid;
442
+ this._state = typeof state === 'string' ? state : Call.State.Connecting;
443
+ this._to = to;
444
+ this._isMuted = isMuted;
445
+ this._isOnHold = isOnHold;
446
+ this._initialConnectedTimestamp = initialConnectedTimestamp
447
+ ? new Date(initialConnectedTimestamp)
448
+ : undefined;
449
+
450
+ this._nativeEventHandler = {
451
+ /**
452
+ * Call State
453
+ */
454
+ [Constants.CallEventConnected]: this._handleConnectedEvent,
455
+ [Constants.CallEventConnectFailure]: this._handleConnectFailureEvent,
456
+ [Constants.CallEventDisconnected]: this._handleDisconnectedEvent,
457
+ [Constants.CallEventReconnected]: this._handleReconnectedEvent,
458
+ [Constants.CallEventReconnecting]: this._handleReconnectingEvent,
459
+ [Constants.CallEventRinging]: this._handleRingingEvent,
460
+
461
+ /**
462
+ * Call Quality
463
+ */
464
+ [Constants.CallEventQualityWarningsChanged]:
465
+ this._handleQualityWarningsChangedEvent,
466
+
467
+ /**
468
+ * Call Message
469
+ */
470
+ [Constants.CallEventMessageReceived]: this._handleMessageReceivedEvent,
471
+ };
472
+
473
+ NativeEventEmitter.addListener(
474
+ Constants.ScopeCall,
475
+ this._handleNativeEvent
476
+ );
477
+ }
478
+
479
+ /**
480
+ * This intermediate native call event handler acts as a "gate", only
481
+ * executing the actual call event handler (such as `Connected`) if this call
482
+ * object matches the `Uuid` of the call that had an event raised.
483
+ * @param nativeCallEvent - A call event directly from the native layer.
484
+ */
485
+ private _handleNativeEvent = (nativeCallEvent: NativeCallEvent) => {
486
+ const { type, call: callInfo } = nativeCallEvent;
487
+
488
+ const handler = this._nativeEventHandler[type];
489
+ if (typeof handler === 'undefined') {
490
+ throw new Error(
491
+ `Unknown call event type received from the native layer: "${type}".`
492
+ );
493
+ }
494
+
495
+ if (callInfo.uuid === this._uuid) {
496
+ handler(nativeCallEvent);
497
+ }
498
+ };
499
+
500
+ /**
501
+ * Helper function to update the state of the call when a call event occurs
502
+ * that necessitates an update, i.e. upon a
503
+ * {@link (Call:namespace).Event.Connected | Connected event} we want to
504
+ * update the state of the call to also reflect the
505
+ * {@link (Call:namespace).State.Connected | Connected state}.
506
+ * @param nativeCallEvent - The native call event.
507
+ */
508
+ private _update({
509
+ type,
510
+ call: { from, initialConnectedTimestamp, sid, to },
511
+ }: NativeCallEvent) {
512
+ const newState = eventTypeStateMap[type];
513
+ if (typeof newState === 'string') {
514
+ this._state = newState;
515
+ }
516
+ this._from = from;
517
+ this._initialConnectedTimestamp = initialConnectedTimestamp
518
+ ? new Date(initialConnectedTimestamp)
519
+ : undefined;
520
+ this._sid = sid;
521
+ this._to = to;
522
+ }
523
+
524
+ /**
525
+ * Handler for the the {@link (Call:namespace).Event.Connected} event.
526
+ * @param nativeCallEvent - The native call event.
527
+ */
528
+ private _handleConnectedEvent = (nativeCallEvent: NativeCallEvent) => {
529
+ if (nativeCallEvent.type !== Constants.CallEventConnected) {
530
+ throw new Error(
531
+ 'Incorrect "call#connected" handler called for type ' +
532
+ `"${nativeCallEvent.type}".`
533
+ );
534
+ }
535
+
536
+ this._update(nativeCallEvent);
537
+
538
+ this.emit(Call.Event.Connected);
539
+ };
540
+
541
+ /**
542
+ * Handler for the the {@link (Call:namespace).Event.ConnectFailure} event.
543
+ * @param nativeCallEvent - The native call event.
544
+ */
545
+ private _handleConnectFailureEvent = (nativeCallEvent: NativeCallEvent) => {
546
+ if (nativeCallEvent.type !== Constants.CallEventConnectFailure) {
547
+ throw new Error(
548
+ 'Incorrect "call#connectFailure" handler called for type ' +
549
+ `"${nativeCallEvent.type}".`
550
+ );
551
+ }
552
+
553
+ this._update(nativeCallEvent);
554
+
555
+ const { message, code } = nativeCallEvent.error;
556
+ const error = constructTwilioError(message, code);
557
+ this.emit(Call.Event.ConnectFailure, error);
558
+ };
559
+
560
+ /**
561
+ * Handler for the the {@link (Call:namespace).Event.Disconnected} event.
562
+ * @param nativeCallEvent - The native call event.
563
+ */
564
+ private _handleDisconnectedEvent = (nativeCallEvent: NativeCallEvent) => {
565
+ if (nativeCallEvent.type !== Constants.CallEventDisconnected) {
566
+ throw new Error(
567
+ 'Incorrect "call#disconnected" handler called for type ' +
568
+ `"${nativeCallEvent.type}".`
569
+ );
570
+ }
571
+
572
+ this._update(nativeCallEvent);
573
+
574
+ if (nativeCallEvent.error) {
575
+ const { message, code } = nativeCallEvent.error;
576
+ const error = constructTwilioError(message, code);
577
+ this.emit(Call.Event.Disconnected, error);
578
+ } else {
579
+ this.emit(Call.Event.Disconnected);
580
+ }
581
+ };
582
+
583
+ /**
584
+ * Handler for the the {@link (Call:namespace).Event.Reconnecting} event.
585
+ * @param nativeCallEvent - The native call event.
586
+ */
587
+ private _handleReconnectingEvent = (nativeCallEvent: NativeCallEvent) => {
588
+ if (nativeCallEvent.type !== Constants.CallEventReconnecting) {
589
+ throw new Error(
590
+ 'Incorrect "call#reconnecting" handler called for type ' +
591
+ `"${nativeCallEvent.type}".`
592
+ );
593
+ }
594
+
595
+ this._update(nativeCallEvent);
596
+
597
+ const { message, code } = nativeCallEvent.error;
598
+ const error = constructTwilioError(message, code);
599
+ this.emit(Call.Event.Reconnecting, error);
600
+ };
601
+
602
+ /**
603
+ * Handler for the the {@link (Call:namespace).Event.Reconnected} event.
604
+ * @param nativeCallEvent - The native call event.
605
+ */
606
+ private _handleReconnectedEvent = (nativeCallEvent: NativeCallEvent) => {
607
+ if (nativeCallEvent.type !== Constants.CallEventReconnected) {
608
+ throw new Error(
609
+ 'Incorrect "call#reconnected" handler called for type ' +
610
+ `"${nativeCallEvent.type}".`
611
+ );
612
+ }
613
+
614
+ this._update(nativeCallEvent);
615
+
616
+ this.emit(Call.Event.Reconnected);
617
+ };
618
+
619
+ /**
620
+ * Handler for the the {@link (Call:namespace).Event.Ringing} event.
621
+ * @param nativeCallEvent - The native call event.
622
+ */
623
+ private _handleRingingEvent = (nativeCallEvent: NativeCallEvent) => {
624
+ if (nativeCallEvent.type !== Constants.CallEventRinging) {
625
+ throw new Error(
626
+ 'Incorrect "call#ringing" handler called for type ' +
627
+ `"${nativeCallEvent.type}".`
628
+ );
629
+ }
630
+
631
+ this._update(nativeCallEvent);
632
+
633
+ this.emit(Call.Event.Ringing);
634
+ };
635
+
636
+ /**
637
+ * Handler for the the {@link (Call:namespace).Event.QualityWarningsChanged}
638
+ * event.
639
+ * @param nativeCallEvent - The native call event.
640
+ */
641
+ private _handleQualityWarningsChangedEvent = (
642
+ nativeCallEvent: NativeCallEvent
643
+ ) => {
644
+ if (nativeCallEvent.type !== Constants.CallEventQualityWarningsChanged) {
645
+ throw new Error(
646
+ 'Incorrect "call#qualityWarnings" handler called for type ' +
647
+ `"${nativeCallEvent.type}".`
648
+ );
649
+ }
650
+
651
+ this._update(nativeCallEvent);
652
+
653
+ const currentWarnings = nativeCallEvent[Constants.CallEventCurrentWarnings];
654
+ const previousWarnings =
655
+ nativeCallEvent[Constants.CallEventPreviousWarnings];
656
+
657
+ this.emit(
658
+ Call.Event.QualityWarningsChanged,
659
+ currentWarnings as Call.QualityWarning[],
660
+ previousWarnings as Call.QualityWarning[]
661
+ );
662
+ };
663
+
664
+ /**
665
+ * Handler for the {@link (Call:namespace).Event.MessageReceived} event.
666
+ * @param nativeCallEvent - The native call event.
667
+ */
668
+ private _handleMessageReceivedEvent = (nativeCallEvent: NativeCallEvent) => {
669
+ if (nativeCallEvent.type !== Constants.CallEventMessageReceived) {
670
+ throw new Error(
671
+ 'Incorrect "call#Received" handler called for type' +
672
+ `"${nativeCallEvent.type}`
673
+ );
674
+ }
675
+
676
+ this._update(nativeCallEvent);
677
+
678
+ const { callMessage: callMessageInfo } = nativeCallEvent;
679
+
680
+ const incomingCallMessage = new IncomingCallMessage(callMessageInfo);
681
+
682
+ this.emit(Call.Event.MessageReceived, incomingCallMessage);
683
+ };
684
+
685
+ /**
686
+ * Disconnect this side of the call.
687
+ * @returns
688
+ * A `Promise` that
689
+ * - Resolves when the call has disconnected.
690
+ * - Rejects if the native layer cannot disconnect the call.
691
+ */
692
+ disconnect(): Promise<void> {
693
+ return NativeModule.call_disconnect(this._uuid);
694
+ }
695
+
696
+ /**
697
+ * Get the mute status of this side of the call.
698
+ * @returns
699
+ * - A boolean representing the muted status of the call.
700
+ * - `undefined` if the call state has not yet been received from the native
701
+ * layer.
702
+ */
703
+ isMuted(): boolean | undefined {
704
+ return this._isMuted;
705
+ }
706
+
707
+ /**
708
+ * Get the hold status of this side of the call.
709
+ * @returns
710
+ * - A boolean representing the hold status of the call.
711
+ * - `undefined` if the call state has not yet been received from the native
712
+ * layer.
713
+ */
714
+ isOnHold(): boolean | undefined {
715
+ return this._isOnHold;
716
+ }
717
+
718
+ /**
719
+ * Return a `Record` of custom parameters given to this call.
720
+ * @returns
721
+ * - A `Record` of custom parameters.
722
+ */
723
+ getCustomParameters(): CustomParameters {
724
+ return this._customParameters;
725
+ }
726
+
727
+ /**
728
+ * Get the value of the `from` parameter given to this call.
729
+ * @returns
730
+ * - A `String` representing the `from` parameter.
731
+ * - `undefined` if the call information has not yet been received from the
732
+ * native layer.
733
+ */
734
+ getFrom(): string | undefined {
735
+ return this._from;
736
+ }
737
+
738
+ /**
739
+ * Get the timestamp (milliseconds since epoch) of the call connected event.
740
+ * @returns
741
+ * - A `number` representing the timestamp.
742
+ * - `undefined` if the call has not yet connected.
743
+ */
744
+ getInitialConnectedTimestamp(): Date | undefined {
745
+ return this._initialConnectedTimestamp;
746
+ }
747
+
748
+ /**
749
+ * Get the call `SID`.
750
+ * @returns
751
+ * - A `String` representing the `SID` of the call.
752
+ * - `undefined` if the call information has not yet been received from the
753
+ * native layer.
754
+ */
755
+ getSid(): string | undefined {
756
+ return this._sid;
757
+ }
758
+
759
+ /**
760
+ * Get the state of the call object, such as {@link (Call:namespace).State.Connected} or
761
+ * {@link (Call:namespace).State.Disconnected}.
762
+ * @returns
763
+ * - A {@link (Call:namespace).State}.
764
+ */
765
+ getState(): Call.State {
766
+ return this._state;
767
+ }
768
+
769
+ /**
770
+ * Gets the `PeerConnection` `WebRTC` stats for the ongoing call.
771
+ * @returns
772
+ * A `Promise` that
773
+ * - Resolves with a {@link RTCStats.StatsReport} object representing the
774
+ * `WebRTC` `PeerConnection` stats of a call.
775
+ * - Rejects when a {@link RTCStats.StatsReport} cannot be generated for a
776
+ * call.
777
+ */
778
+ getStats(): Promise<RTCStats.StatsReport> {
779
+ return NativeModule.call_getStats(this._uuid);
780
+ }
781
+
782
+ /**
783
+ * Get the value of the `to` parameter given to this call.
784
+ * @returns
785
+ * - A `String` representing the `to` parameter.
786
+ * - `undefined` if the call information has not yet been received from the
787
+ * native layer.
788
+ */
789
+ getTo(): string | undefined {
790
+ return this._to;
791
+ }
792
+
793
+ /**
794
+ * Put this end of the call on hold or not on hold.
795
+ *
796
+ * @example
797
+ * To put a call on hold
798
+ * ```typescript
799
+ * call.hold(true);
800
+ * ```
801
+ * @example
802
+ * To take a call off hold
803
+ * ```typescript
804
+ * call.hold(false);
805
+ * ```
806
+ *
807
+ * @param hold - A `boolean` representing whether or not to put this end of
808
+ * the call on hold.
809
+ *
810
+ * @returns
811
+ * A `Promise` that
812
+ * - Resolves with the hold status when the call is put on hold or not on
813
+ * hold.
814
+ * - Rejects when the call is not able to be put on hold or not on hold.
815
+ */
816
+ async hold(hold: boolean): Promise<boolean> {
817
+ this._isOnHold = await NativeModule.call_hold(this._uuid, hold);
818
+ return this._isOnHold;
819
+ }
820
+
821
+ /**
822
+ * Mute or unmute this end of the call.
823
+ *
824
+ * @example
825
+ * To mute a call
826
+ * ```typescript
827
+ * call.mute(true);
828
+ * ```
829
+ *
830
+ * @example
831
+ * To unmute a call
832
+ * ```typescript
833
+ * call.mute(false);
834
+ * ```
835
+ *
836
+ * @param mute - A `boolean` representing whether or not to mute this end of
837
+ * the call.
838
+ *
839
+ * @returns
840
+ * A `Promise` that
841
+ * - Resolves with the muted status of the call when the call is muted or
842
+ * unmuted.
843
+ * - Rejects when the call is not able to be muted or unmuted.
844
+ */
845
+ async mute(mute: boolean): Promise<boolean> {
846
+ this._isMuted = await NativeModule.call_mute(this._uuid, mute);
847
+ return this._isMuted;
848
+ }
849
+
850
+ /**
851
+ * Send DTMF digits.
852
+ *
853
+ * @example
854
+ * To send the `0` dialtone:
855
+ * ```typescript
856
+ * call.sendDigits('0');
857
+ * ```
858
+ *
859
+ * @example
860
+ * To send the `0` and then `1` dialtone:
861
+ * ```typescript
862
+ * call.sendDigits('01');
863
+ * ```
864
+ *
865
+ * @param digits - A sequence of DTMF digits in a string.
866
+ *
867
+ * @returns
868
+ * A `Promise` that
869
+ * - Resolves when the DTMF digits have been sent.
870
+ * - Rejects when DTMF tones are not able to be sent.
871
+ */
872
+ sendDigits(digits: string): Promise<void> {
873
+ return NativeModule.call_sendDigits(this._uuid, digits);
874
+ }
875
+
876
+ /**
877
+ * Send a CallMessage.
878
+ *
879
+ * @example
880
+ * To send a user-defined-message
881
+ * ```typescript
882
+ * const outgoingCallMessage: OutgoingCallMessage = await call.sendMessage({
883
+ * content: { key1: 'This is a messsage from the parent call' },
884
+ * contentType: 'application/json',
885
+ * messageType: 'user-defined-message'
886
+ * });
887
+ *
888
+ * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Failure, (error) => {
889
+ * // outgoingCallMessage failed, handle error
890
+ * });
891
+ *
892
+ * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Sent, () => {
893
+ * // outgoingCallMessage sent
894
+ * });
895
+ * ```
896
+ *
897
+ * @param message - The call message to send.
898
+ *
899
+ * @returns
900
+ * A `Promise` that
901
+ * - Resolves with the OutgoingCallMessage object.
902
+ * - Rejects when the message is unable to be sent.
903
+ */
904
+ async sendMessage(message: CallMessage): Promise<OutgoingCallMessage> {
905
+ const { content, contentType, messageType } = validateCallMessage(message);
906
+
907
+ const voiceEventSid = await NativeModule.call_sendMessage(
908
+ this._uuid,
909
+ content,
910
+ contentType,
911
+ messageType
912
+ );
913
+
914
+ const outgoingCallMessage = new OutgoingCallMessage({
915
+ content,
916
+ contentType,
917
+ messageType,
918
+ voiceEventSid,
919
+ });
920
+
921
+ return outgoingCallMessage;
922
+ }
923
+
924
+ /**
925
+ * Post feedback about a call.
926
+ *
927
+ * @example
928
+ * To report that a call had very significant audio latency:
929
+ * ```typescript
930
+ * call.postFeedback(Call.Score.Five, Call.Issue.AudioLatency);
931
+ * ```
932
+ *
933
+ * @param score - A score representing the serverity of the issue being
934
+ * reported.
935
+ * @param issue - The issue being reported.
936
+ * @returns
937
+ * A `Promise` that
938
+ * - Resolves when the feedback has been posted.
939
+ * - Rejects when the feedback is unable to be sent.
940
+ */
941
+ async postFeedback(score: Call.Score, issue: Call.Issue): Promise<void> {
942
+ if (!validScores.includes(score)) {
943
+ throw new InvalidArgumentError(
944
+ '"score" parameter invalid. Must be a member of the `Call.Score` enum.'
945
+ );
946
+ }
947
+
948
+ if (!Object.values(Call.Issue).includes(issue)) {
949
+ throw new InvalidArgumentError(
950
+ '"issue" parameter invalid. Must be a member of the `Call.Issue` enum.'
951
+ );
952
+ }
953
+
954
+ const nativeScore = scoreMap[score];
955
+ const nativeIssue = issueMap[issue];
956
+
957
+ return NativeModule.call_postFeedback(this._uuid, nativeScore, nativeIssue);
958
+ }
959
+ }
960
+
961
+ /**
962
+ * Namespace for enumerations and types used by
963
+ * {@link (Call:class) | Call objects}.
964
+ *
965
+ * @remarks
966
+ * - See also the {@link (Call:class) | Call class}.
967
+ * - See also the {@link (Call:interface) | Call interface}.
968
+ *
969
+ * @public
970
+ */
971
+ export namespace Call {
972
+ /**
973
+ * Enumeration of all event strings emitted by {@link (Call:class)} objects.
974
+ */
975
+ export enum Event {
976
+ /**
977
+ * Event string for the `Connected` event.
978
+ * See {@link (Call:interface).(addListener:1)}.
979
+ */
980
+ 'Connected' = 'connected',
981
+
982
+ /**
983
+ * Event string for the `ConnectedFailure` event.
984
+ * See {@link (Call:interface).(addListener:2)}.
985
+ */
986
+ 'ConnectFailure' = 'connectFailure',
987
+
988
+ /**
989
+ * Event string for the `Reconnecting` event.
990
+ * See {@link (Call:interface).(addListener:3)}.
991
+ */
992
+ 'Reconnecting' = 'reconnecting',
993
+
994
+ /**
995
+ * Event string for the `Reconnected` event.
996
+ * See {@link (Call:interface).(addListener:4)}.
997
+ */
998
+ 'Reconnected' = 'reconnected',
999
+
1000
+ /**
1001
+ * Event string for the `Disconnected` event.
1002
+ * See {@link (Call:interface).(addListener:5)}.
1003
+ */
1004
+ 'Disconnected' = 'disconnected',
1005
+
1006
+ /**
1007
+ * Event string for the `Ringing` event.
1008
+ * See {@link (Call:interface).(addListener:6)}.
1009
+ */
1010
+ 'Ringing' = 'ringing',
1011
+
1012
+ /**
1013
+ * Event string for the `QualityWarningsChanged` event.
1014
+ * See {@link (Call:interface).(addListener:7)}.
1015
+ */
1016
+ 'QualityWarningsChanged' = 'qualityWarningsChanged',
1017
+
1018
+ /**
1019
+ * Event string for the `MessageReceived` event.
1020
+ * See {@link (Call:interface).(addListener:8)}
1021
+ */
1022
+ 'MessageReceived' = 'messageReceived',
1023
+ }
1024
+
1025
+ /**
1026
+ * An enumeration of all possible {@link (Call:class) | Call object} states.
1027
+ */
1028
+ export enum State {
1029
+ /**
1030
+ * Call `Connected` state.
1031
+ *
1032
+ * Occurs when the `Connected` and `Reconnected` event is raised.
1033
+ *
1034
+ * @remarks
1035
+ *
1036
+ * See {@link (Call:interface).(addListener:1)}.
1037
+ *
1038
+ * See {@link (Call:interface).(addListener:4)}.
1039
+ */
1040
+ 'Connected' = Constants.CallStateConnected,
1041
+
1042
+ /**
1043
+ * Call `Connecting` state.
1044
+ *
1045
+ * The default state of an outgoing call.
1046
+ */
1047
+ 'Connecting' = Constants.CallStateConnecting,
1048
+
1049
+ /**
1050
+ * Call `Disconnected` state.
1051
+ *
1052
+ * Occurs when the `Disconnected` or `ConnectFailure` event is raised.
1053
+ *
1054
+ * @remarks
1055
+ *
1056
+ * See {@link (Call:interface).(addListener:5)}.
1057
+ *
1058
+ * See {@link (Call:interface).(addListener:2)}.
1059
+ */
1060
+ 'Disconnected' = Constants.CallStateDisconnected,
1061
+
1062
+ /**
1063
+ * Call `Reconnecting` state.
1064
+ *
1065
+ * Occurs when the `Reconnecting` event is raised.
1066
+ *
1067
+ * @remarks
1068
+ *
1069
+ * See {@link (Call:interface).(addListener:3)}.
1070
+ */
1071
+ 'Reconnecting' = Constants.CallStateReconnecting,
1072
+
1073
+ /**
1074
+ * Call `Ringing` state. Occurs when the `Ringing` event is raised.
1075
+ *
1076
+ * @remarks
1077
+ *
1078
+ * See {@link (Call:interface).(addListener:6)}.
1079
+ */
1080
+ 'Ringing' = Constants.CallStateRinging,
1081
+ }
1082
+
1083
+ /**
1084
+ * An enumeration of all call quality-warning types.
1085
+ */
1086
+ export enum QualityWarning {
1087
+ /**
1088
+ * Raised when the call detects constant audio input, such as silence.
1089
+ */
1090
+ 'ConstantAudioInputLevel' = 'constant-audio-input-level',
1091
+ /**
1092
+ * Raised when the network encounters high jitter.
1093
+ */
1094
+ 'HighJitter' = 'high-jitter',
1095
+ /**
1096
+ * Raised when the network encounters high packet loss.
1097
+ */
1098
+ 'HighPacketLoss' = 'high-packet-loss',
1099
+ /**
1100
+ * Raised when the network encounters high packet round-trip-time.
1101
+ */
1102
+ 'HighRtt' = 'high-rtt',
1103
+ /**
1104
+ * Raised when the call detects a low mean-opinion-score or MOS.
1105
+ */
1106
+ 'LowMos' = 'low-mos',
1107
+ }
1108
+
1109
+ /**
1110
+ * An enumeration of all scores that could be used to rate the experience of
1111
+ * a call or issues encountered during the call.
1112
+ */
1113
+ export enum Score {
1114
+ /**
1115
+ * An issue was not encountered or there is no desire to report said issue.
1116
+ */
1117
+ 'NotReported' = 0,
1118
+ /**
1119
+ * An issue had severity approximately 1/5.
1120
+ */
1121
+ 'One' = 1,
1122
+ /**
1123
+ * An issue had severity approximately 2/5.
1124
+ */
1125
+ 'Two' = 2,
1126
+ /**
1127
+ * An issue had severity approximately 3/5.
1128
+ */
1129
+ 'Three' = 3,
1130
+ /**
1131
+ * An issue had severity approximately 4/5.
1132
+ */
1133
+ 'Four' = 4,
1134
+ /**
1135
+ * An issue had severity approximately 5/5.
1136
+ */
1137
+ 'Five' = 5,
1138
+ }
1139
+
1140
+ /**
1141
+ * An enumeration of call issues that can be reported.
1142
+ */
1143
+ export enum Issue {
1144
+ /**
1145
+ * No issue is reported.
1146
+ */
1147
+ 'NotReported' = 'not-reported',
1148
+ /**
1149
+ * The call was dropped unexpectedly.
1150
+ */
1151
+ 'DroppedCall' = 'dropped-call',
1152
+ /**
1153
+ * The call encountered significant audio latency.
1154
+ */
1155
+ 'AudioLatency' = 'audio-latency',
1156
+ /**
1157
+ * One party of the call could not hear the other callee.
1158
+ */
1159
+ 'OneWayAudio' = 'one-way-audio',
1160
+ /**
1161
+ * Call audio was choppy.
1162
+ */
1163
+ 'ChoppyAudio' = 'choppy-audio',
1164
+ /**
1165
+ * Call audio had significant noise.
1166
+ */
1167
+ 'NoisyCall' = 'noisy-call',
1168
+ /**
1169
+ * Call audio had significant echo.
1170
+ */
1171
+ 'Echo' = 'echo',
1172
+ }
1173
+
1174
+ /**
1175
+ * Listener types for all events emitted by a
1176
+ * {@link (Call:class) | Call object.}
1177
+ */
1178
+ export namespace Listener {
1179
+ /**
1180
+ * Connected event listener. This should be the function signature of any
1181
+ * event listener bound to the {@link (Call:namespace).Event.Connected}
1182
+ * event.
1183
+ *
1184
+ * @remarks
1185
+ * See {@link (Call:interface).(addListener:1)}.
1186
+ */
1187
+ export type Connected = () => void;
1188
+
1189
+ /**
1190
+ * Connect failure event listener. This should be the function signature of
1191
+ * any event listener bound to the
1192
+ * {@link (Call:namespace).Event.ConnectFailure} event.
1193
+ *
1194
+ * @remarks
1195
+ * See {@link (Call:interface).(addListener:2)}.
1196
+ *
1197
+ * See {@link TwilioErrors} for all error classes.
1198
+ */
1199
+ export type ConnectFailure = (error: TwilioError) => void;
1200
+
1201
+ /**
1202
+ * Reconnecting event listener. This should be the function signature of any
1203
+ * event listener bound to the {@link (Call:namespace).Event.Reconnecting}
1204
+ * event.
1205
+ *
1206
+ * @remarks
1207
+ * See {@link (Call:interface).(addListener:3)}.
1208
+ *
1209
+ * See {@link TwilioErrors} for all error classes.
1210
+ */
1211
+ export type Reconnecting = (error: TwilioError) => void;
1212
+
1213
+ /**
1214
+ * Reconnected event listener. This should be the function signature of any
1215
+ * event listener bound to the {@link (Call:namespace).Event.Reconnected}
1216
+ * event.
1217
+ *
1218
+ * @remarks
1219
+ * See {@link (Call:interface).(addListener:4)}.
1220
+ */
1221
+ export type Reconnected = () => void;
1222
+
1223
+ /**
1224
+ * Disconnected event listener. This should be the function signature of any
1225
+ * event listener bound to the {@link (Call:namespace).Event.Disconnected}
1226
+ * event.
1227
+ *
1228
+ * @remarks
1229
+ * See {@link (Call:interface).(addListener:5)}.
1230
+ *
1231
+ * See {@link TwilioErrors} for all error classes.
1232
+ */
1233
+ export type Disconnected = (error?: TwilioError) => void;
1234
+
1235
+ /**
1236
+ * Ringing event listener. This should be the function signature of any
1237
+ * event listener bound to the {@link (Call:namespace).Event.Ringing} event.
1238
+ *
1239
+ * @remarks
1240
+ * See {@link (Call:interface).(addListener:6)}.
1241
+ */
1242
+ export type Ringing = () => void;
1243
+
1244
+ /**
1245
+ * Quality warnings changed event listener. This should be the function
1246
+ * signature of any event listener bound to the
1247
+ * {@link (Call:namespace).Event.QualityWarningsChanged} event.
1248
+ *
1249
+ * @remarks
1250
+ * See {@link (Call:interface).(addListener:7)}.
1251
+ */
1252
+ export type QualityWarningsChanged = (
1253
+ currentQualityWarnings: Call.QualityWarning[],
1254
+ previousQualityWarnings: Call.QualityWarning[]
1255
+ ) => void;
1256
+
1257
+ /**
1258
+ * CallMessage received event listener. This should be the function signature of
1259
+ * any event listener bound to the {@link (Call:namespace).Event.MessageReceived} event.
1260
+ *
1261
+ * @remarks
1262
+ * See {@link (Call:interface).(addListener:8)}.
1263
+ */
1264
+ export type MessageReceived = (
1265
+ incomingCallMessage: IncomingCallMessage
1266
+ ) => void;
1267
+
1268
+ /**
1269
+ * Generic event listener. This should be the function signature of any
1270
+ * event listener bound to any call event.
1271
+ *
1272
+ * @remarks
1273
+ * See {@link (Call:interface).(addListener:9)}.
1274
+ */
1275
+ export type Generic = (...args: any[]) => void;
1276
+ }
1277
+ }
1278
+
1279
+ /**
1280
+ * Mapping of {@link (Call:namespace).Event | Call events} to
1281
+ * {@link (Call:namespace).State | Call states}.
1282
+ *
1283
+ * @remarks
1284
+ * Note that this mapping is not a 1:1 bijection. Not every event coming from
1285
+ * the native layer has a relevant state, and some events share a state.
1286
+ * Therefore, this `Record` needs to be marked as `Partial` and
1287
+ * undefined-checking logic is needed when using this mapping.
1288
+ *
1289
+ * @internal
1290
+ */
1291
+ const eventTypeStateMap: Partial<Record<NativeCallEventType, Call.State>> = {
1292
+ [Constants.CallEventConnected]: Call.State.Connected,
1293
+ [Constants.CallEventConnectFailure]: Call.State.Disconnected,
1294
+ [Constants.CallEventDisconnected]: Call.State.Disconnected,
1295
+ [Constants.CallEventReconnecting]: Call.State.Reconnecting,
1296
+ [Constants.CallEventReconnected]: Call.State.Connected,
1297
+ [Constants.CallEventRinging]: Call.State.Ringing,
1298
+ };
1299
+
1300
+ /**
1301
+ * Array of valid call scores.
1302
+ *
1303
+ * @internal
1304
+ */
1305
+ const validScores = [
1306
+ Call.Score.NotReported,
1307
+ Call.Score.One,
1308
+ Call.Score.Two,
1309
+ Call.Score.Three,
1310
+ Call.Score.Four,
1311
+ Call.Score.Five,
1312
+ ];
1313
+
1314
+ /**
1315
+ * Mapping of the {@link (Call:namespace).Score | Call score} enum to
1316
+ * cross-platform common constants.
1317
+ *
1318
+ * @internal
1319
+ */
1320
+ const scoreMap: Record<Call.Score, NativeCallFeedbackScore> = {
1321
+ [Call.Score.NotReported]: Constants.CallFeedbackScoreNotReported,
1322
+ [Call.Score.One]: Constants.CallFeedbackScoreOne,
1323
+ [Call.Score.Two]: Constants.CallFeedbackScoreTwo,
1324
+ [Call.Score.Three]: Constants.CallFeedbackScoreThree,
1325
+ [Call.Score.Four]: Constants.CallFeedbackScoreFour,
1326
+ [Call.Score.Five]: Constants.CallFeedbackScoreFive,
1327
+ };
1328
+
1329
+ /**
1330
+ * Mapping of the {@link (Call:namespace).Issue | Call issue} enum to
1331
+ * cross-platform common constants.
1332
+ *
1333
+ * @internal
1334
+ */
1335
+ const issueMap: Record<Call.Issue, NativeCallFeedbackIssue> = {
1336
+ [Call.Issue.AudioLatency]: Constants.CallFeedbackIssueAudioLatency,
1337
+ [Call.Issue.ChoppyAudio]: Constants.CallFeedbackIssueChoppyAudio,
1338
+ [Call.Issue.DroppedCall]: Constants.CallFeedbackIssueDroppedCall,
1339
+ [Call.Issue.Echo]: Constants.CallFeedbackIssueEcho,
1340
+ [Call.Issue.NoisyCall]: Constants.CallFeedbackIssueNoisyCall,
1341
+ [Call.Issue.NotReported]: Constants.CallFeedbackIssueNotReported,
1342
+ [Call.Issue.OneWayAudio]: Constants.CallFeedbackIssueOneWayAudio,
1343
+ };