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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/LICENSE +206 -0
  2. package/README.md +179 -0
  3. package/android/build.gradle +113 -0
  4. package/android/gradle.properties +29 -0
  5. package/android/src/main/AndroidManifest.xml +30 -0
  6. package/android/src/main/java/com/twiliovoicereactnative/AudioSwitchManager.java +141 -0
  7. package/android/src/main/java/com/twiliovoicereactnative/CallListenerProxy.java +186 -0
  8. package/android/src/main/java/com/twiliovoicereactnative/CallMessageListenerProxy.java +103 -0
  9. package/android/src/main/java/com/twiliovoicereactnative/CallRecordDatabase.java +183 -0
  10. package/android/src/main/java/com/twiliovoicereactnative/CommonConstants.java +195 -0
  11. package/android/src/main/java/com/twiliovoicereactnative/ConfigurationProperties.java +41 -0
  12. package/android/src/main/java/com/twiliovoicereactnative/Constants.java +23 -0
  13. package/android/src/main/java/com/twiliovoicereactnative/ExpoActivityLifecycleListener.java +27 -0
  14. package/android/src/main/java/com/twiliovoicereactnative/ExpoApplicationLifecycleListener.java +14 -0
  15. package/android/src/main/java/com/twiliovoicereactnative/ExpoModule.kt +36 -0
  16. package/android/src/main/java/com/twiliovoicereactnative/ExpoPackage.java +20 -0
  17. package/android/src/main/java/com/twiliovoicereactnative/JSEventEmitter.java +98 -0
  18. package/android/src/main/java/com/twiliovoicereactnative/MediaPlayerManager.java +58 -0
  19. package/android/src/main/java/com/twiliovoicereactnative/NotificationUtility.java +363 -0
  20. package/android/src/main/java/com/twiliovoicereactnative/ReactNativeArgumentsSerializer.java +276 -0
  21. package/android/src/main/java/com/twiliovoicereactnative/SDKLog.java +74 -0
  22. package/android/src/main/java/com/twiliovoicereactnative/StatsListenerProxy.java +178 -0
  23. package/android/src/main/java/com/twiliovoicereactnative/TwilioVoiceReactNativeModule.java +778 -0
  24. package/android/src/main/java/com/twiliovoicereactnative/TwilioVoiceReactNativePackage.java +28 -0
  25. package/android/src/main/java/com/twiliovoicereactnative/VoiceActivityProxy.java +101 -0
  26. package/android/src/main/java/com/twiliovoicereactnative/VoiceApplicationProxy.java +133 -0
  27. package/android/src/main/java/com/twiliovoicereactnative/VoiceFirebaseMessagingService.java +88 -0
  28. package/android/src/main/java/com/twiliovoicereactnative/VoiceService.java +403 -0
  29. package/android/src/main/res/drawable/answered_call_small_icon.png +0 -0
  30. package/android/src/main/res/drawable/ic_launcher_round.png +0 -0
  31. package/android/src/main/res/drawable/ic_launcher_sdk.png +0 -0
  32. package/android/src/main/res/drawable/incoming_call_small_icon.png +0 -0
  33. package/android/src/main/res/drawable/outgoing_call_small_icon.png +0 -0
  34. package/android/src/main/res/raw/disconnect.wav +0 -0
  35. package/android/src/main/res/raw/incoming.wav +0 -0
  36. package/android/src/main/res/raw/outgoing.wav +0 -0
  37. package/android/src/main/res/raw/ringtone.wav +0 -0
  38. package/android/src/main/res/raw/silent.wav +0 -0
  39. package/android/src/main/res/values/colors.xml +11 -0
  40. package/android/src/main/res/values/config.xml +5 -0
  41. package/android/src/main/res/values/dimens.xml +7 -0
  42. package/android/src/main/res/values/strings.xml +25 -0
  43. package/android/src/main/res/values/styles.xml +10 -0
  44. package/android/src/main/res/values-night/colors.xml +11 -0
  45. package/expo-config-plugin/android.js +191 -0
  46. package/expo-config-plugin/ios.js +22 -0
  47. package/expo-module.config.json +6 -0
  48. package/ios/TwilioVoicePushRegistry.h +19 -0
  49. package/ios/TwilioVoicePushRegistry.m +72 -0
  50. package/ios/TwilioVoiceReactNative+CallInvite.m +56 -0
  51. package/ios/TwilioVoiceReactNative+CallKit.m +533 -0
  52. package/ios/TwilioVoiceReactNative+CallMessage.m +81 -0
  53. package/ios/TwilioVoiceReactNative.h +74 -0
  54. package/ios/TwilioVoiceReactNative.m +1046 -0
  55. package/ios/TwilioVoiceReactNative.xcodeproj/project.pbxproj +328 -0
  56. package/ios/TwilioVoiceReactNativeConstants.h +200 -0
  57. package/ios/Utilities/TwilioVoiceStatsReport.h +175 -0
  58. package/lib/commonjs/AudioDevice.js +101 -0
  59. package/lib/commonjs/AudioDevice.js.map +1 -0
  60. package/lib/commonjs/Call.js +765 -0
  61. package/lib/commonjs/Call.js.map +1 -0
  62. package/lib/commonjs/CallInvite.js +452 -0
  63. package/lib/commonjs/CallInvite.js.map +1 -0
  64. package/lib/commonjs/CallMessage/CallMessage.js +54 -0
  65. package/lib/commonjs/CallMessage/CallMessage.js.map +1 -0
  66. package/lib/commonjs/CallMessage/IncomingCallMessage.js +120 -0
  67. package/lib/commonjs/CallMessage/IncomingCallMessage.js.map +1 -0
  68. package/lib/commonjs/CallMessage/OutgoingCallMessage.js +148 -0
  69. package/lib/commonjs/CallMessage/OutgoingCallMessage.js.map +1 -0
  70. package/lib/commonjs/ExpoModule.js +69 -0
  71. package/lib/commonjs/ExpoModule.js.map +1 -0
  72. package/lib/commonjs/Voice.js +611 -0
  73. package/lib/commonjs/Voice.js.map +1 -0
  74. package/lib/commonjs/common.js +26 -0
  75. package/lib/commonjs/common.js.map +1 -0
  76. package/lib/commonjs/constants.js +158 -0
  77. package/lib/commonjs/constants.js.map +1 -0
  78. package/lib/commonjs/error/InvalidArgumentError.js +32 -0
  79. package/lib/commonjs/error/InvalidArgumentError.js.map +1 -0
  80. package/lib/commonjs/error/InvalidStateError.js +33 -0
  81. package/lib/commonjs/error/InvalidStateError.js.map +1 -0
  82. package/lib/commonjs/error/TwilioError.js +38 -0
  83. package/lib/commonjs/error/TwilioError.js.map +1 -0
  84. package/lib/commonjs/error/UnsupportedPlatformError.js +33 -0
  85. package/lib/commonjs/error/UnsupportedPlatformError.js.map +1 -0
  86. package/lib/commonjs/error/generated.js +2343 -0
  87. package/lib/commonjs/error/generated.js.map +1 -0
  88. package/lib/commonjs/error/index.js +112 -0
  89. package/lib/commonjs/error/index.js.map +1 -0
  90. package/lib/commonjs/error/utility.js +37 -0
  91. package/lib/commonjs/error/utility.js.map +1 -0
  92. package/lib/commonjs/index.js +95 -0
  93. package/lib/commonjs/index.js.map +1 -0
  94. package/lib/commonjs/type/AudioDevice.js +6 -0
  95. package/lib/commonjs/type/AudioDevice.js.map +1 -0
  96. package/lib/commonjs/type/Call.js +6 -0
  97. package/lib/commonjs/type/Call.js.map +1 -0
  98. package/lib/commonjs/type/CallInvite.js +6 -0
  99. package/lib/commonjs/type/CallInvite.js.map +1 -0
  100. package/lib/commonjs/type/CallKit.js +30 -0
  101. package/lib/commonjs/type/CallKit.js.map +1 -0
  102. package/lib/commonjs/type/CallMessage.js +6 -0
  103. package/lib/commonjs/type/CallMessage.js.map +1 -0
  104. package/lib/commonjs/type/Error.js +6 -0
  105. package/lib/commonjs/type/Error.js.map +1 -0
  106. package/lib/commonjs/type/NativeModule.js +6 -0
  107. package/lib/commonjs/type/NativeModule.js.map +1 -0
  108. package/lib/commonjs/type/RTCStats.js +29 -0
  109. package/lib/commonjs/type/RTCStats.js.map +1 -0
  110. package/lib/commonjs/type/Voice.js +6 -0
  111. package/lib/commonjs/type/Voice.js.map +1 -0
  112. package/lib/commonjs/type/common.js +2 -0
  113. package/lib/commonjs/type/common.js.map +1 -0
  114. package/lib/module/AudioDevice.js +97 -0
  115. package/lib/module/AudioDevice.js.map +1 -0
  116. package/lib/module/Call.js +766 -0
  117. package/lib/module/Call.js.map +1 -0
  118. package/lib/module/CallInvite.js +450 -0
  119. package/lib/module/CallInvite.js.map +1 -0
  120. package/lib/module/CallMessage/CallMessage.js +51 -0
  121. package/lib/module/CallMessage/CallMessage.js.map +1 -0
  122. package/lib/module/CallMessage/IncomingCallMessage.js +116 -0
  123. package/lib/module/CallMessage/IncomingCallMessage.js.map +1 -0
  124. package/lib/module/CallMessage/OutgoingCallMessage.js +154 -0
  125. package/lib/module/CallMessage/OutgoingCallMessage.js.map +1 -0
  126. package/lib/module/ExpoModule.js +58 -0
  127. package/lib/module/ExpoModule.js.map +1 -0
  128. package/lib/module/Voice.js +598 -0
  129. package/lib/module/Voice.js.map +1 -0
  130. package/lib/module/common.js +11 -0
  131. package/lib/module/common.js.map +1 -0
  132. package/lib/module/constants.js +151 -0
  133. package/lib/module/constants.js.map +1 -0
  134. package/lib/module/error/InvalidArgumentError.js +23 -0
  135. package/lib/module/error/InvalidArgumentError.js.map +1 -0
  136. package/lib/module/error/InvalidStateError.js +24 -0
  137. package/lib/module/error/InvalidStateError.js.map +1 -0
  138. package/lib/module/error/TwilioError.js +29 -0
  139. package/lib/module/error/TwilioError.js.map +1 -0
  140. package/lib/module/error/UnsupportedPlatformError.js +24 -0
  141. package/lib/module/error/UnsupportedPlatformError.js.map +1 -0
  142. package/lib/module/error/generated.js +2315 -0
  143. package/lib/module/error/generated.js.map +1 -0
  144. package/lib/module/error/index.js +6 -0
  145. package/lib/module/error/index.js.map +1 -0
  146. package/lib/module/error/utility.js +27 -0
  147. package/lib/module/error/utility.js.map +1 -0
  148. package/lib/module/index.js +23 -0
  149. package/lib/module/index.js.map +1 -0
  150. package/lib/module/type/AudioDevice.js +2 -0
  151. package/lib/module/type/AudioDevice.js.map +1 -0
  152. package/lib/module/type/Call.js +2 -0
  153. package/lib/module/type/Call.js.map +1 -0
  154. package/lib/module/type/CallInvite.js +2 -0
  155. package/lib/module/type/CallInvite.js.map +1 -0
  156. package/lib/module/type/CallKit.js +22 -0
  157. package/lib/module/type/CallKit.js.map +1 -0
  158. package/lib/module/type/CallMessage.js +2 -0
  159. package/lib/module/type/CallMessage.js.map +1 -0
  160. package/lib/module/type/Error.js +2 -0
  161. package/lib/module/type/Error.js.map +1 -0
  162. package/lib/module/type/NativeModule.js +2 -0
  163. package/lib/module/type/NativeModule.js.map +1 -0
  164. package/lib/module/type/RTCStats.js +21 -0
  165. package/lib/module/type/RTCStats.js.map +1 -0
  166. package/lib/module/type/Voice.js +2 -0
  167. package/lib/module/type/Voice.js.map +1 -0
  168. package/lib/module/type/common.js +2 -0
  169. package/lib/module/type/common.js.map +1 -0
  170. package/lib/typescript/AudioDevice.d.ts +74 -0
  171. package/lib/typescript/Call.d.ts +874 -0
  172. package/lib/typescript/CallInvite.d.ts +484 -0
  173. package/lib/typescript/CallMessage/CallMessage.d.ts +53 -0
  174. package/lib/typescript/CallMessage/IncomingCallMessage.d.ts +75 -0
  175. package/lib/typescript/CallMessage/OutgoingCallMessage.d.ts +198 -0
  176. package/lib/typescript/ExpoModule.d.ts +13 -0
  177. package/lib/typescript/Voice.d.ts +620 -0
  178. package/lib/typescript/common.d.ts +11 -0
  179. package/lib/typescript/constants.d.ts +148 -0
  180. package/lib/typescript/error/InvalidArgumentError.d.ts +11 -0
  181. package/lib/typescript/error/InvalidStateError.d.ts +12 -0
  182. package/lib/typescript/error/TwilioError.d.ts +14 -0
  183. package/lib/typescript/error/UnsupportedPlatformError.d.ts +12 -0
  184. package/lib/typescript/error/generated.d.ts +1558 -0
  185. package/lib/typescript/error/index.d.ts +5 -0
  186. package/lib/typescript/error/utility.d.ts +12 -0
  187. package/lib/typescript/index.d.ts +18 -0
  188. package/lib/typescript/type/AudioDevice.d.ts +15 -0
  189. package/lib/typescript/type/Call.d.ts +59 -0
  190. package/lib/typescript/type/CallInvite.d.ts +40 -0
  191. package/lib/typescript/type/CallKit.d.ts +60 -0
  192. package/lib/typescript/type/CallMessage.d.ts +20 -0
  193. package/lib/typescript/type/Error.d.ts +9 -0
  194. package/lib/typescript/type/NativeModule.d.ts +59 -0
  195. package/lib/typescript/type/RTCStats.d.ts +91 -0
  196. package/lib/typescript/type/Voice.d.ts +16 -0
  197. package/lib/typescript/type/common.d.ts +15 -0
  198. package/package.json +167 -0
  199. package/src/AudioDevice.tsx +88 -0
  200. package/src/Call.tsx +1343 -0
  201. package/src/CallInvite.tsx +757 -0
  202. package/src/CallMessage/CallMessage.ts +83 -0
  203. package/src/CallMessage/IncomingCallMessage.ts +104 -0
  204. package/src/CallMessage/OutgoingCallMessage.ts +308 -0
  205. package/src/ExpoModule.ts +59 -0
  206. package/src/Voice.tsx +1010 -0
  207. package/src/common.ts +16 -0
  208. package/src/constants.ts +193 -0
  209. package/src/error/InvalidArgumentError.ts +19 -0
  210. package/src/error/InvalidStateError.ts +19 -0
  211. package/src/error/TwilioError.ts +22 -0
  212. package/src/error/UnsupportedPlatformError.ts +19 -0
  213. package/src/error/generated.ts +2277 -0
  214. package/src/error/index.ts +18 -0
  215. package/src/error/utility.ts +36 -0
  216. package/src/index.tsx +24 -0
  217. package/src/type/AudioDevice.ts +18 -0
  218. package/src/type/Call.ts +102 -0
  219. package/src/type/CallInvite.ts +59 -0
  220. package/src/type/CallKit.ts +61 -0
  221. package/src/type/CallMessage.ts +31 -0
  222. package/src/type/Error.ts +11 -0
  223. package/src/type/NativeModule.ts +93 -0
  224. package/src/type/RTCStats.ts +99 -0
  225. package/src/type/Voice.ts +31 -0
  226. package/src/type/common.ts +16 -0
  227. package/twilio-voice-react-native.podspec +22 -0
