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,83 @@
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 { InvalidArgumentError } from '../error/InvalidArgumentError';
9
+
10
+ /**
11
+ * The constituent values of a Call Message.
12
+ *
13
+ * @public
14
+ */
15
+ export interface CallMessage {
16
+ /**
17
+ * The content of the message. This value should match the content type
18
+ * parameter.
19
+ *
20
+ * See {@link CallMessage.contentType} for more information.
21
+ */
22
+ content: any;
23
+
24
+ /**
25
+ * The content type of the message. This value should accurately describe
26
+ * the content of the message. The following values are accepted:
27
+ *
28
+ * - "application/json"
29
+ *
30
+ * If no value is defined, then the default value of "application/json" will
31
+ * be used.
32
+ *
33
+ * If the `contentType` of the message is "application/json", the content
34
+ * of the message may be a JS object.
35
+ */
36
+ contentType?: string;
37
+
38
+ /**
39
+ * The message type. The following values are accepted:
40
+ *
41
+ * - "user-defined-message"
42
+ */
43
+ messageType: string;
44
+ }
45
+
46
+ /**
47
+ * Parse CallMessage values. Used when constructing a CallMessage from the
48
+ * native layer, or by the Call and CallInvite classes when sending a
49
+ * CallMessage.
50
+ *
51
+ * @param message the CallMessage details.
52
+ *
53
+ * @internal
54
+ */
55
+ export function validateCallMessage(message: CallMessage) {
56
+ const content = message.content;
57
+ const messageType = message.messageType;
58
+
59
+ let contentType = message.contentType;
60
+
61
+ if (typeof contentType === 'undefined') {
62
+ contentType = 'application/json';
63
+ }
64
+
65
+ if (typeof contentType !== 'string') {
66
+ throw new InvalidArgumentError(
67
+ 'If "contentType" is present, it must be of type "string".'
68
+ );
69
+ }
70
+
71
+ if (typeof messageType !== 'string') {
72
+ throw new InvalidArgumentError('"messageType" must be of type "string".');
73
+ }
74
+
75
+ if (typeof content === 'undefined' || content === null) {
76
+ throw new InvalidArgumentError('"content" must be defined and not "null".');
77
+ }
78
+
79
+ const contentStr =
80
+ typeof content === 'string' ? content : JSON.stringify(content);
81
+
82
+ return { content: contentStr, contentType, messageType };
83
+ }
@@ -0,0 +1,104 @@
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 { NativeCallMessageInfo } from '../type/CallMessage';
10
+ import { validateCallMessage } from './CallMessage';
11
+
12
+ /**
13
+ * CallMessage API is in beta.
14
+ *
15
+ * Provides access to information about a CallMessage, including the call
16
+ * message content, content type, message type, and voice event SID.
17
+ *
18
+ * @public
19
+ */
20
+ export class IncomingCallMessage extends EventEmitter {
21
+ /**
22
+ * The content of the message which should match the contentType parameter.
23
+ */
24
+ private _content: any;
25
+
26
+ /**
27
+ * The MIME type of the content.
28
+ */
29
+ private _contentType: string;
30
+
31
+ /**
32
+ * Message type
33
+ */
34
+ private _messageType: string;
35
+
36
+ /**
37
+ * An autogenerated ID that uniquely identifies this message.
38
+ * This is not required when sending a message from the SDK as this is
39
+ * autogenerated.
40
+ * The ID will be available after the message is sent, or immediately when a
41
+ * message is received.
42
+ */
43
+ private _voiceEventSid?: string;
44
+
45
+ /**
46
+ * Constructor for the {@link IncomingCallMessage} class. This should not be
47
+ * invoked by third-party code.
48
+ *
49
+ * @param NativeCallMessageInfo - An object containing all of the data from
50
+ * the native layer necessary to fully describe a call message, as well as
51
+ * invoke native functionality for the call message.
52
+ *
53
+ * @internal
54
+ */
55
+ constructor(callMessageInfo: NativeCallMessageInfo) {
56
+ super();
57
+
58
+ const { content, contentType, messageType } =
59
+ validateCallMessage(callMessageInfo);
60
+
61
+ this._content = content;
62
+ this._contentType = contentType;
63
+ this._messageType = messageType;
64
+ this._voiceEventSid = callMessageInfo.voiceEventSid;
65
+ }
66
+
67
+ /**
68
+ * {@inheritdoc CallMessage.content}
69
+ *
70
+ * @returns the content of the call message.
71
+ */
72
+ getContent(): any {
73
+ return this._content;
74
+ }
75
+
76
+ /**
77
+ * {@inheritdoc CallMessage.contentType}
78
+ *
79
+ * @returns the content type of the call message.
80
+ */
81
+ getContentType(): string {
82
+ return this._contentType;
83
+ }
84
+
85
+ /**
86
+ * {@inheritdoc CallMessage.messageType}
87
+ *
88
+ * @returns the message type of the call message.
89
+ */
90
+ getMessageType(): string {
91
+ return this._messageType;
92
+ }
93
+
94
+ /**
95
+ * Get the message SID.
96
+ * @returns
97
+ * - A string representing the message SID.
98
+ * - `undefined` if the call information has not yet been received from the
99
+ * native layer.
100
+ */
101
+ getSid(): string | undefined {
102
+ return this._voiceEventSid;
103
+ }
104
+ }
@@ -0,0 +1,308 @@
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 type { TwilioError } from '../error';
9
+ import type {
10
+ NativeCallMessageEvent,
11
+ NativeCallMessageEventType,
12
+ NativeCallMessageInfo,
13
+ } from '../type/CallMessage';
14
+ import { Constants } from '../constants';
15
+ import { NativeEventEmitter } from '../common';
16
+ import { constructTwilioError } from '../error/utility';
17
+ import { IncomingCallMessage } from './IncomingCallMessage';
18
+
19
+ /**
20
+ * Defines strict typings for all events emitted by
21
+ * {@link (OutgoingCallMessage:class) | OutgoingCallMessage objects}.
22
+ *
23
+ * @remarks
24
+ * Note that the `on` function is an alias for the `addListener` function.
25
+ * They share identical functionality and either may be used interchangeably.
26
+ *
27
+ * - See also the {@link CallMessage} interface.
28
+ * - See also the {@link IncomingCallMessage} class.
29
+ * - See also the {@link (OutgoingCallMessage:namespace)} namespace.
30
+ *
31
+ * @public
32
+ */
33
+ export declare interface OutgoingCallMessage {
34
+ /**
35
+ * ------------
36
+ * Emit Typings
37
+ * ------------
38
+ */
39
+
40
+ /** @internal */
41
+ emit(
42
+ failureEvent: OutgoingCallMessage.Event.Failure,
43
+ error: TwilioError
44
+ ): boolean;
45
+
46
+ /** @internal */
47
+ emit(sentEvent: OutgoingCallMessage.Event.Sent): boolean;
48
+
49
+ /**
50
+ * ----------------
51
+ * Listener Typings
52
+ * ----------------
53
+ */
54
+
55
+ /**
56
+ * Failure event. Raised when outgoingCallMessage fails to be sent out.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Failure, (error) => {
61
+ * // outgoingCallMessage failed, handle error
62
+ * });
63
+ * ```
64
+ *
65
+ * @param failureEvent - The raised event string.
66
+ * @param listener - A listener function that will be invoked when the event
67
+ * is raised.
68
+ * @returns - The callMessage object.
69
+ */
70
+ addListener(
71
+ failureEvent: OutgoingCallMessage.Event.Failure,
72
+ listener: OutgoingCallMessage.Listener.Failure
73
+ ): this;
74
+ /** {@inheritDoc (OutgoingCallMessage:interface).(addListener:1)} */
75
+ on(
76
+ failureEvent: OutgoingCallMessage.Event.Failure,
77
+ listener: OutgoingCallMessage.Listener.Failure
78
+ ): this;
79
+
80
+ /**
81
+ * Sent event. Raised when outgoingCallMessage is sent.
82
+ * @example
83
+ * ```typescript
84
+ * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Sent, () => {
85
+ * // outgoingCallMessage sent
86
+ * })
87
+ * ```
88
+ *
89
+ * @param sentEvent - The raised event string.
90
+ * @param listener - A listener function that will be invoked when the event
91
+ * is raised.
92
+ * @returns - The callMessage object
93
+ */
94
+ addListener(
95
+ sentEvent: OutgoingCallMessage.Event.Sent,
96
+ listener: OutgoingCallMessage.Listener.Sent
97
+ ): this;
98
+ /** {@inheritDoc (OutgoingCallMessage:interface).(addListener:2)} */
99
+ on(
100
+ sentEvent: OutgoingCallMessage.Event.Sent,
101
+ listener: OutgoingCallMessage.Listener.Sent
102
+ ): this;
103
+
104
+ /**
105
+ * Generic event listener typings.
106
+ * @param outgoingCallMessageEvent - The raised event string.
107
+ * @param listener - A listener function that will be invoked when the event
108
+ * is raised.
109
+ * @returns - The outgoingCallMessage object.
110
+ */
111
+ addListener(
112
+ outgoingCallMessageEvent: OutgoingCallMessage.Event,
113
+ listener: OutgoingCallMessage.Listener.Generic
114
+ ): this;
115
+ /**
116
+ * {@inheritDoc (OutgoingCallMessage:interface).(addListener:3)}
117
+ */
118
+ on(
119
+ outgoingCallMessageEvent: OutgoingCallMessage.Event,
120
+ listener: OutgoingCallMessage.Listener.Generic
121
+ ): this;
122
+ }
123
+
124
+ /**
125
+ * CallMessage API is in beta.
126
+ *
127
+ * Provides access to information about a outgoingCallMessage, including the call
128
+ * message content, contentType, messageType, and voiceEventSid
129
+ *
130
+ * @remarks
131
+ * Note that the outgoingCallMessage information is fetched as soon as possible from the
132
+ * native layer, but there is no guarantee that all information is immediately
133
+ * available. Methods such as `OutgoingCallMessage.getContent` or `OutgoingCallMessage.getSid`
134
+ * may return `undefined`.
135
+ *
136
+ * As outgoingCallMessage events are received from the native layer, outgoingCallMessage information will
137
+ * propagate from the native layer to the JS layer and become available.
138
+ * Therefore, it is good practice to read information from the outgoingCallMessage after an
139
+ * event occurs, or as events occur.
140
+ *
141
+ * - See the {@link (OutgoingCallMessage:namespace).Event} enum for events emitted by `OutgoingCallMessage`
142
+ * objects.
143
+ * - See the {@link (OutgoingCallMessage:interface) | OutgoingCallMessage interface} for overloaded event listening
144
+ * metods.
145
+ * - See the {@link (OutgoingCallMessage:namespace) | OutgoingCallMessage namespace} for types and enumerations
146
+ * used by this class.
147
+ *
148
+ * @public
149
+ */
150
+ export class OutgoingCallMessage extends IncomingCallMessage {
151
+ /**
152
+ * Handlers for native OutgoingCallMessage events. Set upon construction so we can
153
+ * dynamically bind events to handlers.
154
+ *
155
+ * @privateRemarks
156
+ * This is done by the constructor so this mapping isn't made every time the
157
+ * {@link (OutgoingCallMessage:class)._handleNativeEvent} function is invoked.
158
+ */
159
+ private _nativeEventHandler: Record<
160
+ NativeCallMessageEventType,
161
+ (callEvent: NativeCallMessageEvent) => void
162
+ >;
163
+ constructor({
164
+ content,
165
+ contentType,
166
+ messageType,
167
+ voiceEventSid,
168
+ }: NativeCallMessageInfo) {
169
+ super({
170
+ content,
171
+ contentType,
172
+ messageType,
173
+ voiceEventSid,
174
+ });
175
+
176
+ this._nativeEventHandler = {
177
+ /**
178
+ * Sending Call Message State
179
+ */
180
+ [Constants.CallEventMessageFailure]: this._handleFailureEvent,
181
+ [Constants.CallEventMessageSent]: this._handleSentEvent,
182
+ };
183
+ NativeEventEmitter.addListener(
184
+ Constants.ScopeCallMessage,
185
+ this._handleNativeEvent
186
+ );
187
+ }
188
+
189
+ /**
190
+ * This intermediate native callMessage event handler acts as a "gate".
191
+ * @param nativeCallMessageEvent - A callMessage event directly from the native layer.
192
+ */
193
+ private _handleNativeEvent = (
194
+ nativeCallMessageEvent: NativeCallMessageEvent
195
+ ) => {
196
+ const { type } = nativeCallMessageEvent;
197
+
198
+ const handler = this._nativeEventHandler[type];
199
+ if (typeof handler === 'undefined') {
200
+ throw new Error(
201
+ `Unknown callMessage event type received from the native layer: "${type}"`
202
+ );
203
+ }
204
+
205
+ if (this.getSid() === nativeCallMessageEvent.voiceEventSid) {
206
+ handler(nativeCallMessageEvent);
207
+ }
208
+ };
209
+
210
+ /**
211
+ * Handler for the {@link (OutgoingCallMessage:namespace).Event.Failure} event.
212
+ * @param nativeCallMessageEvent - The native callMessage event.
213
+ */
214
+ private _handleFailureEvent = (
215
+ nativeCallMessageEvent: NativeCallMessageEvent
216
+ ) => {
217
+ if (nativeCallMessageEvent.type !== Constants.CallEventMessageFailure) {
218
+ throw new Error(
219
+ 'Incorrect "outgoingCallMessage#Failure" handler called for type' +
220
+ `"${nativeCallMessageEvent.type}`
221
+ );
222
+ }
223
+
224
+ const { message, code } = nativeCallMessageEvent.error;
225
+ const error = constructTwilioError(message, code);
226
+ this.emit(OutgoingCallMessage.Event.Failure, error);
227
+ };
228
+
229
+ /**
230
+ * Handler for the {@link (OutgoingCallMessage:namespace).Event.Sent} event.
231
+ * @param nativeCallMessageEvent - The native callMessage event.
232
+ */
233
+ private _handleSentEvent = (
234
+ nativeCallMessageEvent: NativeCallMessageEvent
235
+ ) => {
236
+ if (nativeCallMessageEvent.type !== Constants.CallEventMessageSent) {
237
+ throw new Error(
238
+ 'Incorrect "outgoingCallMessage#Sent" handler called for type' +
239
+ `"${nativeCallMessageEvent.type}"`
240
+ );
241
+ }
242
+
243
+ this.emit(OutgoingCallMessage.Event.Sent);
244
+ };
245
+ }
246
+
247
+ /**
248
+ * Namespace for enumerations and types used by
249
+ * {@link (OutgoingCallMessage:class) | OutgoingCallMessage objects}.
250
+ *
251
+ * @remarks
252
+ * - See also the {@link (OutgoingCallMessage:class) | OutgoingCallMessage class}.
253
+ * - See also the {@link (OutgoingCallMessage:interface) | OutgoingCallMessage interface}.
254
+ *
255
+ * @public
256
+ */
257
+ export namespace OutgoingCallMessage {
258
+ /**
259
+ * Enumeration of all event strings emitted by {@link (OutgoingCallMessage:class)} objects.
260
+ */
261
+ export enum Event {
262
+ /**
263
+ * Raised when outgoingCallMessage fails.
264
+ * See {@link (OutgoingCallMessage:interface).(addListener:1)}.
265
+ */
266
+ 'Failure' = 'failure',
267
+ /**
268
+ * Raised when outgoingCallMessage has been sent.
269
+ * See {@link (OutgoingCallMessage:interface).(addListener:2)}.
270
+ */
271
+ 'Sent' = 'sent',
272
+ }
273
+
274
+ /**
275
+ * Listener types for all events emitted by a
276
+ * {@link (OutgoingCallMessage:class) | OutgoingCallMessage: object}
277
+ */
278
+ export namespace Listener {
279
+ /**
280
+ * OutgoingCallMessage failure event listener. This should be the function signature of
281
+ * any event listener bound to the {@link (OutgoingCallMessage:namespace).Event.Failure} event.
282
+ *
283
+ * @remarks
284
+ * See {@link (OutgoingCallMessage:interface).(addListener:1)}.
285
+ *
286
+ * See {@link TwilioErrors} for all error classes.
287
+ */
288
+ export type Failure = (error: TwilioError) => void;
289
+
290
+ /**
291
+ * OutgoingCallMessage sent event listner. This should be the function signature of
292
+ * any event listener bound to the {@link (OutgoingCallMessage:namespace).Event.Sent} event.
293
+ *
294
+ * @remarks
295
+ * See {@link (OutgoingCallMessage:interface).(addListener:2)}.
296
+ */
297
+ export type Sent = () => void;
298
+
299
+ /**
300
+ * Generic event listener. This should be the function signature of any
301
+ * event listener bound to any OutgoingCallMessage event.
302
+ *
303
+ * @remarks
304
+ * See {@link (OutgoingCallMessage:interface).(addListener:3)}.
305
+ */
306
+ export type Generic = (...args: any[]) => void;
307
+ }
308
+ }
@@ -0,0 +1,59 @@
1
+ import { NativeModule, Platform } from './common';
2
+ import { requireNativeModule } from 'expo-modules-core';
3
+ import { Call } from './Call';
4
+ import type { NativeCallInfo } from './type/Call';
5
+
6
+ interface ConnectOptions {
7
+ params?: Record<string, any>;
8
+ customParameters?: Record<string, any>;
9
+ }
10
+
11
+ class ExpoNativeModule {
12
+ private androidExpoNativeModule =
13
+ Platform.OS === 'android'
14
+ ? (() => {
15
+ try {
16
+ return requireNativeModule('TwilioVoiceExpo');
17
+ } catch (e) {
18
+ console.warn('TwilioVoiceExpo native module not found');
19
+ return null;
20
+ }
21
+ })()
22
+ : null;
23
+
24
+ async voice_connect(accessToken: string, options: ConnectOptions = {}) {
25
+ const { params = {}, customParameters = {} } = options;
26
+ let info: NativeCallInfo;
27
+ if (Platform.OS === 'android' && this.androidExpoNativeModule) {
28
+ info = await this.androidExpoNativeModule.voice_connect(
29
+ accessToken,
30
+ params,
31
+ customParameters
32
+ );
33
+ } else if (Platform.OS === 'ios') {
34
+ info = await NativeModule.voice_connect_ios(
35
+ accessToken,
36
+ params,
37
+ // @ts-ignore
38
+ customParameters
39
+ );
40
+ } else {
41
+ throw new Error('Unsupported platform');
42
+ }
43
+ return new Call(info);
44
+ }
45
+
46
+ async disconnect() {
47
+ if (Platform.OS === 'android' && this.androidExpoNativeModule) {
48
+ return this.androidExpoNativeModule.voice_disconnect?.();
49
+ }
50
+ return NativeModule.voice_disconnect_ios?.();
51
+ }
52
+
53
+ isExpoEnvironment(): boolean {
54
+ return Platform.OS === 'android';
55
+ }
56
+ }
57
+
58
+ export const ExpoModule = new ExpoNativeModule();
59
+ export default ExpoModule;