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.
- package/LICENSE +206 -0
- package/README.md +179 -0
- package/android/build.gradle +113 -0
- package/android/gradle.properties +29 -0
- package/android/src/main/AndroidManifest.xml +30 -0
- package/android/src/main/java/com/twiliovoicereactnative/AudioSwitchManager.java +141 -0
- package/android/src/main/java/com/twiliovoicereactnative/CallListenerProxy.java +186 -0
- package/android/src/main/java/com/twiliovoicereactnative/CallMessageListenerProxy.java +103 -0
- package/android/src/main/java/com/twiliovoicereactnative/CallRecordDatabase.java +183 -0
- package/android/src/main/java/com/twiliovoicereactnative/CommonConstants.java +195 -0
- package/android/src/main/java/com/twiliovoicereactnative/ConfigurationProperties.java +41 -0
- package/android/src/main/java/com/twiliovoicereactnative/Constants.java +23 -0
- package/android/src/main/java/com/twiliovoicereactnative/ExpoActivityLifecycleListener.java +27 -0
- package/android/src/main/java/com/twiliovoicereactnative/ExpoApplicationLifecycleListener.java +14 -0
- package/android/src/main/java/com/twiliovoicereactnative/ExpoModule.kt +36 -0
- package/android/src/main/java/com/twiliovoicereactnative/ExpoPackage.java +20 -0
- package/android/src/main/java/com/twiliovoicereactnative/JSEventEmitter.java +98 -0
- package/android/src/main/java/com/twiliovoicereactnative/MediaPlayerManager.java +58 -0
- package/android/src/main/java/com/twiliovoicereactnative/NotificationUtility.java +363 -0
- package/android/src/main/java/com/twiliovoicereactnative/ReactNativeArgumentsSerializer.java +276 -0
- package/android/src/main/java/com/twiliovoicereactnative/SDKLog.java +74 -0
- package/android/src/main/java/com/twiliovoicereactnative/StatsListenerProxy.java +178 -0
- package/android/src/main/java/com/twiliovoicereactnative/TwilioVoiceReactNativeModule.java +778 -0
- package/android/src/main/java/com/twiliovoicereactnative/TwilioVoiceReactNativePackage.java +28 -0
- package/android/src/main/java/com/twiliovoicereactnative/VoiceActivityProxy.java +101 -0
- package/android/src/main/java/com/twiliovoicereactnative/VoiceApplicationProxy.java +133 -0
- package/android/src/main/java/com/twiliovoicereactnative/VoiceFirebaseMessagingService.java +88 -0
- package/android/src/main/java/com/twiliovoicereactnative/VoiceService.java +403 -0
- package/android/src/main/res/drawable/answered_call_small_icon.png +0 -0
- package/android/src/main/res/drawable/ic_launcher_round.png +0 -0
- package/android/src/main/res/drawable/ic_launcher_sdk.png +0 -0
- package/android/src/main/res/drawable/incoming_call_small_icon.png +0 -0
- package/android/src/main/res/drawable/outgoing_call_small_icon.png +0 -0
- package/android/src/main/res/raw/disconnect.wav +0 -0
- package/android/src/main/res/raw/incoming.wav +0 -0
- package/android/src/main/res/raw/outgoing.wav +0 -0
- package/android/src/main/res/raw/ringtone.wav +0 -0
- package/android/src/main/res/raw/silent.wav +0 -0
- package/android/src/main/res/values/colors.xml +11 -0
- package/android/src/main/res/values/config.xml +5 -0
- package/android/src/main/res/values/dimens.xml +7 -0
- package/android/src/main/res/values/strings.xml +25 -0
- package/android/src/main/res/values/styles.xml +10 -0
- package/android/src/main/res/values-night/colors.xml +11 -0
- package/expo-config-plugin/android.js +191 -0
- package/expo-config-plugin/ios.js +22 -0
- package/expo-module.config.json +6 -0
- package/ios/TwilioVoicePushRegistry.h +19 -0
- package/ios/TwilioVoicePushRegistry.m +72 -0
- package/ios/TwilioVoiceReactNative+CallInvite.m +56 -0
- package/ios/TwilioVoiceReactNative+CallKit.m +533 -0
- package/ios/TwilioVoiceReactNative+CallMessage.m +81 -0
- package/ios/TwilioVoiceReactNative.h +74 -0
- package/ios/TwilioVoiceReactNative.m +1046 -0
- package/ios/TwilioVoiceReactNative.xcodeproj/project.pbxproj +328 -0
- package/ios/TwilioVoiceReactNativeConstants.h +200 -0
- package/ios/Utilities/TwilioVoiceStatsReport.h +175 -0
- package/lib/commonjs/AudioDevice.js +101 -0
- package/lib/commonjs/AudioDevice.js.map +1 -0
- package/lib/commonjs/Call.js +765 -0
- package/lib/commonjs/Call.js.map +1 -0
- package/lib/commonjs/CallInvite.js +452 -0
- package/lib/commonjs/CallInvite.js.map +1 -0
- package/lib/commonjs/CallMessage/CallMessage.js +54 -0
- package/lib/commonjs/CallMessage/CallMessage.js.map +1 -0
- package/lib/commonjs/CallMessage/IncomingCallMessage.js +120 -0
- package/lib/commonjs/CallMessage/IncomingCallMessage.js.map +1 -0
- package/lib/commonjs/CallMessage/OutgoingCallMessage.js +148 -0
- package/lib/commonjs/CallMessage/OutgoingCallMessage.js.map +1 -0
- package/lib/commonjs/ExpoModule.js +69 -0
- package/lib/commonjs/ExpoModule.js.map +1 -0
- package/lib/commonjs/Voice.js +611 -0
- package/lib/commonjs/Voice.js.map +1 -0
- package/lib/commonjs/common.js +26 -0
- package/lib/commonjs/common.js.map +1 -0
- package/lib/commonjs/constants.js +158 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/error/InvalidArgumentError.js +32 -0
- package/lib/commonjs/error/InvalidArgumentError.js.map +1 -0
- package/lib/commonjs/error/InvalidStateError.js +33 -0
- package/lib/commonjs/error/InvalidStateError.js.map +1 -0
- package/lib/commonjs/error/TwilioError.js +38 -0
- package/lib/commonjs/error/TwilioError.js.map +1 -0
- package/lib/commonjs/error/UnsupportedPlatformError.js +33 -0
- package/lib/commonjs/error/UnsupportedPlatformError.js.map +1 -0
- package/lib/commonjs/error/generated.js +2343 -0
- package/lib/commonjs/error/generated.js.map +1 -0
- package/lib/commonjs/error/index.js +112 -0
- package/lib/commonjs/error/index.js.map +1 -0
- package/lib/commonjs/error/utility.js +37 -0
- package/lib/commonjs/error/utility.js.map +1 -0
- package/lib/commonjs/index.js +95 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/type/AudioDevice.js +6 -0
- package/lib/commonjs/type/AudioDevice.js.map +1 -0
- package/lib/commonjs/type/Call.js +6 -0
- package/lib/commonjs/type/Call.js.map +1 -0
- package/lib/commonjs/type/CallInvite.js +6 -0
- package/lib/commonjs/type/CallInvite.js.map +1 -0
- package/lib/commonjs/type/CallKit.js +30 -0
- package/lib/commonjs/type/CallKit.js.map +1 -0
- package/lib/commonjs/type/CallMessage.js +6 -0
- package/lib/commonjs/type/CallMessage.js.map +1 -0
- package/lib/commonjs/type/Error.js +6 -0
- package/lib/commonjs/type/Error.js.map +1 -0
- package/lib/commonjs/type/NativeModule.js +6 -0
- package/lib/commonjs/type/NativeModule.js.map +1 -0
- package/lib/commonjs/type/RTCStats.js +29 -0
- package/lib/commonjs/type/RTCStats.js.map +1 -0
- package/lib/commonjs/type/Voice.js +6 -0
- package/lib/commonjs/type/Voice.js.map +1 -0
- package/lib/commonjs/type/common.js +2 -0
- package/lib/commonjs/type/common.js.map +1 -0
- package/lib/module/AudioDevice.js +97 -0
- package/lib/module/AudioDevice.js.map +1 -0
- package/lib/module/Call.js +766 -0
- package/lib/module/Call.js.map +1 -0
- package/lib/module/CallInvite.js +450 -0
- package/lib/module/CallInvite.js.map +1 -0
- package/lib/module/CallMessage/CallMessage.js +51 -0
- package/lib/module/CallMessage/CallMessage.js.map +1 -0
- package/lib/module/CallMessage/IncomingCallMessage.js +116 -0
- package/lib/module/CallMessage/IncomingCallMessage.js.map +1 -0
- package/lib/module/CallMessage/OutgoingCallMessage.js +154 -0
- package/lib/module/CallMessage/OutgoingCallMessage.js.map +1 -0
- package/lib/module/ExpoModule.js +58 -0
- package/lib/module/ExpoModule.js.map +1 -0
- package/lib/module/Voice.js +598 -0
- package/lib/module/Voice.js.map +1 -0
- package/lib/module/common.js +11 -0
- package/lib/module/common.js.map +1 -0
- package/lib/module/constants.js +151 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/error/InvalidArgumentError.js +23 -0
- package/lib/module/error/InvalidArgumentError.js.map +1 -0
- package/lib/module/error/InvalidStateError.js +24 -0
- package/lib/module/error/InvalidStateError.js.map +1 -0
- package/lib/module/error/TwilioError.js +29 -0
- package/lib/module/error/TwilioError.js.map +1 -0
- package/lib/module/error/UnsupportedPlatformError.js +24 -0
- package/lib/module/error/UnsupportedPlatformError.js.map +1 -0
- package/lib/module/error/generated.js +2315 -0
- package/lib/module/error/generated.js.map +1 -0
- package/lib/module/error/index.js +6 -0
- package/lib/module/error/index.js.map +1 -0
- package/lib/module/error/utility.js +27 -0
- package/lib/module/error/utility.js.map +1 -0
- package/lib/module/index.js +23 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/type/AudioDevice.js +2 -0
- package/lib/module/type/AudioDevice.js.map +1 -0
- package/lib/module/type/Call.js +2 -0
- package/lib/module/type/Call.js.map +1 -0
- package/lib/module/type/CallInvite.js +2 -0
- package/lib/module/type/CallInvite.js.map +1 -0
- package/lib/module/type/CallKit.js +22 -0
- package/lib/module/type/CallKit.js.map +1 -0
- package/lib/module/type/CallMessage.js +2 -0
- package/lib/module/type/CallMessage.js.map +1 -0
- package/lib/module/type/Error.js +2 -0
- package/lib/module/type/Error.js.map +1 -0
- package/lib/module/type/NativeModule.js +2 -0
- package/lib/module/type/NativeModule.js.map +1 -0
- package/lib/module/type/RTCStats.js +21 -0
- package/lib/module/type/RTCStats.js.map +1 -0
- package/lib/module/type/Voice.js +2 -0
- package/lib/module/type/Voice.js.map +1 -0
- package/lib/module/type/common.js +2 -0
- package/lib/module/type/common.js.map +1 -0
- package/lib/typescript/AudioDevice.d.ts +74 -0
- package/lib/typescript/Call.d.ts +874 -0
- package/lib/typescript/CallInvite.d.ts +484 -0
- package/lib/typescript/CallMessage/CallMessage.d.ts +53 -0
- package/lib/typescript/CallMessage/IncomingCallMessage.d.ts +75 -0
- package/lib/typescript/CallMessage/OutgoingCallMessage.d.ts +198 -0
- package/lib/typescript/ExpoModule.d.ts +13 -0
- package/lib/typescript/Voice.d.ts +620 -0
- package/lib/typescript/common.d.ts +11 -0
- package/lib/typescript/constants.d.ts +148 -0
- package/lib/typescript/error/InvalidArgumentError.d.ts +11 -0
- package/lib/typescript/error/InvalidStateError.d.ts +12 -0
- package/lib/typescript/error/TwilioError.d.ts +14 -0
- package/lib/typescript/error/UnsupportedPlatformError.d.ts +12 -0
- package/lib/typescript/error/generated.d.ts +1558 -0
- package/lib/typescript/error/index.d.ts +5 -0
- package/lib/typescript/error/utility.d.ts +12 -0
- package/lib/typescript/index.d.ts +18 -0
- package/lib/typescript/type/AudioDevice.d.ts +15 -0
- package/lib/typescript/type/Call.d.ts +59 -0
- package/lib/typescript/type/CallInvite.d.ts +40 -0
- package/lib/typescript/type/CallKit.d.ts +60 -0
- package/lib/typescript/type/CallMessage.d.ts +20 -0
- package/lib/typescript/type/Error.d.ts +9 -0
- package/lib/typescript/type/NativeModule.d.ts +59 -0
- package/lib/typescript/type/RTCStats.d.ts +91 -0
- package/lib/typescript/type/Voice.d.ts +16 -0
- package/lib/typescript/type/common.d.ts +15 -0
- package/package.json +167 -0
- package/src/AudioDevice.tsx +88 -0
- package/src/Call.tsx +1343 -0
- package/src/CallInvite.tsx +757 -0
- package/src/CallMessage/CallMessage.ts +83 -0
- package/src/CallMessage/IncomingCallMessage.ts +104 -0
- package/src/CallMessage/OutgoingCallMessage.ts +308 -0
- package/src/ExpoModule.ts +59 -0
- package/src/Voice.tsx +1010 -0
- package/src/common.ts +16 -0
- package/src/constants.ts +193 -0
- package/src/error/InvalidArgumentError.ts +19 -0
- package/src/error/InvalidStateError.ts +19 -0
- package/src/error/TwilioError.ts +22 -0
- package/src/error/UnsupportedPlatformError.ts +19 -0
- package/src/error/generated.ts +2277 -0
- package/src/error/index.ts +18 -0
- package/src/error/utility.ts +36 -0
- package/src/index.tsx +24 -0
- package/src/type/AudioDevice.ts +18 -0
- package/src/type/Call.ts +102 -0
- package/src/type/CallInvite.ts +59 -0
- package/src/type/CallKit.ts +61 -0
- package/src/type/CallMessage.ts +31 -0
- package/src/type/Error.ts +11 -0
- package/src/type/NativeModule.ts +93 -0
- package/src/type/RTCStats.ts +99 -0
- package/src/type/Voice.ts +31 -0
- package/src/type/common.ts +16 -0
- package/twilio-voice-react-native.podspec +22 -0
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Voice = void 0;
|
|
7
|
+
|
|
8
|
+
var _eventemitter = require("eventemitter3");
|
|
9
|
+
|
|
10
|
+
var _AudioDevice = require("./AudioDevice");
|
|
11
|
+
|
|
12
|
+
var _Call = require("./Call");
|
|
13
|
+
|
|
14
|
+
var _CallInvite = require("./CallInvite");
|
|
15
|
+
|
|
16
|
+
var _common = require("./common");
|
|
17
|
+
|
|
18
|
+
var _constants = require("./constants");
|
|
19
|
+
|
|
20
|
+
var _InvalidArgumentError = require("./error/InvalidArgumentError");
|
|
21
|
+
|
|
22
|
+
var _UnsupportedPlatformError = require("./error/UnsupportedPlatformError");
|
|
23
|
+
|
|
24
|
+
var _utility = require("./error/utility");
|
|
25
|
+
|
|
26
|
+
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; }
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Main entry-point of the Voice SDK. Provides access to the entire feature-set
|
|
30
|
+
* of the library.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* Usage:
|
|
34
|
+
* ```
|
|
35
|
+
* const token = '...';
|
|
36
|
+
*
|
|
37
|
+
* const voice = new Voice();
|
|
38
|
+
*
|
|
39
|
+
* voice.on(Voice.Event.CallInvite, (callInvite: CallInvite) => {
|
|
40
|
+
* callInvite.accept();
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* voice.register(token);
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* - See also the {@link (Voice:namespace).Event} enum for events emitted by
|
|
48
|
+
* `Voice` objects.
|
|
49
|
+
* - See also the {@link (Voice:interface) | Voice interface} for events
|
|
50
|
+
* emitted by this class and associated types.
|
|
51
|
+
* - See also the {@link (Voice:namespace) | Voice namespace} for types and
|
|
52
|
+
* enumerations used by this class.
|
|
53
|
+
*
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
class Voice extends _eventemitter.EventEmitter {
|
|
57
|
+
/**
|
|
58
|
+
* Handlers for native voice events. Set upon construction so we can
|
|
59
|
+
* dynamically bind events to handlers.
|
|
60
|
+
*
|
|
61
|
+
* @privateRemarks
|
|
62
|
+
* This is done by the constructor so this mapping isn't made every time the
|
|
63
|
+
* {@link (Voice:class)._handleNativeEvent} function is invoked.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Main entry-point of the Voice SDK. Provides access to the entire
|
|
68
|
+
* feature-set of the library.
|
|
69
|
+
*/
|
|
70
|
+
constructor() {
|
|
71
|
+
super();
|
|
72
|
+
|
|
73
|
+
_defineProperty(this, "_nativeEventHandler", void 0);
|
|
74
|
+
|
|
75
|
+
_defineProperty(this, "_handleNativeEvent", nativeVoiceEvent => {
|
|
76
|
+
const {
|
|
77
|
+
type
|
|
78
|
+
} = nativeVoiceEvent;
|
|
79
|
+
const handler = this._nativeEventHandler[type];
|
|
80
|
+
|
|
81
|
+
if (typeof handler === 'undefined') {
|
|
82
|
+
throw new Error(`Unknown voice event type received from the native layer: "${type}".`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
handler(nativeVoiceEvent);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
_defineProperty(this, "_handleCallInvite", nativeVoiceEvent => {
|
|
89
|
+
if (nativeVoiceEvent.type !== _constants.Constants.VoiceEventTypeValueIncomingCallInvite) {
|
|
90
|
+
throw new Error('Incorrect "voice#callInvite" handler called for type ' + `"${nativeVoiceEvent.type}".`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const {
|
|
94
|
+
callInvite: callInviteInfo
|
|
95
|
+
} = nativeVoiceEvent;
|
|
96
|
+
const callInvite = new _CallInvite.CallInvite(callInviteInfo, _CallInvite.CallInvite.State.Pending);
|
|
97
|
+
this.emit(Voice.Event.CallInvite, callInvite);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
_defineProperty(this, "_handleError", nativeVoiceEvent => {
|
|
101
|
+
if (nativeVoiceEvent.type !== _constants.Constants.VoiceEventError) {
|
|
102
|
+
throw new Error('Incorrect "voice#error" handler called for type ' + `"${nativeVoiceEvent.type}".`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const {
|
|
106
|
+
error: {
|
|
107
|
+
code,
|
|
108
|
+
message
|
|
109
|
+
}
|
|
110
|
+
} = nativeVoiceEvent;
|
|
111
|
+
const error = (0, _utility.constructTwilioError)(message, code);
|
|
112
|
+
this.emit(Voice.Event.Error, error);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
_defineProperty(this, "_handleRegistered", nativeVoiceEvent => {
|
|
116
|
+
if (nativeVoiceEvent.type !== _constants.Constants.VoiceEventRegistered) {
|
|
117
|
+
throw new Error('Incorrect "voice#error" handler called for type ' + `"${nativeVoiceEvent.type}".`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
this.emit(Voice.Event.Registered);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
_defineProperty(this, "_handleUnregistered", nativeVoiceEvent => {
|
|
124
|
+
if (nativeVoiceEvent.type !== _constants.Constants.VoiceEventUnregistered) {
|
|
125
|
+
throw new Error('Incorrect "voice#error" handler called for type ' + `"${nativeVoiceEvent.type}".`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.emit(Voice.Event.Unregistered);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
_defineProperty(this, "_handleAudioDevicesUpdated", nativeVoiceEvent => {
|
|
132
|
+
if (nativeVoiceEvent.type !== _constants.Constants.VoiceEventAudioDevicesUpdated) {
|
|
133
|
+
throw new Error('Incorrect "voice#audioDevicesUpdated" handler called for type ' + `"${nativeVoiceEvent.type}".`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const {
|
|
137
|
+
audioDevices: audioDeviceInfos,
|
|
138
|
+
selectedDevice: selectedDeviceInfo
|
|
139
|
+
} = nativeVoiceEvent;
|
|
140
|
+
const audioDevices = audioDeviceInfos.map(audioDeviceInfo => new _AudioDevice.AudioDevice(audioDeviceInfo));
|
|
141
|
+
const selectedDevice = typeof selectedDeviceInfo !== 'undefined' && selectedDeviceInfo !== null ? new _AudioDevice.AudioDevice(selectedDeviceInfo) : undefined;
|
|
142
|
+
this.emit(Voice.Event.AudioDevicesUpdated, audioDevices, selectedDevice);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
this._nativeEventHandler = {
|
|
146
|
+
/**
|
|
147
|
+
* Common
|
|
148
|
+
*/
|
|
149
|
+
[_constants.Constants.VoiceEventError]: this._handleError,
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Call Invite
|
|
153
|
+
*/
|
|
154
|
+
[_constants.Constants.VoiceEventTypeValueIncomingCallInvite]: this._handleCallInvite,
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Registration
|
|
158
|
+
*/
|
|
159
|
+
[_constants.Constants.VoiceEventRegistered]: this._handleRegistered,
|
|
160
|
+
[_constants.Constants.VoiceEventUnregistered]: this._handleUnregistered,
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Audio Devices
|
|
164
|
+
*/
|
|
165
|
+
[_constants.Constants.VoiceEventAudioDevicesUpdated]: this._handleAudioDevicesUpdated
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
_common.NativeEventEmitter.addListener(_constants.Constants.ScopeVoice, this._handleNativeEvent);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Connect for devices on Android platforms.
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
async _connect_android(token, params, notificationDisplayName) {
|
|
176
|
+
const connectResult = await _common.NativeModule.voice_connect_android(token, params, notificationDisplayName).then(callInfo => {
|
|
177
|
+
return {
|
|
178
|
+
type: 'ok',
|
|
179
|
+
callInfo
|
|
180
|
+
};
|
|
181
|
+
}).catch(error => {
|
|
182
|
+
const code = error.userInfo.code;
|
|
183
|
+
const message = error.userInfo.message;
|
|
184
|
+
return {
|
|
185
|
+
type: 'err',
|
|
186
|
+
message,
|
|
187
|
+
code
|
|
188
|
+
};
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
if (connectResult.type === 'err') {
|
|
192
|
+
throw (0, _utility.constructTwilioError)(connectResult.message, connectResult.code);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return new _Call.Call(connectResult.callInfo);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Connect for devices on iOS platforms.
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
async _connect_ios(token, params, contactHandle) {
|
|
203
|
+
const parsedContactHandle = contactHandle === '' ? 'Default Contact' : contactHandle;
|
|
204
|
+
const callInfo = await _common.NativeModule.voice_connect_ios(token, params, parsedContactHandle);
|
|
205
|
+
return new _Call.Call(callInfo);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Intermediary event handler for `Voice`-level events. Ensures that the type
|
|
209
|
+
* of the incoming event is expected and invokes the proper event listener.
|
|
210
|
+
* @param nativeVoiceEvent - A `Voice` event directly from the native layer.
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Create an outgoing call.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* Note that the resolution of the returned `Promise` does not imply any call
|
|
219
|
+
* event occurring, such as answered or rejected.
|
|
220
|
+
* The `contactHandle` parameter is only required for iOS apps. Currently the
|
|
221
|
+
* parameter does have any effect on Android apps and can be ignored.
|
|
222
|
+
* `Default Contact` will appear in the iOS call history if the value is empty
|
|
223
|
+
* or not provided.
|
|
224
|
+
*
|
|
225
|
+
* @param token - A Twilio Access Token, usually minted by an
|
|
226
|
+
* authentication-gated endpoint using a Twilio helper library.
|
|
227
|
+
* @param options - Connect options.
|
|
228
|
+
* See {@link (Voice:namespace).ConnectOptions}.
|
|
229
|
+
*
|
|
230
|
+
* @returns
|
|
231
|
+
* A `Promise` that
|
|
232
|
+
* - Resolves with a call when the call is created.
|
|
233
|
+
* - Rejects:
|
|
234
|
+
* * When a call is not able to be created on the native layer.
|
|
235
|
+
* * With an {@link TwilioErrors.InvalidArgumentError} when invalid
|
|
236
|
+
* arguments are passed.
|
|
237
|
+
*/
|
|
238
|
+
async connect(token, {
|
|
239
|
+
contactHandle = 'Default Contact',
|
|
240
|
+
notificationDisplayName = undefined,
|
|
241
|
+
params = {}
|
|
242
|
+
} = {}) {
|
|
243
|
+
if (typeof token !== 'string') {
|
|
244
|
+
throw new _InvalidArgumentError.InvalidArgumentError('Argument "token" must be of type "string".');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (typeof contactHandle !== 'string') {
|
|
248
|
+
throw new _InvalidArgumentError.InvalidArgumentError('Optional argument "contactHandle" must be undefined or of type' + ' "string".');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (typeof params !== 'object') {
|
|
252
|
+
throw new _InvalidArgumentError.InvalidArgumentError('Optional argument "params" must be undefined or of type "object".');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (const [key, value] of Object.entries(params)) {
|
|
256
|
+
if (typeof value !== 'string') {
|
|
257
|
+
throw new _InvalidArgumentError.InvalidArgumentError(`Voice.ConnectOptions.params["${key}"] must be of type string`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
switch (_common.Platform.OS) {
|
|
262
|
+
case 'ios':
|
|
263
|
+
return this._connect_ios(token, params, contactHandle);
|
|
264
|
+
|
|
265
|
+
case 'android':
|
|
266
|
+
return this._connect_android(token, params, notificationDisplayName);
|
|
267
|
+
|
|
268
|
+
default:
|
|
269
|
+
throw new _UnsupportedPlatformError.UnsupportedPlatformError(`Unsupported platform "${_common.Platform.OS}". Expected "android" or "ios".`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get the version of the native SDK. Note that this is not the version of the
|
|
274
|
+
* React Native SDK, this is the version of the mobile SDK that the RN SDK is
|
|
275
|
+
* utilizing.
|
|
276
|
+
* @returns
|
|
277
|
+
* A `Promise` that
|
|
278
|
+
* - Resolves with a string representing the version of the native SDK.
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
getVersion() {
|
|
283
|
+
return _common.NativeModule.voice_getVersion();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get the Device token from the native layer.
|
|
287
|
+
* @returns a Promise that resolves with a string representing the Device
|
|
288
|
+
* token.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
getDeviceToken() {
|
|
293
|
+
return _common.NativeModule.voice_getDeviceToken();
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Get a list of existing calls, ongoing and pending. This will not return any
|
|
297
|
+
* call that has finished.
|
|
298
|
+
* @returns
|
|
299
|
+
* A `Promise` that
|
|
300
|
+
* - Resolves with a mapping of `Uuid`s to {@link (Call:class)}s.
|
|
301
|
+
*/
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
async getCalls() {
|
|
305
|
+
const callInfos = await _common.NativeModule.voice_getCalls();
|
|
306
|
+
const callsMap = new Map(callInfos.map(callInfo => [callInfo.uuid, new _Call.Call(callInfo)]));
|
|
307
|
+
return callsMap;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Get a list of pending call invites.
|
|
311
|
+
*
|
|
312
|
+
* @remarks
|
|
313
|
+
* This list will not contain any call invites that have been "settled"
|
|
314
|
+
* (answered or rejected).
|
|
315
|
+
*
|
|
316
|
+
* @returns
|
|
317
|
+
* A `Promise` that
|
|
318
|
+
* - Resolves with a mapping of `Uuid`s to {@link (CallInvite:class)}s.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
async getCallInvites() {
|
|
323
|
+
const callInviteInfos = await _common.NativeModule.voice_getCallInvites();
|
|
324
|
+
const callInvitesMap = new Map(callInviteInfos.map(callInviteInfo => [callInviteInfo.uuid, new _CallInvite.CallInvite(callInviteInfo, _CallInvite.CallInvite.State.Pending)]));
|
|
325
|
+
return callInvitesMap;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Handle Firebase messages from an out-of-band Firebase messaging service.
|
|
329
|
+
*
|
|
330
|
+
* @remarks
|
|
331
|
+
*
|
|
332
|
+
* Note that this method only works on Android platforms, and will only work
|
|
333
|
+
* when the built-in Firebase messaging service as been opted-out.
|
|
334
|
+
*
|
|
335
|
+
* Unsupported platforms:
|
|
336
|
+
* - iOS
|
|
337
|
+
*
|
|
338
|
+
* @returns
|
|
339
|
+
* A `Promise` that
|
|
340
|
+
* - Resolves with a boolean. This boolean is `true` if the Firebase message
|
|
341
|
+
* was handled properly, `false` otherwise.
|
|
342
|
+
* - Rejects if an error occurred when parsing the Firebase message, or if
|
|
343
|
+
* the app is incorrectly configured. This method will also reject if used
|
|
344
|
+
* on an unsupported platform.
|
|
345
|
+
*/
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
async handleFirebaseMessage(remoteMessage) {
|
|
349
|
+
switch (_common.Platform.OS) {
|
|
350
|
+
case 'android':
|
|
351
|
+
break;
|
|
352
|
+
|
|
353
|
+
default:
|
|
354
|
+
throw new _UnsupportedPlatformError.UnsupportedPlatformError(`Unsupported platform "${_common.Platform.OS}". This method is only supported on Android.`);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return await _common.NativeModule.voice_handleEvent(remoteMessage);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Register this device for incoming calls.
|
|
361
|
+
* @param token - A Twilio Access Token.
|
|
362
|
+
* @returns
|
|
363
|
+
* A `Promise` that
|
|
364
|
+
* - Resolves when the device has been registered.
|
|
365
|
+
*/
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
register(token) {
|
|
369
|
+
return _common.NativeModule.voice_register(token);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Unregister this device for incoming calls.
|
|
373
|
+
* @param token - A Twilio Access Token.
|
|
374
|
+
* @returns
|
|
375
|
+
* A `Promise` that
|
|
376
|
+
* - Resolves when the device has been unregistered.
|
|
377
|
+
*/
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
unregister(token) {
|
|
381
|
+
return _common.NativeModule.voice_unregister(token);
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Get audio device information from the native layer.
|
|
385
|
+
* @returns
|
|
386
|
+
* A `Promise` that
|
|
387
|
+
* - Resolves with a list of the native device's audio devices and the
|
|
388
|
+
* currently selected device.
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
async getAudioDevices() {
|
|
393
|
+
const {
|
|
394
|
+
audioDevices: audioDeviceInfos,
|
|
395
|
+
selectedDevice: selectedDeviceInfo
|
|
396
|
+
} = await _common.NativeModule.voice_getAudioDevices();
|
|
397
|
+
const audioDevices = audioDeviceInfos.map(audioDeviceInfo => new _AudioDevice.AudioDevice(audioDeviceInfo));
|
|
398
|
+
const selectedDevice = typeof selectedDeviceInfo !== 'undefined' ? new _AudioDevice.AudioDevice(selectedDeviceInfo) : undefined;
|
|
399
|
+
return selectedDevice ? {
|
|
400
|
+
audioDevices,
|
|
401
|
+
selectedDevice
|
|
402
|
+
} : {
|
|
403
|
+
audioDevices
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Show the native AV route picker.
|
|
408
|
+
*
|
|
409
|
+
* @remarks
|
|
410
|
+
* Unsupported platforms:
|
|
411
|
+
* - Android
|
|
412
|
+
*
|
|
413
|
+
* This API is specific to iOS and unavailable in Android. If this API is
|
|
414
|
+
* invoked on Android, there will be no operation and the returned `Promise`
|
|
415
|
+
* will immediately resolve with `null`.
|
|
416
|
+
*
|
|
417
|
+
* @returns
|
|
418
|
+
* A `Promise` that
|
|
419
|
+
* - Resolves when the AV Route Picker View is shown.
|
|
420
|
+
*/
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
showAvRoutePickerView() {
|
|
424
|
+
return _common.NativeModule.voice_showNativeAvRoutePicker();
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Initialize a Push Registry instance inside the SDK for handling
|
|
428
|
+
* PushKit device token updates and receiving push notifications.
|
|
429
|
+
*
|
|
430
|
+
* @remarks
|
|
431
|
+
* Unsupported platforms:
|
|
432
|
+
* - Android
|
|
433
|
+
*
|
|
434
|
+
* This API is specific to iOS and unavailable in Android.
|
|
435
|
+
* Use this method if the application does not have an iOS PushKit
|
|
436
|
+
* module and wishes to delegate the event handling to the SDK.
|
|
437
|
+
* Call this method upon launching the app to guarantee that incoming
|
|
438
|
+
* call push notifications will be surfaced to the users, especially when
|
|
439
|
+
* the app is not running in the foreground.
|
|
440
|
+
*
|
|
441
|
+
* @returns
|
|
442
|
+
* A `Promise` that
|
|
443
|
+
* - Resolves when the initialization is done.
|
|
444
|
+
*/
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
async initializePushRegistry() {
|
|
448
|
+
switch (_common.Platform.OS) {
|
|
449
|
+
case 'ios':
|
|
450
|
+
return _common.NativeModule.voice_initializePushRegistry();
|
|
451
|
+
|
|
452
|
+
default:
|
|
453
|
+
throw new _UnsupportedPlatformError.UnsupportedPlatformError(`Unsupported platform "${_common.Platform.OS}". This method is only supported on iOS.`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Custom iOS CallKit configuration.
|
|
458
|
+
*
|
|
459
|
+
* @param configuration - iOS CallKit configuration options.
|
|
460
|
+
*
|
|
461
|
+
* @remarks
|
|
462
|
+
* Unsupported platforms:
|
|
463
|
+
* - Android
|
|
464
|
+
*
|
|
465
|
+
* See {@link CallKit} for more information.
|
|
466
|
+
*
|
|
467
|
+
* @returns
|
|
468
|
+
* A `Promise` that
|
|
469
|
+
* - Resolves when the configuration has been applied.
|
|
470
|
+
* - Rejects if the configuration is unable to be applied.
|
|
471
|
+
*/
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
async setCallKitConfiguration(configuration) {
|
|
475
|
+
switch (_common.Platform.OS) {
|
|
476
|
+
case 'ios':
|
|
477
|
+
return _common.NativeModule.voice_setCallKitConfiguration(configuration);
|
|
478
|
+
|
|
479
|
+
default:
|
|
480
|
+
throw new _UnsupportedPlatformError.UnsupportedPlatformError(`Unsupported platform "${_common.Platform.OS}". This method is only supported on iOS.`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Set the native call contact handle template.
|
|
485
|
+
*
|
|
486
|
+
* This method is used to customize the displayed contact for Android
|
|
487
|
+
* notifications and the contact handle displayed in iOS CallKit UIs.
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```ts
|
|
491
|
+
* await voice.setIncomingCallContactHandleTemplate('Foo ${DisplayName}');
|
|
492
|
+
* ```
|
|
493
|
+
* If an incoming call is made and there is a Twiml Parameter with key
|
|
494
|
+
* "DisplayName" and value "Bar", then the notification title or CallKit
|
|
495
|
+
* handle will display as "Foo Bar".
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```ts
|
|
499
|
+
* await voice.setIncomingCallContactHandleTemplate();
|
|
500
|
+
* ```
|
|
501
|
+
* When invoking this method without any parameters, the template will be
|
|
502
|
+
* unset and the default notification and contact handle behavior is restored.
|
|
503
|
+
*
|
|
504
|
+
* @param template - The string to set the notification and contact handle
|
|
505
|
+
* template to. Note that this value is optional, if the method is invoked
|
|
506
|
+
* with an implicit undefined (no parameter) then the template will be unset
|
|
507
|
+
* and the default notification and contact handle behavior will be restored.
|
|
508
|
+
* Empty string values will be considered as the same as passing `undefined`.
|
|
509
|
+
*
|
|
510
|
+
* @returns
|
|
511
|
+
* A `Promise` that
|
|
512
|
+
* - Resolves with `undefined` if the template were set.
|
|
513
|
+
* - Rejects if the template was unable to be set.
|
|
514
|
+
*/
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
async setIncomingCallContactHandleTemplate(template) {
|
|
518
|
+
await _common.NativeModule.voice_setIncomingCallContactHandleTemplate(template);
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Returns a boolean representing whether or not Android Full Screen
|
|
522
|
+
* notifications are enabled.
|
|
523
|
+
*
|
|
524
|
+
* @remarks
|
|
525
|
+
* Unsupported platforms:
|
|
526
|
+
* - iOS
|
|
527
|
+
*
|
|
528
|
+
* @returns
|
|
529
|
+
* A `Promise` that
|
|
530
|
+
* - Resolves `false` if either of the following is true:
|
|
531
|
+
* - Full Screen Notifications are disabled in your app's configuration.
|
|
532
|
+
* See `docs/disable-full-screen-notifications.md` for more info.
|
|
533
|
+
* - The app was not granted Full Screen Notification permissions by the
|
|
534
|
+
* operating system.
|
|
535
|
+
* - Resolves `true` if none of the above is true.
|
|
536
|
+
* - Rejects if the Android layer encountered an error.
|
|
537
|
+
*/
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
async isFullScreenNotificationEnabled() {
|
|
541
|
+
switch (_common.Platform.OS) {
|
|
542
|
+
case 'ios':
|
|
543
|
+
{
|
|
544
|
+
throw new _UnsupportedPlatformError.UnsupportedPlatformError(`Unsupported platform "${_common.Platform.OS}". This method is only supported on Android.`);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
return _common.NativeModule.system_isFullScreenNotificationEnabled();
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Opens the Android System Settings app to attempt to request Full Screen
|
|
552
|
+
* Notification permissions.
|
|
553
|
+
*
|
|
554
|
+
* @remarks
|
|
555
|
+
* Unsupported platforms:
|
|
556
|
+
* - iOS
|
|
557
|
+
*
|
|
558
|
+
* @returns
|
|
559
|
+
* A `Promise` that
|
|
560
|
+
* - Resolves `void` if the Android System Settings app was opened.
|
|
561
|
+
* - Rejects if the Android system encountered an error while trying to open
|
|
562
|
+
* the System Settings app.
|
|
563
|
+
*/
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
async requestFullScreenNotificationPermission() {
|
|
567
|
+
switch (_common.Platform.OS) {
|
|
568
|
+
case 'ios':
|
|
569
|
+
{
|
|
570
|
+
throw new _UnsupportedPlatformError.UnsupportedPlatformError(`Unsupported platform "${_common.Platform.OS}". This method is only supported on Android.`);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return _common.NativeModule.system_requestFullScreenNotificationPermission();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Provides enumerations and types used by {@link (Voice:class)
|
|
580
|
+
* | Voice objects}.
|
|
581
|
+
*
|
|
582
|
+
* @remarks
|
|
583
|
+
* - See also the {@link (Voice:class) | Voice class}.
|
|
584
|
+
* - See also the {@link (Voice:interface) | Voice interface}.
|
|
585
|
+
*
|
|
586
|
+
* @public
|
|
587
|
+
*/
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
exports.Voice = Voice;
|
|
591
|
+
|
|
592
|
+
(function (_Voice) {
|
|
593
|
+
/**
|
|
594
|
+
* Options to pass to the {@link (Voice:class).connect} method.
|
|
595
|
+
*/
|
|
596
|
+
let Event;
|
|
597
|
+
|
|
598
|
+
(function (Event) {
|
|
599
|
+
Event["AudioDevicesUpdated"] = "audioDevicesUpdated";
|
|
600
|
+
Event["CallInvite"] = "callInvite";
|
|
601
|
+
Event["Error"] = "error";
|
|
602
|
+
Event["Registered"] = "registered";
|
|
603
|
+
Event["Unregistered"] = "unregistered";
|
|
604
|
+
})(Event || (Event = {}));
|
|
605
|
+
|
|
606
|
+
_Voice.Event = Event;
|
|
607
|
+
let Listener;
|
|
608
|
+
|
|
609
|
+
(function (_Listener) {})(Listener || (Listener = _Voice.Listener || (_Voice.Listener = {})));
|
|
610
|
+
})(Voice || (exports.Voice = Voice = {}));
|
|
611
|
+
//# sourceMappingURL=Voice.js.map
|