@@ -0,0 +1,765 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Call = void 0;
7
+
8
+ var _eventemitter = require("eventemitter3");
9
+
10
+ var _common = require("./common");
11
+
12
+ var _constants = require("./constants");
13
+
14
+ var _InvalidArgumentError = require("./error/InvalidArgumentError");
15
+
16
+ var _utility = require("./error/utility");
17
+
18
+ var _CallMessage = require("./CallMessage/CallMessage");
19
+
20
+ var _IncomingCallMessage = require("./CallMessage/IncomingCallMessage");
21
+
22
+ var _OutgoingCallMessage = require("./CallMessage/OutgoingCallMessage");
23
+
24
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
+
26
+ /**
27
+ * Provides access to information about a call, including the call parameters,
28
+ * and exposes functionality for a call such as disconnecting, muting, and
29
+ * holding.
30
+ *
31
+ * @remarks
32
+ * Note that the call information is fetched as soon as possible from the native
33
+ * layer, but there is no guarantee that all information is immediately
34
+ * available. Methods such as `Call.getFrom()` or `Call.getTo()` may return
35
+ * `undefined`.
36
+ *
37
+ * As call events are received from the native layer, call information will
38
+ * propagate from the native layer to the JS layer and become available.
39
+ * Therefore, it is good practice to read information from the call after an
40
+ * event occurs, or as events occur.
41
+ *
42
+ * - See the {@link (Call:namespace).Event} enum for events emitted by `Call`
43
+ * objects.
44
+ * - See the {@link (Call:interface) | Call interface} for overloaded event
45
+ * listening methods.
46
+ * - See the {@link (Call:namespace) | Call namespace} for types and
47
+ * enumerations used by this class.
48
+ *
49
+ * @public
50
+ */
51
+ class Call extends _eventemitter.EventEmitter {
52
+ /**
53
+ * The `Uuid` of this call. Used to identify calls between the JS and native
54
+ * layer so we can associate events and native functionality between the
55
+ * layers.
56
+ */
57
+
58
+ /**
59
+ * Call custom parameters.
60
+ */
61
+
62
+ /**
63
+ * Call `from` parameter.
64
+ */
65
+
66
+ /**
67
+ * Initial `connected` timestamp. Milliseconds since epoch.
68
+ */
69
+
70
+ /**
71
+ * A boolean representing if the call is currently muted.
72
+ */
73
+
74
+ /**
75
+ * A boolean representing if the call is currently on hold.
76
+ */
77
+
78
+ /**
79
+ * A string representing the SID of this call.
80
+ */
81
+
82
+ /**
83
+ * The current state of the call.
84
+ *
85
+ * @remarks
86
+ * See {@link (Call:namespace).State}.
87
+ */
88
+
89
+ /**
90
+ * Call `to` parameter.
91
+ */
92
+
93
+ /**
94
+ * Handlers for native call events. Set upon construction so we can
95
+ * dynamically bind events to handlers.
96
+ *
97
+ * @privateRemarks
98
+ * This is done by the constructor so this mapping isn't made every time the
99
+ * {@link (Call:class)._handleNativeEvent} function is invoked.
100
+ */
101
+
102
+ /**
103
+ * Constructor for the {@link (Call:class) | Call class}. This should not be
104
+ * invoked by third-party code. All instances of the
105
+ * {@link (Call:class) | Call class} should be made by the SDK and emitted by
106
+ * {@link (Voice:class) | Voice objects}.
107
+ *
108
+ * @param nativeCallInfo - An object containing all of the data from the
109
+ * native layer necessary to fully describe a call, as well as invoke native
110
+ * functionality for the call.
111
+ *
112
+ * @internal
113
+ */
114
+ constructor({
115
+ uuid,
116
+ customParameters,
117
+ from,
118
+ sid,
119
+ state,
120
+ to,
121
+ isMuted,
122
+ isOnHold,
123
+ initialConnectedTimestamp
124
+ }) {
125
+ super();
126
+
127
+ _defineProperty(this, "_uuid", void 0);
128
+
129
+ _defineProperty(this, "_customParameters", void 0);
130
+
131
+ _defineProperty(this, "_from", void 0);
132
+
133
+ _defineProperty(this, "_initialConnectedTimestamp", void 0);
134
+
135
+ _defineProperty(this, "_isMuted", void 0);
136
+
137
+ _defineProperty(this, "_isOnHold", void 0);
138
+
139
+ _defineProperty(this, "_sid", void 0);
140
+
141
+ _defineProperty(this, "_state", void 0);
142
+
143
+ _defineProperty(this, "_to", void 0);
144
+
145
+ _defineProperty(this, "_nativeEventHandler", void 0);
146
+
147
+ _defineProperty(this, "_handleNativeEvent", nativeCallEvent => {
148
+ const {
149
+ type,
150
+ call: callInfo
151
+ } = nativeCallEvent;
152
+ const handler = this._nativeEventHandler[type];
153
+
154
+ if (typeof handler === 'undefined') {
155
+ throw new Error(`Unknown call event type received from the native layer: "${type}".`);
156
+ }
157
+
158
+ if (callInfo.uuid === this._uuid) {
159
+ handler(nativeCallEvent);
160
+ }
161
+ });
162
+
163
+ _defineProperty(this, "_handleConnectedEvent", nativeCallEvent => {
164
+ if (nativeCallEvent.type !== _constants.Constants.CallEventConnected) {
165
+ throw new Error('Incorrect "call#connected" handler called for type ' + `"${nativeCallEvent.type}".`);
166
+ }
167
+
168
+ this._update(nativeCallEvent);
169
+
170
+ this.emit(Call.Event.Connected);
171
+ });
172
+
173
+ _defineProperty(this, "_handleConnectFailureEvent", nativeCallEvent => {
174
+ if (nativeCallEvent.type !== _constants.Constants.CallEventConnectFailure) {
175
+ throw new Error('Incorrect "call#connectFailure" handler called for type ' + `"${nativeCallEvent.type}".`);
176
+ }
177
+
178
+ this._update(nativeCallEvent);
179
+
180
+ const {
181
+ message,
182
+ code
183
+ } = nativeCallEvent.error;
184
+ const error = (0, _utility.constructTwilioError)(message, code);
185
+ this.emit(Call.Event.ConnectFailure, error);
186
+ });
187
+
188
+ _defineProperty(this, "_handleDisconnectedEvent", nativeCallEvent => {
189
+ if (nativeCallEvent.type !== _constants.Constants.CallEventDisconnected) {
190
+ throw new Error('Incorrect "call#disconnected" handler called for type ' + `"${nativeCallEvent.type}".`);
191
+ }
192
+
193
+ this._update(nativeCallEvent);
194
+
195
+ if (nativeCallEvent.error) {
196
+ const {
197
+ message,
198
+ code
199
+ } = nativeCallEvent.error;
200
+ const error = (0, _utility.constructTwilioError)(message, code);
201
+ this.emit(Call.Event.Disconnected, error);
202
+ } else {
203
+ this.emit(Call.Event.Disconnected);
204
+ }
205
+ });
206
+
207
+ _defineProperty(this, "_handleReconnectingEvent", nativeCallEvent => {
208
+ if (nativeCallEvent.type !== _constants.Constants.CallEventReconnecting) {
209
+ throw new Error('Incorrect "call#reconnecting" handler called for type ' + `"${nativeCallEvent.type}".`);
210
+ }
211
+
212
+ this._update(nativeCallEvent);
213
+
214
+ const {
215
+ message,
216
+ code
217
+ } = nativeCallEvent.error;
218
+ const error = (0, _utility.constructTwilioError)(message, code);
219
+ this.emit(Call.Event.Reconnecting, error);
220
+ });
221
+
222
+ _defineProperty(this, "_handleReconnectedEvent", nativeCallEvent => {
223
+ if (nativeCallEvent.type !== _constants.Constants.CallEventReconnected) {
224
+ throw new Error('Incorrect "call#reconnected" handler called for type ' + `"${nativeCallEvent.type}".`);
225
+ }
226
+
227
+ this._update(nativeCallEvent);
228
+
229
+ this.emit(Call.Event.Reconnected);
230
+ });
231
+
232
+ _defineProperty(this, "_handleRingingEvent", nativeCallEvent => {
233
+ if (nativeCallEvent.type !== _constants.Constants.CallEventRinging) {
234
+ throw new Error('Incorrect "call#ringing" handler called for type ' + `"${nativeCallEvent.type}".`);
235
+ }
236
+
237
+ this._update(nativeCallEvent);
238
+
239
+ this.emit(Call.Event.Ringing);
240
+ });
241
+
242
+ _defineProperty(this, "_handleQualityWarningsChangedEvent", nativeCallEvent => {
243
+ if (nativeCallEvent.type !== _constants.Constants.CallEventQualityWarningsChanged) {
244
+ throw new Error('Incorrect "call#qualityWarnings" handler called for type ' + `"${nativeCallEvent.type}".`);
245
+ }
246
+
247
+ this._update(nativeCallEvent);
248
+
249
+ const currentWarnings = nativeCallEvent[_constants.Constants.CallEventCurrentWarnings];
250
+ const previousWarnings = nativeCallEvent[_constants.Constants.CallEventPreviousWarnings];
251
+ this.emit(Call.Event.QualityWarningsChanged, currentWarnings, previousWarnings);
252
+ });
253
+
254
+ _defineProperty(this, "_handleMessageReceivedEvent", nativeCallEvent => {
255
+ if (nativeCallEvent.type !== _constants.Constants.CallEventMessageReceived) {
256
+ throw new Error('Incorrect "call#Received" handler called for type' + `"${nativeCallEvent.type}`);
257
+ }
258
+
259
+ this._update(nativeCallEvent);
260
+
261
+ const {
262
+ callMessage: callMessageInfo
263
+ } = nativeCallEvent;
264
+ const incomingCallMessage = new _IncomingCallMessage.IncomingCallMessage(callMessageInfo);
265
+ this.emit(Call.Event.MessageReceived, incomingCallMessage);
266
+ });
267
+
268
+ this._uuid = uuid;
269
+ this._customParameters = { ...customParameters
270
+ };
271
+ this._from = from;
272
+ this._sid = sid;
273
+ this._state = typeof state === 'string' ? state : Call.State.Connecting;
274
+ this._to = to;
275
+ this._isMuted = isMuted;
276
+ this._isOnHold = isOnHold;
277
+ this._initialConnectedTimestamp = initialConnectedTimestamp ? new Date(initialConnectedTimestamp) : undefined;
278
+ this._nativeEventHandler = {
279
+ /**
280
+ * Call State
281
+ */
282
+ [_constants.Constants.CallEventConnected]: this._handleConnectedEvent,
283
+ [_constants.Constants.CallEventConnectFailure]: this._handleConnectFailureEvent,
284
+ [_constants.Constants.CallEventDisconnected]: this._handleDisconnectedEvent,
285
+ [_constants.Constants.CallEventReconnected]: this._handleReconnectedEvent,
286
+ [_constants.Constants.CallEventReconnecting]: this._handleReconnectingEvent,
287
+ [_constants.Constants.CallEventRinging]: this._handleRingingEvent,
288
+
289
+ /**
290
+ * Call Quality
291
+ */
292
+ [_constants.Constants.CallEventQualityWarningsChanged]: this._handleQualityWarningsChangedEvent,
293
+
294
+ /**
295
+ * Call Message
296
+ */
297
+ [_constants.Constants.CallEventMessageReceived]: this._handleMessageReceivedEvent
298
+ };
299
+
300
+ _common.NativeEventEmitter.addListener(_constants.Constants.ScopeCall, this._handleNativeEvent);
301
+ }
302
+ /**
303
+ * This intermediate native call event handler acts as a "gate", only
304
+ * executing the actual call event handler (such as `Connected`) if this call
305
+ * object matches the `Uuid` of the call that had an event raised.
306
+ * @param nativeCallEvent - A call event directly from the native layer.
307
+ */
308
+
309
+
310
+ /**
311
+ * Helper function to update the state of the call when a call event occurs
312
+ * that necessitates an update, i.e. upon a
313
+ * {@link (Call:namespace).Event.Connected | Connected event} we want to
314
+ * update the state of the call to also reflect the
315
+ * {@link (Call:namespace).State.Connected | Connected state}.
316
+ * @param nativeCallEvent - The native call event.
317
+ */
318
+ _update({
319
+ type,
320
+ call: {
321
+ from,
322
+ initialConnectedTimestamp,
323
+ sid,
324
+ to
325
+ }
326
+ }) {
327
+ const newState = eventTypeStateMap[type];
328
+
329
+ if (typeof newState === 'string') {
330
+ this._state = newState;
331
+ }
332
+
333
+ this._from = from;
334
+ this._initialConnectedTimestamp = initialConnectedTimestamp ? new Date(initialConnectedTimestamp) : undefined;
335
+ this._sid = sid;
336
+ this._to = to;
337
+ }
338
+ /**
339
+ * Handler for the the {@link (Call:namespace).Event.Connected} event.
340
+ * @param nativeCallEvent - The native call event.
341
+ */
342
+
343
+
344
+ /**
345
+ * Disconnect this side of the call.
346
+ * @returns
347
+ * A `Promise` that
348
+ * - Resolves when the call has disconnected.
349
+ * - Rejects if the native layer cannot disconnect the call.
350
+ */
351
+ disconnect() {
352
+ return _common.NativeModule.call_disconnect(this._uuid);
353
+ }
354
+ /**
355
+ * Get the mute status of this side of the call.
356
+ * @returns
357
+ * - A boolean representing the muted status of the call.
358
+ * - `undefined` if the call state has not yet been received from the native
359
+ * layer.
360
+ */
361
+
362
+
363
+ isMuted() {
364
+ return this._isMuted;
365
+ }
366
+ /**
367
+ * Get the hold status of this side of the call.
368
+ * @returns
369
+ * - A boolean representing the hold status of the call.
370
+ * - `undefined` if the call state has not yet been received from the native
371
+ * layer.
372
+ */
373
+
374
+
375
+ isOnHold() {
376
+ return this._isOnHold;
377
+ }
378
+ /**
379
+ * Return a `Record` of custom parameters given to this call.
380
+ * @returns
381
+ * - A `Record` of custom parameters.
382
+ */
383
+
384
+
385
+ getCustomParameters() {
386
+ return this._customParameters;
387
+ }
388
+ /**
389
+ * Get the value of the `from` parameter given to this call.
390
+ * @returns
391
+ * - A `String` representing the `from` parameter.
392
+ * - `undefined` if the call information has not yet been received from the
393
+ * native layer.
394
+ */
395
+
396
+
397
+ getFrom() {
398
+ return this._from;
399
+ }
400
+ /**
401
+ * Get the timestamp (milliseconds since epoch) of the call connected event.
402
+ * @returns
403
+ * - A `number` representing the timestamp.
404
+ * - `undefined` if the call has not yet connected.
405
+ */
406
+
407
+
408
+ getInitialConnectedTimestamp() {
409
+ return this._initialConnectedTimestamp;
410
+ }
411
+ /**
412
+ * Get the call `SID`.
413
+ * @returns
414
+ * - A `String` representing the `SID` of the call.
415
+ * - `undefined` if the call information has not yet been received from the
416
+ * native layer.
417
+ */
418
+
419
+
420
+ getSid() {
421
+ return this._sid;
422
+ }
423
+ /**
424
+ * Get the state of the call object, such as {@link (Call:namespace).State.Connected} or
425
+ * {@link (Call:namespace).State.Disconnected}.
426
+ * @returns
427
+ * - A {@link (Call:namespace).State}.
428
+ */
429
+
430
+
431
+ getState() {
432
+ return this._state;
433
+ }
434
+ /**
435
+ * Gets the `PeerConnection` `WebRTC` stats for the ongoing call.
436
+ * @returns
437
+ * A `Promise` that
438
+ * - Resolves with a {@link RTCStats.StatsReport} object representing the
439
+ * `WebRTC` `PeerConnection` stats of a call.
440
+ * - Rejects when a {@link RTCStats.StatsReport} cannot be generated for a
441
+ * call.
442
+ */
443
+
444
+
445
+ getStats() {
446
+ return _common.NativeModule.call_getStats(this._uuid);
447
+ }
448
+ /**
449
+ * Get the value of the `to` parameter given to this call.
450
+ * @returns
451
+ * - A `String` representing the `to` parameter.
452
+ * - `undefined` if the call information has not yet been received from the
453
+ * native layer.
454
+ */
455
+
456
+
457
+ getTo() {
458
+ return this._to;
459
+ }
460
+ /**
461
+ * Put this end of the call on hold or not on hold.
462
+ *
463
+ * @example
464
+ * To put a call on hold
465
+ * ```typescript
466
+ * call.hold(true);
467
+ * ```
468
+ * @example
469
+ * To take a call off hold
470
+ * ```typescript
471
+ * call.hold(false);
472
+ * ```
473
+ *
474
+ * @param hold - A `boolean` representing whether or not to put this end of
475
+ * the call on hold.
476
+ *
477
+ * @returns
478
+ * A `Promise` that
479
+ * - Resolves with the hold status when the call is put on hold or not on
480
+ * hold.
481
+ * - Rejects when the call is not able to be put on hold or not on hold.
482
+ */
483
+
484
+
485
+ async hold(hold) {
486
+ this._isOnHold = await _common.NativeModule.call_hold(this._uuid, hold);
487
+ return this._isOnHold;
488
+ }
489
+ /**
490
+ * Mute or unmute this end of the call.
491
+ *
492
+ * @example
493
+ * To mute a call
494
+ * ```typescript
495
+ * call.mute(true);
496
+ * ```
497
+ *
498
+ * @example
499
+ * To unmute a call
500
+ * ```typescript
501
+ * call.mute(false);
502
+ * ```
503
+ *
504
+ * @param mute - A `boolean` representing whether or not to mute this end of
505
+ * the call.
506
+ *
507
+ * @returns
508
+ * A `Promise` that
509
+ * - Resolves with the muted status of the call when the call is muted or
510
+ * unmuted.
511
+ * - Rejects when the call is not able to be muted or unmuted.
512
+ */
513
+
514
+
515
+ async mute(mute) {
516
+ this._isMuted = await _common.NativeModule.call_mute(this._uuid, mute);
517
+ return this._isMuted;
518
+ }
519
+ /**
520
+ * Send DTMF digits.
521
+ *
522
+ * @example
523
+ * To send the `0` dialtone:
524
+ * ```typescript
525
+ * call.sendDigits('0');
526
+ * ```
527
+ *
528
+ * @example
529
+ * To send the `0` and then `1` dialtone:
530
+ * ```typescript
531
+ * call.sendDigits('01');
532
+ * ```
533
+ *
534
+ * @param digits - A sequence of DTMF digits in a string.
535
+ *
536
+ * @returns
537
+ * A `Promise` that
538
+ * - Resolves when the DTMF digits have been sent.
539
+ * - Rejects when DTMF tones are not able to be sent.
540
+ */
541
+
542
+
543
+ sendDigits(digits) {
544
+ return _common.NativeModule.call_sendDigits(this._uuid, digits);
545
+ }
546
+ /**
547
+ * Send a CallMessage.
548
+ *
549
+ * @example
550
+ * To send a user-defined-message
551
+ * ```typescript
552
+ * const outgoingCallMessage: OutgoingCallMessage = await call.sendMessage({
553
+ * content: { key1: 'This is a messsage from the parent call' },
554
+ * contentType: 'application/json',
555
+ * messageType: 'user-defined-message'
556
+ * });
557
+ *
558
+ * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Failure, (error) => {
559
+ * // outgoingCallMessage failed, handle error
560
+ * });
561
+ *
562
+ * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Sent, () => {
563
+ * // outgoingCallMessage sent
564
+ * });
565
+ * ```
566
+ *
567
+ * @param message - The call message to send.
568
+ *
569
+ * @returns
570
+ * A `Promise` that
571
+ * - Resolves with the OutgoingCallMessage object.
572
+ * - Rejects when the message is unable to be sent.
573
+ */
574
+
575
+
576
+ async sendMessage(message) {
577
+ const {
578
+ content,
579
+ contentType,
580
+ messageType
581
+ } = (0, _CallMessage.validateCallMessage)(message);
582
+ const voiceEventSid = await _common.NativeModule.call_sendMessage(this._uuid, content, contentType, messageType);
583
+ const outgoingCallMessage = new _OutgoingCallMessage.OutgoingCallMessage({
584
+ content,
585
+ contentType,
586
+ messageType,
587
+ voiceEventSid
588
+ });
589
+ return outgoingCallMessage;
590
+ }
591
+ /**
592
+ * Post feedback about a call.
593
+ *
594
+ * @example
595
+ * To report that a call had very significant audio latency:
596
+ * ```typescript
597
+ * call.postFeedback(Call.Score.Five, Call.Issue.AudioLatency);
598
+ * ```
599
+ *
600
+ * @param score - A score representing the serverity of the issue being
601
+ * reported.
602
+ * @param issue - The issue being reported.
603
+ * @returns
604
+ * A `Promise` that
605
+ * - Resolves when the feedback has been posted.
606
+ * - Rejects when the feedback is unable to be sent.
607
+ */
608
+
609
+
610
+ async postFeedback(score, issue) {
611
+ if (!validScores.includes(score)) {
612
+ throw new _InvalidArgumentError.InvalidArgumentError('"score" parameter invalid. Must be a member of the `Call.Score` enum.');
613
+ }
614
+
615
+ if (!Object.values(Call.Issue).includes(issue)) {
616
+ throw new _InvalidArgumentError.InvalidArgumentError('"issue" parameter invalid. Must be a member of the `Call.Issue` enum.');
617
+ }
618
+
619
+ const nativeScore = scoreMap[score];
620
+ const nativeIssue = issueMap[issue];
621
+ return _common.NativeModule.call_postFeedback(this._uuid, nativeScore, nativeIssue);
622
+ }
623
+
624
+ }
625
+ /**
626
+ * Namespace for enumerations and types used by
627
+ * {@link (Call:class) | Call objects}.
628
+ *
629
+ * @remarks
630
+ * - See also the {@link (Call:class) | Call class}.
631
+ * - See also the {@link (Call:interface) | Call interface}.
632
+ *
633
+ * @public
634
+ */
635
+
636
+
637
+ exports.Call = Call;
638
+
639
+ (function (_Call) {
640
+ let Event;
641
+
642
+ (function (Event) {
643
+ Event["Connected"] = "connected";
644
+ Event["ConnectFailure"] = "connectFailure";
645
+ Event["Reconnecting"] = "reconnecting";
646
+ Event["Reconnected"] = "reconnected";
647
+ Event["Disconnected"] = "disconnected";
648
+ Event["Ringing"] = "ringing";
649
+ Event["QualityWarningsChanged"] = "qualityWarningsChanged";
650
+ Event["MessageReceived"] = "messageReceived";
651
+ })(Event || (Event = {}));
652
+
653
+ _Call.Event = Event;
654
+ let State;
655
+
656
+ (function (State) {
657
+ State[State["Connected"] = _constants.Constants.CallStateConnected] = "Connected";
658
+ State[State["Connecting"] = _constants.Constants.CallStateConnecting] = "Connecting";
659
+ State[State["Disconnected"] = _constants.Constants.CallStateDisconnected] = "Disconnected";
660
+ State[State["Reconnecting"] = _constants.Constants.CallStateReconnecting] = "Reconnecting";
661
+ State[State["Ringing"] = _constants.Constants.CallStateRinging] = "Ringing";
662
+ })(State || (State = {}));
663
+
664
+ _Call.State = State;
665
+ let QualityWarning;
666
+
667
+ (function (QualityWarning) {
668
+ QualityWarning["ConstantAudioInputLevel"] = "constant-audio-input-level";
669
+ QualityWarning["HighJitter"] = "high-jitter";
670
+ QualityWarning["HighPacketLoss"] = "high-packet-loss";
671
+ QualityWarning["HighRtt"] = "high-rtt";
672
+ QualityWarning["LowMos"] = "low-mos";
673
+ })(QualityWarning || (QualityWarning = {}));
674
+
675
+ _Call.QualityWarning = QualityWarning;
676
+ let Score;
677
+
678
+ (function (Score) {
679
+ Score[Score["NotReported"] = 0] = "NotReported";
680
+ Score[Score["One"] = 1] = "One";
681
+ Score[Score["Two"] = 2] = "Two";
682
+ Score[Score["Three"] = 3] = "Three";
683
+ Score[Score["Four"] = 4] = "Four";
684
+ Score[Score["Five"] = 5] = "Five";
685
+ })(Score || (Score = {}));
686
+
687
+ _Call.Score = Score;
688
+ let Issue;
689
+
690
+ (function (Issue) {
691
+ Issue["NotReported"] = "not-reported";
692
+ Issue["DroppedCall"] = "dropped-call";
693
+ Issue["AudioLatency"] = "audio-latency";
694
+ Issue["OneWayAudio"] = "one-way-audio";
695
+ Issue["ChoppyAudio"] = "choppy-audio";
696
+ Issue["NoisyCall"] = "noisy-call";
697
+ Issue["Echo"] = "echo";
698
+ })(Issue || (Issue = {}));
699
+
700
+ _Call.Issue = Issue;
701
+ let Listener;
702
+
703
+ (function (_Listener) {})(Listener || (Listener = _Call.Listener || (_Call.Listener = {})));
704
+ })(Call || (exports.Call = Call = {}));
705
+ /**
706
+ * Mapping of {@link (Call:namespace).Event | Call events} to
707
+ * {@link (Call:namespace).State | Call states}.
708
+ *
709
+ * @remarks
710
+ * Note that this mapping is not a 1:1 bijection. Not every event coming from
711
+ * the native layer has a relevant state, and some events share a state.
712
+ * Therefore, this `Record` needs to be marked as `Partial` and
713
+ * undefined-checking logic is needed when using this mapping.
714
+ *
715
+ * @internal
716
+ */
717
+
718
+
719
+ const eventTypeStateMap = {
720
+ [_constants.Constants.CallEventConnected]: Call.State.Connected,
721
+ [_constants.Constants.CallEventConnectFailure]: Call.State.Disconnected,
722
+ [_constants.Constants.CallEventDisconnected]: Call.State.Disconnected,
723
+ [_constants.Constants.CallEventReconnecting]: Call.State.Reconnecting,
724
+ [_constants.Constants.CallEventReconnected]: Call.State.Connected,
725
+ [_constants.Constants.CallEventRinging]: Call.State.Ringing
726
+ };
727
+ /**
728
+ * Array of valid call scores.
729
+ *
730
+ * @internal
731
+ */
732
+
733
+ const validScores = [Call.Score.NotReported, Call.Score.One, Call.Score.Two, Call.Score.Three, Call.Score.Four, Call.Score.Five];
734
+ /**
735
+ * Mapping of the {@link (Call:namespace).Score | Call score} enum to
736
+ * cross-platform common constants.
737
+ *
738
+ * @internal
739
+ */
740
+
741
+ const scoreMap = {
742
+ [Call.Score.NotReported]: _constants.Constants.CallFeedbackScoreNotReported,
743
+ [Call.Score.One]: _constants.Constants.CallFeedbackScoreOne,
744
+ [Call.Score.Two]: _constants.Constants.CallFeedbackScoreTwo,
745
+ [Call.Score.Three]: _constants.Constants.CallFeedbackScoreThree,
746
+ [Call.Score.Four]: _constants.Constants.CallFeedbackScoreFour,
747
+ [Call.Score.Five]: _constants.Constants.CallFeedbackScoreFive
748
+ };
749
+ /**
750
+ * Mapping of the {@link (Call:namespace).Issue | Call issue} enum to
751
+ * cross-platform common constants.
752
+ *
753
+ * @internal
754
+ */
755
+
756
+ const issueMap = {
757
+ [Call.Issue.AudioLatency]: _constants.Constants.CallFeedbackIssueAudioLatency,
758
+ [Call.Issue.ChoppyAudio]: _constants.Constants.CallFeedbackIssueChoppyAudio,
759
+ [Call.Issue.DroppedCall]: _constants.Constants.CallFeedbackIssueDroppedCall,
760
+ [Call.Issue.Echo]: _constants.Constants.CallFeedbackIssueEcho,
761
+ [Call.Issue.NoisyCall]: _constants.Constants.CallFeedbackIssueNoisyCall,
762
+ [Call.Issue.NotReported]: _constants.Constants.CallFeedbackIssueNotReported,
763
+ [Call.Issue.OneWayAudio]: _constants.Constants.CallFeedbackIssueOneWayAudio
764
+ };
765
+ //# sourceMappingURL=Call.js.map