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,51 @@
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
+ import { InvalidArgumentError } from '../error/InvalidArgumentError';
8
+ /**
9
+ * The constituent values of a Call Message.
10
+ *
11
+ * @public
12
+ */
13
+
14
+ /**
15
+ * Parse CallMessage values. Used when constructing a CallMessage from the
16
+ * native layer, or by the Call and CallInvite classes when sending a
17
+ * CallMessage.
18
+ *
19
+ * @param message the CallMessage details.
20
+ *
21
+ * @internal
22
+ */
23
+ export function validateCallMessage(message) {
24
+ const content = message.content;
25
+ const messageType = message.messageType;
26
+ let contentType = message.contentType;
27
+
28
+ if (typeof contentType === 'undefined') {
29
+ contentType = 'application/json';
30
+ }
31
+
32
+ if (typeof contentType !== 'string') {
33
+ throw new InvalidArgumentError('If "contentType" is present, it must be of type "string".');
34
+ }
35
+
36
+ if (typeof messageType !== 'string') {
37
+ throw new InvalidArgumentError('"messageType" must be of type "string".');
38
+ }
39
+
40
+ if (typeof content === 'undefined' || content === null) {
41
+ throw new InvalidArgumentError('"content" must be defined and not "null".');
42
+ }
43
+
44
+ const contentStr = typeof content === 'string' ? content : JSON.stringify(content);
45
+ return {
46
+ content: contentStr,
47
+ contentType,
48
+ messageType
49
+ };
50
+ }
51
+ //# sourceMappingURL=CallMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["CallMessage.ts"],"names":["InvalidArgumentError","validateCallMessage","message","content","messageType","contentType","contentStr","JSON","stringify"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,oBAAT,QAAqC,+BAArC;AAEA;AACA;AACA;AACA;AACA;;AAgCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAT,CAA6BC,OAA7B,EAAmD;AACxD,QAAMC,OAAO,GAAGD,OAAO,CAACC,OAAxB;AACA,QAAMC,WAAW,GAAGF,OAAO,CAACE,WAA5B;AAEA,MAAIC,WAAW,GAAGH,OAAO,CAACG,WAA1B;;AAEA,MAAI,OAAOA,WAAP,KAAuB,WAA3B,EAAwC;AACtCA,IAAAA,WAAW,GAAG,kBAAd;AACD;;AAED,MAAI,OAAOA,WAAP,KAAuB,QAA3B,EAAqC;AACnC,UAAM,IAAIL,oBAAJ,CACJ,2DADI,CAAN;AAGD;;AAED,MAAI,OAAOI,WAAP,KAAuB,QAA3B,EAAqC;AACnC,UAAM,IAAIJ,oBAAJ,CAAyB,yCAAzB,CAAN;AACD;;AAED,MAAI,OAAOG,OAAP,KAAmB,WAAnB,IAAkCA,OAAO,KAAK,IAAlD,EAAwD;AACtD,UAAM,IAAIH,oBAAJ,CAAyB,2CAAzB,CAAN;AACD;;AAED,QAAMM,UAAU,GACd,OAAOH,OAAP,KAAmB,QAAnB,GAA8BA,OAA9B,GAAwCI,IAAI,CAACC,SAAL,CAAeL,OAAf,CAD1C;AAGA,SAAO;AAAEA,IAAAA,OAAO,EAAEG,UAAX;AAAuBD,IAAAA,WAAvB;AAAoCD,IAAAA;AAApC,GAAP;AACD","sourcesContent":["/**\n * Copyright © 2022 Twilio, Inc. All rights reserved. Licensed under the Twilio\n * license.\n *\n * See LICENSE in the project root for license information.\n */\n\nimport { InvalidArgumentError } from '../error/InvalidArgumentError';\n\n/**\n * The constituent values of a Call Message.\n *\n * @public\n */\nexport interface CallMessage {\n /**\n * The content of the message. This value should match the content type\n * parameter.\n *\n * See {@link CallMessage.contentType} for more information.\n */\n content: any;\n\n /**\n * The content type of the message. This value should accurately describe\n * the content of the message. The following values are accepted:\n *\n * - \"application/json\"\n *\n * If no value is defined, then the default value of \"application/json\" will\n * be used.\n *\n * If the `contentType` of the message is \"application/json\", the content\n * of the message may be a JS object.\n */\n contentType?: string;\n\n /**\n * The message type. The following values are accepted:\n *\n * - \"user-defined-message\"\n */\n messageType: string;\n}\n\n/**\n * Parse CallMessage values. Used when constructing a CallMessage from the\n * native layer, or by the Call and CallInvite classes when sending a\n * CallMessage.\n *\n * @param message the CallMessage details.\n *\n * @internal\n */\nexport function validateCallMessage(message: CallMessage) {\n const content = message.content;\n const messageType = message.messageType;\n\n let contentType = message.contentType;\n\n if (typeof contentType === 'undefined') {\n contentType = 'application/json';\n }\n\n if (typeof contentType !== 'string') {\n throw new InvalidArgumentError(\n 'If \"contentType\" is present, it must be of type \"string\".'\n );\n }\n\n if (typeof messageType !== 'string') {\n throw new InvalidArgumentError('\"messageType\" must be of type \"string\".');\n }\n\n if (typeof content === 'undefined' || content === null) {\n throw new InvalidArgumentError('\"content\" must be defined and not \"null\".');\n }\n\n const contentStr =\n typeof content === 'string' ? content : JSON.stringify(content);\n\n return { content: contentStr, contentType, messageType };\n}\n"]}
@@ -0,0 +1,116 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /**
4
+ * Copyright © 2022 Twilio, Inc. All rights reserved. Licensed under the Twilio
5
+ * license.
6
+ *
7
+ * See LICENSE in the project root for license information.
8
+ */
9
+ import { EventEmitter } from 'eventemitter3';
10
+ import { validateCallMessage } from './CallMessage';
11
+ /**
12
+ * CallMessage API is in beta.
13
+ *
14
+ * Provides access to information about a CallMessage, including the call
15
+ * message content, content type, message type, and voice event SID.
16
+ *
17
+ * @public
18
+ */
19
+
20
+ export class IncomingCallMessage extends EventEmitter {
21
+ /**
22
+ * The content of the message which should match the contentType parameter.
23
+ */
24
+
25
+ /**
26
+ * The MIME type of the content.
27
+ */
28
+
29
+ /**
30
+ * Message type
31
+ */
32
+
33
+ /**
34
+ * An autogenerated ID that uniquely identifies this message.
35
+ * This is not required when sending a message from the SDK as this is
36
+ * autogenerated.
37
+ * The ID will be available after the message is sent, or immediately when a
38
+ * message is received.
39
+ */
40
+
41
+ /**
42
+ * Constructor for the {@link IncomingCallMessage} class. This should not be
43
+ * invoked by third-party code.
44
+ *
45
+ * @param NativeCallMessageInfo - An object containing all of the data from
46
+ * the native layer necessary to fully describe a call message, as well as
47
+ * invoke native functionality for the call message.
48
+ *
49
+ * @internal
50
+ */
51
+ constructor(callMessageInfo) {
52
+ super();
53
+
54
+ _defineProperty(this, "_content", void 0);
55
+
56
+ _defineProperty(this, "_contentType", void 0);
57
+
58
+ _defineProperty(this, "_messageType", void 0);
59
+
60
+ _defineProperty(this, "_voiceEventSid", void 0);
61
+
62
+ const {
63
+ content,
64
+ contentType,
65
+ messageType
66
+ } = validateCallMessage(callMessageInfo);
67
+ this._content = content;
68
+ this._contentType = contentType;
69
+ this._messageType = messageType;
70
+ this._voiceEventSid = callMessageInfo.voiceEventSid;
71
+ }
72
+ /**
73
+ * {@inheritdoc CallMessage.content}
74
+ *
75
+ * @returns the content of the call message.
76
+ */
77
+
78
+
79
+ getContent() {
80
+ return this._content;
81
+ }
82
+ /**
83
+ * {@inheritdoc CallMessage.contentType}
84
+ *
85
+ * @returns the content type of the call message.
86
+ */
87
+
88
+
89
+ getContentType() {
90
+ return this._contentType;
91
+ }
92
+ /**
93
+ * {@inheritdoc CallMessage.messageType}
94
+ *
95
+ * @returns the message type of the call message.
96
+ */
97
+
98
+
99
+ getMessageType() {
100
+ return this._messageType;
101
+ }
102
+ /**
103
+ * Get the message SID.
104
+ * @returns
105
+ * - A string representing the message SID.
106
+ * - `undefined` if the call information has not yet been received from the
107
+ * native layer.
108
+ */
109
+
110
+
111
+ getSid() {
112
+ return this._voiceEventSid;
113
+ }
114
+
115
+ }
116
+ //# sourceMappingURL=IncomingCallMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["IncomingCallMessage.ts"],"names":["EventEmitter","validateCallMessage","IncomingCallMessage","constructor","callMessageInfo","content","contentType","messageType","_content","_contentType","_messageType","_voiceEventSid","voiceEventSid","getContent","getContentType","getMessageType","getSid"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,YAAT,QAA6B,eAA7B;AAEA,SAASC,mBAAT,QAAoC,eAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,mBAAN,SAAkCF,YAAlC,CAA+C;AACpD;AACF;AACA;;AAGE;AACF;AACA;;AAGE;AACF;AACA;;AAGE;AACF;AACA;AACA;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEG,EAAAA,WAAW,CAACC,eAAD,EAAyC;AAClD;;AADkD;;AAAA;;AAAA;;AAAA;;AAGlD,UAAM;AAAEC,MAAAA,OAAF;AAAWC,MAAAA,WAAX;AAAwBC,MAAAA;AAAxB,QACJN,mBAAmB,CAACG,eAAD,CADrB;AAGA,SAAKI,QAAL,GAAgBH,OAAhB;AACA,SAAKI,YAAL,GAAoBH,WAApB;AACA,SAAKI,YAAL,GAAoBH,WAApB;AACA,SAAKI,cAAL,GAAsBP,eAAe,CAACQ,aAAtC;AACD;AAED;AACF;AACA;AACA;AACA;;;AACEC,EAAAA,UAAU,GAAQ;AAChB,WAAO,KAAKL,QAAZ;AACD;AAED;AACF;AACA;AACA;AACA;;;AACEM,EAAAA,cAAc,GAAW;AACvB,WAAO,KAAKL,YAAZ;AACD;AAED;AACF;AACA;AACA;AACA;;;AACEM,EAAAA,cAAc,GAAW;AACvB,WAAO,KAAKL,YAAZ;AACD;AAED;AACF;AACA;AACA;AACA;AACA;AACA;;;AACEM,EAAAA,MAAM,GAAuB;AAC3B,WAAO,KAAKL,cAAZ;AACD;;AAnFmD","sourcesContent":["/**\n * Copyright © 2022 Twilio, Inc. All rights reserved. Licensed under the Twilio\n * license.\n *\n * See LICENSE in the project root for license information.\n */\n\nimport { EventEmitter } from 'eventemitter3';\nimport type { NativeCallMessageInfo } from '../type/CallMessage';\nimport { validateCallMessage } from './CallMessage';\n\n/**\n * CallMessage API is in beta.\n *\n * Provides access to information about a CallMessage, including the call\n * message content, content type, message type, and voice event SID.\n *\n * @public\n */\nexport class IncomingCallMessage extends EventEmitter {\n /**\n * The content of the message which should match the contentType parameter.\n */\n private _content: any;\n\n /**\n * The MIME type of the content.\n */\n private _contentType: string;\n\n /**\n * Message type\n */\n private _messageType: string;\n\n /**\n * An autogenerated ID that uniquely identifies this message.\n * This is not required when sending a message from the SDK as this is\n * autogenerated.\n * The ID will be available after the message is sent, or immediately when a\n * message is received.\n */\n private _voiceEventSid?: string;\n\n /**\n * Constructor for the {@link IncomingCallMessage} class. This should not be\n * invoked by third-party code.\n *\n * @param NativeCallMessageInfo - An object containing all of the data from\n * the native layer necessary to fully describe a call message, as well as\n * invoke native functionality for the call message.\n *\n * @internal\n */\n constructor(callMessageInfo: NativeCallMessageInfo) {\n super();\n\n const { content, contentType, messageType } =\n validateCallMessage(callMessageInfo);\n\n this._content = content;\n this._contentType = contentType;\n this._messageType = messageType;\n this._voiceEventSid = callMessageInfo.voiceEventSid;\n }\n\n /**\n * {@inheritdoc CallMessage.content}\n *\n * @returns the content of the call message.\n */\n getContent(): any {\n return this._content;\n }\n\n /**\n * {@inheritdoc CallMessage.contentType}\n *\n * @returns the content type of the call message.\n */\n getContentType(): string {\n return this._contentType;\n }\n\n /**\n * {@inheritdoc CallMessage.messageType}\n *\n * @returns the message type of the call message.\n */\n getMessageType(): string {\n return this._messageType;\n }\n\n /**\n * Get the message SID.\n * @returns\n * - A string representing the message SID.\n * - `undefined` if the call information has not yet been received from the\n * native layer.\n */\n getSid(): string | undefined {\n return this._voiceEventSid;\n }\n}\n"]}
@@ -0,0 +1,154 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ /**
4
+ * Copyright © 2022 Twilio, Inc. All rights reserved. Licensed under the Twilio
5
+ * license.
6
+ *
7
+ * See LICENSE in the project root for license information.
8
+ */
9
+ import { Constants } from '../constants';
10
+ import { NativeEventEmitter } from '../common';
11
+ import { constructTwilioError } from '../error/utility';
12
+ import { IncomingCallMessage } from './IncomingCallMessage';
13
+ /**
14
+ * Defines strict typings for all events emitted by
15
+ * {@link (OutgoingCallMessage:class) | OutgoingCallMessage objects}.
16
+ *
17
+ * @remarks
18
+ * Note that the `on` function is an alias for the `addListener` function.
19
+ * They share identical functionality and either may be used interchangeably.
20
+ *
21
+ * - See also the {@link CallMessage} interface.
22
+ * - See also the {@link IncomingCallMessage} class.
23
+ * - See also the {@link (OutgoingCallMessage:namespace)} namespace.
24
+ *
25
+ * @public
26
+ */
27
+
28
+ /**
29
+ * CallMessage API is in beta.
30
+ *
31
+ * Provides access to information about a outgoingCallMessage, including the call
32
+ * message content, contentType, messageType, and voiceEventSid
33
+ *
34
+ * @remarks
35
+ * Note that the outgoingCallMessage information is fetched as soon as possible from the
36
+ * native layer, but there is no guarantee that all information is immediately
37
+ * available. Methods such as `OutgoingCallMessage.getContent` or `OutgoingCallMessage.getSid`
38
+ * may return `undefined`.
39
+ *
40
+ * As outgoingCallMessage events are received from the native layer, outgoingCallMessage information will
41
+ * propagate from the native layer to the JS layer and become available.
42
+ * Therefore, it is good practice to read information from the outgoingCallMessage after an
43
+ * event occurs, or as events occur.
44
+ *
45
+ * - See the {@link (OutgoingCallMessage:namespace).Event} enum for events emitted by `OutgoingCallMessage`
46
+ * objects.
47
+ * - See the {@link (OutgoingCallMessage:interface) | OutgoingCallMessage interface} for overloaded event listening
48
+ * metods.
49
+ * - See the {@link (OutgoingCallMessage:namespace) | OutgoingCallMessage namespace} for types and enumerations
50
+ * used by this class.
51
+ *
52
+ * @public
53
+ */
54
+ export class OutgoingCallMessage extends IncomingCallMessage {
55
+ /**
56
+ * Handlers for native OutgoingCallMessage events. Set upon construction so we can
57
+ * dynamically bind events to handlers.
58
+ *
59
+ * @privateRemarks
60
+ * This is done by the constructor so this mapping isn't made every time the
61
+ * {@link (OutgoingCallMessage:class)._handleNativeEvent} function is invoked.
62
+ */
63
+ constructor({
64
+ content,
65
+ contentType,
66
+ messageType,
67
+ voiceEventSid
68
+ }) {
69
+ super({
70
+ content,
71
+ contentType,
72
+ messageType,
73
+ voiceEventSid
74
+ });
75
+
76
+ _defineProperty(this, "_nativeEventHandler", void 0);
77
+
78
+ _defineProperty(this, "_handleNativeEvent", nativeCallMessageEvent => {
79
+ const {
80
+ type
81
+ } = nativeCallMessageEvent;
82
+ const handler = this._nativeEventHandler[type];
83
+
84
+ if (typeof handler === 'undefined') {
85
+ throw new Error(`Unknown callMessage event type received from the native layer: "${type}"`);
86
+ }
87
+
88
+ if (this.getSid() === nativeCallMessageEvent.voiceEventSid) {
89
+ handler(nativeCallMessageEvent);
90
+ }
91
+ });
92
+
93
+ _defineProperty(this, "_handleFailureEvent", nativeCallMessageEvent => {
94
+ if (nativeCallMessageEvent.type !== Constants.CallEventMessageFailure) {
95
+ throw new Error('Incorrect "outgoingCallMessage#Failure" handler called for type' + `"${nativeCallMessageEvent.type}`);
96
+ }
97
+
98
+ const {
99
+ message,
100
+ code
101
+ } = nativeCallMessageEvent.error;
102
+ const error = constructTwilioError(message, code);
103
+ this.emit(OutgoingCallMessage.Event.Failure, error);
104
+ });
105
+
106
+ _defineProperty(this, "_handleSentEvent", nativeCallMessageEvent => {
107
+ if (nativeCallMessageEvent.type !== Constants.CallEventMessageSent) {
108
+ throw new Error('Incorrect "outgoingCallMessage#Sent" handler called for type' + `"${nativeCallMessageEvent.type}"`);
109
+ }
110
+
111
+ this.emit(OutgoingCallMessage.Event.Sent);
112
+ });
113
+
114
+ this._nativeEventHandler = {
115
+ /**
116
+ * Sending Call Message State
117
+ */
118
+ [Constants.CallEventMessageFailure]: this._handleFailureEvent,
119
+ [Constants.CallEventMessageSent]: this._handleSentEvent
120
+ };
121
+ NativeEventEmitter.addListener(Constants.ScopeCallMessage, this._handleNativeEvent);
122
+ }
123
+ /**
124
+ * This intermediate native callMessage event handler acts as a "gate".
125
+ * @param nativeCallMessageEvent - A callMessage event directly from the native layer.
126
+ */
127
+
128
+
129
+ }
130
+ /**
131
+ * Namespace for enumerations and types used by
132
+ * {@link (OutgoingCallMessage:class) | OutgoingCallMessage objects}.
133
+ *
134
+ * @remarks
135
+ * - See also the {@link (OutgoingCallMessage:class) | OutgoingCallMessage class}.
136
+ * - See also the {@link (OutgoingCallMessage:interface) | OutgoingCallMessage interface}.
137
+ *
138
+ * @public
139
+ */
140
+
141
+ (function (_OutgoingCallMessage) {
142
+ let Event;
143
+
144
+ (function (Event) {
145
+ Event["Failure"] = "failure";
146
+ Event["Sent"] = "sent";
147
+ })(Event || (Event = {}));
148
+
149
+ _OutgoingCallMessage.Event = Event;
150
+ let Listener;
151
+
152
+ (function (_Listener) {})(Listener || (Listener = _OutgoingCallMessage.Listener || (_OutgoingCallMessage.Listener = {})));
153
+ })(OutgoingCallMessage || (OutgoingCallMessage = {}));
154
+ //# sourceMappingURL=OutgoingCallMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["OutgoingCallMessage.ts"],"names":["Constants","NativeEventEmitter","constructTwilioError","IncomingCallMessage","OutgoingCallMessage","constructor","content","contentType","messageType","voiceEventSid","nativeCallMessageEvent","type","handler","_nativeEventHandler","Error","getSid","CallEventMessageFailure","message","code","error","emit","Event","Failure","CallEventMessageSent","Sent","_handleFailureEvent","_handleSentEvent","addListener","ScopeCallMessage","_handleNativeEvent","Listener"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AAQA,SAASA,SAAT,QAA0B,cAA1B;AACA,SAASC,kBAAT,QAAmC,WAAnC;AACA,SAASC,oBAAT,QAAqC,kBAArC;AACA,SAASC,mBAAT,QAAoC,uBAApC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA4FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,mBAAN,SAAkCD,mBAAlC,CAAsD;AAC3D;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AAKEE,EAAAA,WAAW,CAAC;AACVC,IAAAA,OADU;AAEVC,IAAAA,WAFU;AAGVC,IAAAA,WAHU;AAIVC,IAAAA;AAJU,GAAD,EAKe;AACxB,UAAM;AACJH,MAAAA,OADI;AAEJC,MAAAA,WAFI;AAGJC,MAAAA,WAHI;AAIJC,MAAAA;AAJI,KAAN;;AADwB;;AAAA,gDA0BxBC,sBAD2B,IAExB;AACH,YAAM;AAAEC,QAAAA;AAAF,UAAWD,sBAAjB;AAEA,YAAME,OAAO,GAAG,KAAKC,mBAAL,CAAyBF,IAAzB,CAAhB;;AACA,UAAI,OAAOC,OAAP,KAAmB,WAAvB,EAAoC;AAClC,cAAM,IAAIE,KAAJ,CACH,mEAAkEH,IAAK,GADpE,CAAN;AAGD;;AAED,UAAI,KAAKI,MAAL,OAAkBL,sBAAsB,CAACD,aAA7C,EAA4D;AAC1DG,QAAAA,OAAO,CAACF,sBAAD,CAAP;AACD;AACF,KAxCyB;;AAAA,iDA+CxBA,sBAD4B,IAEzB;AACH,UAAIA,sBAAsB,CAACC,IAAvB,KAAgCX,SAAS,CAACgB,uBAA9C,EAAuE;AACrE,cAAM,IAAIF,KAAJ,CACJ,oEACG,IAAGJ,sBAAsB,CAACC,IAAK,EAF9B,CAAN;AAID;;AAED,YAAM;AAAEM,QAAAA,OAAF;AAAWC,QAAAA;AAAX,UAAoBR,sBAAsB,CAACS,KAAjD;AACA,YAAMA,KAAK,GAAGjB,oBAAoB,CAACe,OAAD,EAAUC,IAAV,CAAlC;AACA,WAAKE,IAAL,CAAUhB,mBAAmB,CAACiB,KAApB,CAA0BC,OAApC,EAA6CH,KAA7C;AACD,KA3DyB;;AAAA,8CAkExBT,sBADyB,IAEtB;AACH,UAAIA,sBAAsB,CAACC,IAAvB,KAAgCX,SAAS,CAACuB,oBAA9C,EAAoE;AAClE,cAAM,IAAIT,KAAJ,CACJ,iEACG,IAAGJ,sBAAsB,CAACC,IAAK,GAF9B,CAAN;AAID;;AAED,WAAKS,IAAL,CAAUhB,mBAAmB,CAACiB,KAApB,CAA0BG,IAApC;AACD,KA5EyB;;AAQxB,SAAKX,mBAAL,GAA2B;AACzB;AACN;AACA;AACM,OAACb,SAAS,CAACgB,uBAAX,GAAqC,KAAKS,mBAJjB;AAKzB,OAACzB,SAAS,CAACuB,oBAAX,GAAkC,KAAKG;AALd,KAA3B;AAOAzB,IAAAA,kBAAkB,CAAC0B,WAAnB,CACE3B,SAAS,CAAC4B,gBADZ,EAEE,KAAKC,kBAFP;AAID;AAED;AACF;AACA;AACA;;;AA1C6D;AAiG7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;MAKcR,K;;aAAAA,K;AAAAA,IAAAA,K;AAAAA,IAAAA,K;KAAAA,K,KAAAA,K;;;;;4BAiBKS,Q,KAAAA,Q,wBAAAA,Q,0BAAAA,Q;GArBF1B,mB,KAAAA,mB","sourcesContent":["/**\n * Copyright © 2022 Twilio, Inc. All rights reserved. Licensed under the Twilio\n * license.\n *\n * See LICENSE in the project root for license information.\n */\n\nimport type { TwilioError } from '../error';\nimport type {\n NativeCallMessageEvent,\n NativeCallMessageEventType,\n NativeCallMessageInfo,\n} from '../type/CallMessage';\nimport { Constants } from '../constants';\nimport { NativeEventEmitter } from '../common';\nimport { constructTwilioError } from '../error/utility';\nimport { IncomingCallMessage } from './IncomingCallMessage';\n\n/**\n * Defines strict typings for all events emitted by\n * {@link (OutgoingCallMessage:class) | OutgoingCallMessage objects}.\n *\n * @remarks\n * Note that the `on` function is an alias for the `addListener` function.\n * They share identical functionality and either may be used interchangeably.\n *\n * - See also the {@link CallMessage} interface.\n * - See also the {@link IncomingCallMessage} class.\n * - See also the {@link (OutgoingCallMessage:namespace)} namespace.\n *\n * @public\n */\nexport declare interface OutgoingCallMessage {\n /**\n * ------------\n * Emit Typings\n * ------------\n */\n\n /** @internal */\n emit(\n failureEvent: OutgoingCallMessage.Event.Failure,\n error: TwilioError\n ): boolean;\n\n /** @internal */\n emit(sentEvent: OutgoingCallMessage.Event.Sent): boolean;\n\n /**\n * ----------------\n * Listener Typings\n * ----------------\n */\n\n /**\n * Failure event. Raised when outgoingCallMessage fails to be sent out.\n *\n * @example\n * ```typescript\n * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Failure, (error) => {\n * // outgoingCallMessage failed, handle error\n * });\n * ```\n *\n * @param failureEvent - The raised event string.\n * @param listener - A listener function that will be invoked when the event\n * is raised.\n * @returns - The callMessage object.\n */\n addListener(\n failureEvent: OutgoingCallMessage.Event.Failure,\n listener: OutgoingCallMessage.Listener.Failure\n ): this;\n /** {@inheritDoc (OutgoingCallMessage:interface).(addListener:1)} */\n on(\n failureEvent: OutgoingCallMessage.Event.Failure,\n listener: OutgoingCallMessage.Listener.Failure\n ): this;\n\n /**\n * Sent event. Raised when outgoingCallMessage is sent.\n * @example\n * ```typescript\n * outgoingCallMessage.addListener(OutgoingCallMessage.Event.Sent, () => {\n * // outgoingCallMessage sent\n * })\n * ```\n *\n * @param sentEvent - The raised event string.\n * @param listener - A listener function that will be invoked when the event\n * is raised.\n * @returns - The callMessage object\n */\n addListener(\n sentEvent: OutgoingCallMessage.Event.Sent,\n listener: OutgoingCallMessage.Listener.Sent\n ): this;\n /** {@inheritDoc (OutgoingCallMessage:interface).(addListener:2)} */\n on(\n sentEvent: OutgoingCallMessage.Event.Sent,\n listener: OutgoingCallMessage.Listener.Sent\n ): this;\n\n /**\n * Generic event listener typings.\n * @param outgoingCallMessageEvent - The raised event string.\n * @param listener - A listener function that will be invoked when the event\n * is raised.\n * @returns - The outgoingCallMessage object.\n */\n addListener(\n outgoingCallMessageEvent: OutgoingCallMessage.Event,\n listener: OutgoingCallMessage.Listener.Generic\n ): this;\n /**\n * {@inheritDoc (OutgoingCallMessage:interface).(addListener:3)}\n */\n on(\n outgoingCallMessageEvent: OutgoingCallMessage.Event,\n listener: OutgoingCallMessage.Listener.Generic\n ): this;\n}\n\n/**\n * CallMessage API is in beta.\n *\n * Provides access to information about a outgoingCallMessage, including the call\n * message content, contentType, messageType, and voiceEventSid\n *\n * @remarks\n * Note that the outgoingCallMessage information is fetched as soon as possible from the\n * native layer, but there is no guarantee that all information is immediately\n * available. Methods such as `OutgoingCallMessage.getContent` or `OutgoingCallMessage.getSid`\n * may return `undefined`.\n *\n * As outgoingCallMessage events are received from the native layer, outgoingCallMessage information will\n * propagate from the native layer to the JS layer and become available.\n * Therefore, it is good practice to read information from the outgoingCallMessage after an\n * event occurs, or as events occur.\n *\n * - See the {@link (OutgoingCallMessage:namespace).Event} enum for events emitted by `OutgoingCallMessage`\n * objects.\n * - See the {@link (OutgoingCallMessage:interface) | OutgoingCallMessage interface} for overloaded event listening\n * metods.\n * - See the {@link (OutgoingCallMessage:namespace) | OutgoingCallMessage namespace} for types and enumerations\n * used by this class.\n *\n * @public\n */\nexport class OutgoingCallMessage extends IncomingCallMessage {\n /**\n * Handlers for native OutgoingCallMessage events. Set upon construction so we can\n * dynamically bind events to handlers.\n *\n * @privateRemarks\n * This is done by the constructor so this mapping isn't made every time the\n * {@link (OutgoingCallMessage:class)._handleNativeEvent} function is invoked.\n */\n private _nativeEventHandler: Record<\n NativeCallMessageEventType,\n (callEvent: NativeCallMessageEvent) => void\n >;\n constructor({\n content,\n contentType,\n messageType,\n voiceEventSid,\n }: NativeCallMessageInfo) {\n super({\n content,\n contentType,\n messageType,\n voiceEventSid,\n });\n\n this._nativeEventHandler = {\n /**\n * Sending Call Message State\n */\n [Constants.CallEventMessageFailure]: this._handleFailureEvent,\n [Constants.CallEventMessageSent]: this._handleSentEvent,\n };\n NativeEventEmitter.addListener(\n Constants.ScopeCallMessage,\n this._handleNativeEvent\n );\n }\n\n /**\n * This intermediate native callMessage event handler acts as a \"gate\".\n * @param nativeCallMessageEvent - A callMessage event directly from the native layer.\n */\n private _handleNativeEvent = (\n nativeCallMessageEvent: NativeCallMessageEvent\n ) => {\n const { type } = nativeCallMessageEvent;\n\n const handler = this._nativeEventHandler[type];\n if (typeof handler === 'undefined') {\n throw new Error(\n `Unknown callMessage event type received from the native layer: \"${type}\"`\n );\n }\n\n if (this.getSid() === nativeCallMessageEvent.voiceEventSid) {\n handler(nativeCallMessageEvent);\n }\n };\n\n /**\n * Handler for the {@link (OutgoingCallMessage:namespace).Event.Failure} event.\n * @param nativeCallMessageEvent - The native callMessage event.\n */\n private _handleFailureEvent = (\n nativeCallMessageEvent: NativeCallMessageEvent\n ) => {\n if (nativeCallMessageEvent.type !== Constants.CallEventMessageFailure) {\n throw new Error(\n 'Incorrect \"outgoingCallMessage#Failure\" handler called for type' +\n `\"${nativeCallMessageEvent.type}`\n );\n }\n\n const { message, code } = nativeCallMessageEvent.error;\n const error = constructTwilioError(message, code);\n this.emit(OutgoingCallMessage.Event.Failure, error);\n };\n\n /**\n * Handler for the {@link (OutgoingCallMessage:namespace).Event.Sent} event.\n * @param nativeCallMessageEvent - The native callMessage event.\n */\n private _handleSentEvent = (\n nativeCallMessageEvent: NativeCallMessageEvent\n ) => {\n if (nativeCallMessageEvent.type !== Constants.CallEventMessageSent) {\n throw new Error(\n 'Incorrect \"outgoingCallMessage#Sent\" handler called for type' +\n `\"${nativeCallMessageEvent.type}\"`\n );\n }\n\n this.emit(OutgoingCallMessage.Event.Sent);\n };\n}\n\n/**\n * Namespace for enumerations and types used by\n * {@link (OutgoingCallMessage:class) | OutgoingCallMessage objects}.\n *\n * @remarks\n * - See also the {@link (OutgoingCallMessage:class) | OutgoingCallMessage class}.\n * - See also the {@link (OutgoingCallMessage:interface) | OutgoingCallMessage interface}.\n *\n * @public\n */\nexport namespace OutgoingCallMessage {\n /**\n * Enumeration of all event strings emitted by {@link (OutgoingCallMessage:class)} objects.\n */\n export enum Event {\n /**\n * Raised when outgoingCallMessage fails.\n * See {@link (OutgoingCallMessage:interface).(addListener:1)}.\n */\n 'Failure' = 'failure',\n /**\n * Raised when outgoingCallMessage has been sent.\n * See {@link (OutgoingCallMessage:interface).(addListener:2)}.\n */\n 'Sent' = 'sent',\n }\n\n /**\n * Listener types for all events emitted by a\n * {@link (OutgoingCallMessage:class) | OutgoingCallMessage: object}\n */\n export namespace Listener {\n /**\n * OutgoingCallMessage failure event listener. This should be the function signature of\n * any event listener bound to the {@link (OutgoingCallMessage:namespace).Event.Failure} event.\n *\n * @remarks\n * See {@link (OutgoingCallMessage:interface).(addListener:1)}.\n *\n * See {@link TwilioErrors} for all error classes.\n */\n export type Failure = (error: TwilioError) => void;\n\n /**\n * OutgoingCallMessage sent event listner. This should be the function signature of\n * any event listener bound to the {@link (OutgoingCallMessage:namespace).Event.Sent} event.\n *\n * @remarks\n * See {@link (OutgoingCallMessage:interface).(addListener:2)}.\n */\n export type Sent = () => void;\n\n /**\n * Generic event listener. This should be the function signature of any\n * event listener bound to any OutgoingCallMessage event.\n *\n * @remarks\n * See {@link (OutgoingCallMessage:interface).(addListener:3)}.\n */\n export type Generic = (...args: any[]) => void;\n }\n}\n"]}
@@ -0,0 +1,58 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ import { NativeModule, Platform } from './common';
4
+ import { requireNativeModule } from 'expo-modules-core';
5
+ import { Call } from './Call';
6
+
7
+ class ExpoNativeModule {
8
+ constructor() {
9
+ _defineProperty(this, "androidExpoNativeModule", Platform.OS === 'android' ? (() => {
10
+ try {
11
+ return requireNativeModule('TwilioVoiceExpo');
12
+ } catch (e) {
13
+ console.warn('TwilioVoiceExpo native module not found');
14
+ return null;
15
+ }
16
+ })() : null);
17
+ }
18
+
19
+ async voice_connect(accessToken, options = {}) {
20
+ const {
21
+ params = {},
22
+ customParameters = {}
23
+ } = options;
24
+ let info;
25
+
26
+ if (Platform.OS === 'android' && this.androidExpoNativeModule) {
27
+ info = await this.androidExpoNativeModule.voice_connect(accessToken, params, customParameters);
28
+ } else if (Platform.OS === 'ios') {
29
+ info = await NativeModule.voice_connect_ios(accessToken, params, // @ts-ignore
30
+ customParameters);
31
+ } else {
32
+ throw new Error('Unsupported platform');
33
+ }
34
+
35
+ return new Call(info);
36
+ }
37
+
38
+ async disconnect() {
39
+ var _NativeModule$voice_d;
40
+
41
+ if (Platform.OS === 'android' && this.androidExpoNativeModule) {
42
+ var _this$androidExpoNati, _this$androidExpoNati2;
43
+
44
+ return (_this$androidExpoNati = (_this$androidExpoNati2 = this.androidExpoNativeModule).voice_disconnect) === null || _this$androidExpoNati === void 0 ? void 0 : _this$androidExpoNati.call(_this$androidExpoNati2);
45
+ }
46
+
47
+ return (_NativeModule$voice_d = NativeModule.voice_disconnect_ios) === null || _NativeModule$voice_d === void 0 ? void 0 : _NativeModule$voice_d.call(NativeModule);
48
+ }
49
+
50
+ isExpoEnvironment() {
51
+ return Platform.OS === 'android';
52
+ }
53
+
54
+ }
55
+
56
+ export const ExpoModule = new ExpoNativeModule();
57
+ export default ExpoModule;
58
+ //# sourceMappingURL=ExpoModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["ExpoModule.ts"],"names":["NativeModule","Platform","requireNativeModule","Call","ExpoNativeModule","OS","e","console","warn","voice_connect","accessToken","options","params","customParameters","info","androidExpoNativeModule","voice_connect_ios","Error","disconnect","voice_disconnect","voice_disconnect_ios","isExpoEnvironment","ExpoModule"],"mappings":";;AAAA,SAASA,YAAT,EAAuBC,QAAvB,QAAuC,UAAvC;AACA,SAASC,mBAAT,QAAoC,mBAApC;AACA,SAASC,IAAT,QAAqB,QAArB;;AAQA,MAAMC,gBAAN,CAAuB;AAAA;AAAA,qDAEnBH,QAAQ,CAACI,EAAT,KAAgB,SAAhB,GACI,CAAC,MAAM;AACL,UAAI;AACF,eAAOH,mBAAmB,CAAC,iBAAD,CAA1B;AACD,OAFD,CAEE,OAAOI,CAAP,EAAU;AACVC,QAAAA,OAAO,CAACC,IAAR,CAAa,yCAAb;AACA,eAAO,IAAP;AACD;AACF,KAPD,GADJ,GASI,IAXe;AAAA;;AAaF,QAAbC,aAAa,CAACC,WAAD,EAAsBC,OAAuB,GAAG,EAAhD,EAAoD;AACrE,UAAM;AAAEC,MAAAA,MAAM,GAAG,EAAX;AAAeC,MAAAA,gBAAgB,GAAG;AAAlC,QAAyCF,OAA/C;AACA,QAAIG,IAAJ;;AACA,QAAIb,QAAQ,CAACI,EAAT,KAAgB,SAAhB,IAA6B,KAAKU,uBAAtC,EAA+D;AAC7DD,MAAAA,IAAI,GAAG,MAAM,KAAKC,uBAAL,CAA6BN,aAA7B,CACXC,WADW,EAEXE,MAFW,EAGXC,gBAHW,CAAb;AAKD,KAND,MAMO,IAAIZ,QAAQ,CAACI,EAAT,KAAgB,KAApB,EAA2B;AAChCS,MAAAA,IAAI,GAAG,MAAMd,YAAY,CAACgB,iBAAb,CACXN,WADW,EAEXE,MAFW,EAGX;AACAC,MAAAA,gBAJW,CAAb;AAMD,KAPM,MAOA;AACL,YAAM,IAAII,KAAJ,CAAU,sBAAV,CAAN;AACD;;AACD,WAAO,IAAId,IAAJ,CAASW,IAAT,CAAP;AACD;;AAEe,QAAVI,UAAU,GAAG;AAAA;;AACjB,QAAIjB,QAAQ,CAACI,EAAT,KAAgB,SAAhB,IAA6B,KAAKU,uBAAtC,EAA+D;AAAA;;AAC7D,sCAAO,+BAAKA,uBAAL,EAA6BI,gBAApC,0DAAO,kDAAP;AACD;;AACD,oCAAOnB,YAAY,CAACoB,oBAApB,0DAAO,2BAAApB,YAAY,CAAnB;AACD;;AAEDqB,EAAAA,iBAAiB,GAAY;AAC3B,WAAOpB,QAAQ,CAACI,EAAT,KAAgB,SAAvB;AACD;;AA5CoB;;AA+CvB,OAAO,MAAMiB,UAAU,GAAG,IAAIlB,gBAAJ,EAAnB;AACP,eAAekB,UAAf","sourcesContent":["import { NativeModule, Platform } from './common';\nimport { requireNativeModule } from 'expo-modules-core';\nimport { Call } from './Call';\nimport type { NativeCallInfo } from './type/Call';\n\ninterface ConnectOptions {\n params?: Record<string, any>;\n customParameters?: Record<string, any>;\n}\n\nclass ExpoNativeModule {\n private androidExpoNativeModule =\n Platform.OS === 'android'\n ? (() => {\n try {\n return requireNativeModule('TwilioVoiceExpo');\n } catch (e) {\n console.warn('TwilioVoiceExpo native module not found');\n return null;\n }\n })()\n : null;\n\n async voice_connect(accessToken: string, options: ConnectOptions = {}) {\n const { params = {}, customParameters = {} } = options;\n let info: NativeCallInfo;\n if (Platform.OS === 'android' && this.androidExpoNativeModule) {\n info = await this.androidExpoNativeModule.voice_connect(\n accessToken,\n params,\n customParameters\n );\n } else if (Platform.OS === 'ios') {\n info = await NativeModule.voice_connect_ios(\n accessToken,\n params,\n // @ts-ignore\n customParameters\n );\n } else {\n throw new Error('Unsupported platform');\n }\n return new Call(info);\n }\n\n async disconnect() {\n if (Platform.OS === 'android' && this.androidExpoNativeModule) {\n return this.androidExpoNativeModule.voice_disconnect?.();\n }\n return NativeModule.voice_disconnect_ios?.();\n }\n\n isExpoEnvironment(): boolean {\n return Platform.OS === 'android';\n }\n}\n\nexport const ExpoModule = new ExpoNativeModule();\nexport default ExpoModule;\n"]}