@webex/calling 3.0.0-next.4 → 3.0.0-next.5
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/CHANGELOG.md +1403 -1403
- package/README.md +74 -74
- package/dist/module/CallHistory/CallHistory.js +81 -81
- package/dist/module/CallHistory/callHistoryFixtures.js +307 -307
- package/dist/module/CallHistory/constants.js +9 -9
- package/dist/module/CallHistory/types.js +1 -1
- package/dist/module/CallSettings/CallSettings.js +65 -65
- package/dist/module/CallSettings/UcmBackendConnector.js +100 -100
- package/dist/module/CallSettings/WxCallBackendConnector.js +287 -287
- package/dist/module/CallSettings/constants.js +11 -11
- package/dist/module/CallSettings/testFixtures.js +62 -62
- package/dist/module/CallSettings/types.js +1 -1
- package/dist/module/CallingClient/CallingClient.js +248 -248
- package/dist/module/CallingClient/callRecordFixtures.js +93 -93
- package/dist/module/CallingClient/calling/CallerId/index.js +169 -169
- package/dist/module/CallingClient/calling/CallerId/types.js +1 -1
- package/dist/module/CallingClient/calling/call.js +1658 -1658
- package/dist/module/CallingClient/calling/callManager.js +284 -284
- package/dist/module/CallingClient/calling/index.js +2 -2
- package/dist/module/CallingClient/calling/types.js +53 -53
- package/dist/module/CallingClient/callingClientFixtures.js +38 -38
- package/dist/module/CallingClient/constants.js +122 -122
- package/dist/module/CallingClient/line/index.js +158 -158
- package/dist/module/CallingClient/line/types.js +15 -15
- package/dist/module/CallingClient/registration/index.js +1 -1
- package/dist/module/CallingClient/registration/register.js +507 -507
- package/dist/module/CallingClient/registration/registerFixtures.js +28 -28
- package/dist/module/CallingClient/registration/types.js +1 -1
- package/dist/module/CallingClient/types.js +1 -1
- package/dist/module/Contacts/ContactsClient.js +484 -484
- package/dist/module/Contacts/constants.js +20 -20
- package/dist/module/Contacts/contactFixtures.js +284 -284
- package/dist/module/Contacts/types.js +10 -10
- package/dist/module/Errors/catalog/CallError.js +26 -26
- package/dist/module/Errors/catalog/CallingDeviceError.js +18 -18
- package/dist/module/Errors/catalog/ExtendedError.js +10 -10
- package/dist/module/Errors/catalog/LineError.js +24 -24
- package/dist/module/Errors/index.js +2 -2
- package/dist/module/Errors/types.js +48 -48
- package/dist/module/Events/impl/index.js +19 -19
- package/dist/module/Events/types.js +83 -83
- package/dist/module/Logger/index.js +114 -114
- package/dist/module/Logger/types.js +25 -25
- package/dist/module/Metrics/index.js +232 -232
- package/dist/module/Metrics/types.js +37 -37
- package/dist/module/SDKConnector/index.js +39 -39
- package/dist/module/SDKConnector/types.js +1 -1
- package/dist/module/SDKConnector/utils.js +12 -12
- package/dist/module/Voicemail/BroadworksBackendConnector.js +291 -291
- package/dist/module/Voicemail/UcmBackendConnector.js +279 -279
- package/dist/module/Voicemail/Voicemail.js +110 -110
- package/dist/module/Voicemail/WxCallBackendConnector.js +279 -279
- package/dist/module/Voicemail/constants.js +29 -29
- package/dist/module/Voicemail/types.js +1 -1
- package/dist/module/Voicemail/voicemailFixture.js +510 -510
- package/dist/module/api.js +6 -6
- package/dist/module/common/Utils.js +802 -802
- package/dist/module/common/constants.js +41 -41
- package/dist/module/common/index.js +1 -1
- package/dist/module/common/testUtil.js +938 -938
- package/dist/module/common/types.js +57 -57
- package/dist/module/index.js +8 -8
- package/dist/types/CallHistory/CallHistory.d.ts +17 -17
- package/dist/types/CallHistory/callHistoryFixtures.d.ts +94 -94
- package/dist/types/CallHistory/constants.d.ts +9 -9
- package/dist/types/CallHistory/types.d.ts +18 -18
- package/dist/types/CallSettings/CallSettings.d.ts +19 -19
- package/dist/types/CallSettings/UcmBackendConnector.d.ts +19 -19
- package/dist/types/CallSettings/WxCallBackendConnector.d.ts +21 -21
- package/dist/types/CallSettings/constants.d.ts +11 -11
- package/dist/types/CallSettings/testFixtures.d.ts +15 -15
- package/dist/types/CallSettings/types.d.ts +107 -107
- package/dist/types/CallingClient/CallingClient.d.ts +35 -35
- package/dist/types/CallingClient/callRecordFixtures.d.ts +3 -3
- package/dist/types/CallingClient/calling/CallerId/index.d.ts +17 -17
- package/dist/types/CallingClient/calling/CallerId/types.d.ts +41 -41
- package/dist/types/CallingClient/calling/call.d.ts +96 -96
- package/dist/types/CallingClient/calling/callManager.d.ts +25 -25
- package/dist/types/CallingClient/calling/index.d.ts +2 -2
- package/dist/types/CallingClient/calling/types.d.ts +206 -206
- package/dist/types/CallingClient/callingClientFixtures.d.ts +18 -18
- package/dist/types/CallingClient/constants.d.ts +122 -122
- package/dist/types/CallingClient/line/index.d.ts +43 -43
- package/dist/types/CallingClient/line/types.d.ts +55 -55
- package/dist/types/CallingClient/registration/index.d.ts +1 -1
- package/dist/types/CallingClient/registration/register.d.ts +64 -64
- package/dist/types/CallingClient/registration/registerFixtures.d.ts +28 -28
- package/dist/types/CallingClient/registration/types.d.ts +20 -20
- package/dist/types/CallingClient/types.d.ts +29 -29
- package/dist/types/Contacts/ContactsClient.d.ts +26 -26
- package/dist/types/Contacts/constants.d.ts +19 -19
- package/dist/types/Contacts/contactFixtures.d.ts +280 -280
- package/dist/types/Contacts/types.d.ts +72 -72
- package/dist/types/Errors/catalog/CallError.d.ts +11 -11
- package/dist/types/Errors/catalog/CallingDeviceError.d.ts +10 -10
- package/dist/types/Errors/catalog/ExtendedError.d.ts +6 -6
- package/dist/types/Errors/catalog/LineError.d.ts +10 -10
- package/dist/types/Errors/index.d.ts +2 -2
- package/dist/types/Errors/types.d.ts +60 -60
- package/dist/types/Events/impl/index.d.ts +8 -8
- package/dist/types/Events/types.d.ts +288 -288
- package/dist/types/Logger/index.d.ts +12 -12
- package/dist/types/Logger/types.d.ts +25 -25
- package/dist/types/Metrics/index.d.ts +5 -5
- package/dist/types/Metrics/types.d.ts +42 -42
- package/dist/types/SDKConnector/index.d.ts +12 -12
- package/dist/types/SDKConnector/types.d.ts +128 -128
- package/dist/types/SDKConnector/utils.d.ts +5 -5
- package/dist/types/Voicemail/BroadworksBackendConnector.d.ts +27 -27
- package/dist/types/Voicemail/UcmBackendConnector.d.ts +34 -34
- package/dist/types/Voicemail/Voicemail.d.ts +27 -27
- package/dist/types/Voicemail/WxCallBackendConnector.d.ts +23 -23
- package/dist/types/Voicemail/constants.d.ts +29 -29
- package/dist/types/Voicemail/types.d.ts +133 -133
- package/dist/types/Voicemail/voicemailFixture.d.ts +417 -417
- package/dist/types/api.d.ts +16 -16
- package/dist/types/common/Utils.d.ts +34 -34
- package/dist/types/common/constants.d.ts +41 -41
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/common/testUtil.d.ts +3611 -3611
- package/dist/types/common/types.d.ts +191 -191
- package/dist/types/index.d.ts +8 -8
- package/package.json +2 -2
|
@@ -1,284 +1,284 @@
|
|
|
1
|
-
import { CALL_MANAGER_FILE } from '../constants';
|
|
2
|
-
import { CALLING_CLIENT_EVENT_KEYS, LINE_EVENT_KEYS } from '../../Events/types';
|
|
3
|
-
import { Eventing } from '../../Events/impl';
|
|
4
|
-
import SDKConnector from '../../SDKConnector';
|
|
5
|
-
import { CallDirection } from '../../common/types';
|
|
6
|
-
import { MediaState, MobiusEventType, } from './types';
|
|
7
|
-
import { createCall } from './call';
|
|
8
|
-
import log from '../../Logger';
|
|
9
|
-
let callManager;
|
|
10
|
-
export class CallManager extends Eventing {
|
|
11
|
-
sdkConnector;
|
|
12
|
-
webex;
|
|
13
|
-
callCollection;
|
|
14
|
-
activeMobiusUrl;
|
|
15
|
-
serviceIndicator;
|
|
16
|
-
lineDict;
|
|
17
|
-
constructor(webex, indicator) {
|
|
18
|
-
super();
|
|
19
|
-
this.sdkConnector = SDKConnector;
|
|
20
|
-
this.serviceIndicator = indicator;
|
|
21
|
-
if (!this.sdkConnector.getWebex()) {
|
|
22
|
-
SDKConnector.setWebex(webex);
|
|
23
|
-
}
|
|
24
|
-
this.lineDict = {};
|
|
25
|
-
this.webex = this.sdkConnector.getWebex();
|
|
26
|
-
this.callCollection = {};
|
|
27
|
-
this.activeMobiusUrl = '';
|
|
28
|
-
this.listenForWsEvents();
|
|
29
|
-
}
|
|
30
|
-
createCall = (destination, direction, deviceId, lineId) => {
|
|
31
|
-
log.log('Creating call object', {});
|
|
32
|
-
const newCall = createCall(this.activeMobiusUrl, this.webex, destination, direction, deviceId, lineId, (correlationId) => {
|
|
33
|
-
delete this.callCollection[correlationId];
|
|
34
|
-
const activeCalls = Object.keys(this.getActiveCalls()).length;
|
|
35
|
-
log.info(`DELETE:: Deleted corelationId: ${newCall.getCorrelationId()} from CallManager, Number of call records :- ${activeCalls}`, {});
|
|
36
|
-
if (activeCalls === 0) {
|
|
37
|
-
this.emit(CALLING_CLIENT_EVENT_KEYS.ALL_CALLS_CLEARED);
|
|
38
|
-
}
|
|
39
|
-
}, this.serviceIndicator);
|
|
40
|
-
this.callCollection[newCall.getCorrelationId()] = newCall;
|
|
41
|
-
log.log(`New call created with correlationId: ${newCall.getCorrelationId()}`, {});
|
|
42
|
-
log.info(`ADD:: Added corelationId: ${newCall.getCorrelationId()} to CallManager , Number of call records now:- ${Object.keys(this.getActiveCalls()).length}`, {});
|
|
43
|
-
return newCall;
|
|
44
|
-
};
|
|
45
|
-
updateActiveMobius(url) {
|
|
46
|
-
this.activeMobiusUrl = url;
|
|
47
|
-
}
|
|
48
|
-
listenForWsEvents() {
|
|
49
|
-
this.sdkConnector.registerListener('event:mobius', async (event) => {
|
|
50
|
-
this.dequeueWsEvents(event);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
dequeueWsEvents(event) {
|
|
54
|
-
const mobiusEvent = event;
|
|
55
|
-
const { callId, correlationId } = mobiusEvent.data;
|
|
56
|
-
switch (mobiusEvent.data.eventType) {
|
|
57
|
-
case MobiusEventType.CALL_SETUP: {
|
|
58
|
-
log.log(`Received call Setup message for call: ${callId}`, {
|
|
59
|
-
file: CALL_MANAGER_FILE,
|
|
60
|
-
method: 'dequeueWsEvents',
|
|
61
|
-
});
|
|
62
|
-
if (mobiusEvent.data.midCallService) {
|
|
63
|
-
mobiusEvent.data.midCallService.forEach((midCallEvent) => {
|
|
64
|
-
const call = this.getCall(correlationId);
|
|
65
|
-
if (call) {
|
|
66
|
-
call.handleMidCallEvent(midCallEvent);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
log.log(`Dropping midcall event of type: ${midCallEvent.eventType} as it doesn't match with any existing call`, {
|
|
70
|
-
file: CALL_MANAGER_FILE,
|
|
71
|
-
method: 'dequeueWsEvents',
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const newId = Object.keys(this.callCollection).find((id) => this.callCollection[id].getCallId() === callId);
|
|
78
|
-
let newCall;
|
|
79
|
-
if (!newId) {
|
|
80
|
-
const lineId = this.getLineId(mobiusEvent.data.deviceId);
|
|
81
|
-
newCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId, lineId);
|
|
82
|
-
log.log(`New incoming call created with correlationId from Call Setup message: ${newCall.getCorrelationId()}`, {
|
|
83
|
-
file: CALL_MANAGER_FILE,
|
|
84
|
-
method: 'dequeueWsEvents',
|
|
85
|
-
});
|
|
86
|
-
newCall.setCallId(callId);
|
|
87
|
-
if (mobiusEvent.data.broadworksCorrelationInfo) {
|
|
88
|
-
log.log(`Found broadworksCorrelationInfo: ${mobiusEvent.data.broadworksCorrelationInfo}`, {
|
|
89
|
-
file: CALL_MANAGER_FILE,
|
|
90
|
-
method: 'dequeueWsEvents',
|
|
91
|
-
});
|
|
92
|
-
newCall.setBroadworksCorrelationInfo(mobiusEvent.data.broadworksCorrelationInfo);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
log.info(`Found the call Object with a matching callId: ${callId} from our records with correlationId: ${newId}`, {
|
|
97
|
-
file: CALL_MANAGER_FILE,
|
|
98
|
-
method: 'dequeueWsEvents',
|
|
99
|
-
});
|
|
100
|
-
newCall = this.getCall(newId);
|
|
101
|
-
}
|
|
102
|
-
if (mobiusEvent.data.callerId) {
|
|
103
|
-
log.info('Processing Caller-Id data', {
|
|
104
|
-
file: CALL_MANAGER_FILE,
|
|
105
|
-
method: 'dequeueWsEvents',
|
|
106
|
-
});
|
|
107
|
-
newCall.startCallerIdResolution(mobiusEvent.data.callerId);
|
|
108
|
-
}
|
|
109
|
-
this.emit(LINE_EVENT_KEYS.INCOMING_CALL, newCall);
|
|
110
|
-
newCall.sendCallStateMachineEvt({ type: 'E_RECV_CALL_SETUP', data: mobiusEvent.data });
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
case MobiusEventType.CALL_PROGRESS: {
|
|
114
|
-
log.log(`Received call progress mobiusEvent for call: ${correlationId}`, {
|
|
115
|
-
file: CALL_MANAGER_FILE,
|
|
116
|
-
method: 'dequeueWsEvents',
|
|
117
|
-
});
|
|
118
|
-
const call = this.getCall(correlationId);
|
|
119
|
-
call.sendCallStateMachineEvt({ type: 'E_RECV_CALL_PROGRESS', data: mobiusEvent.data });
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
case MobiusEventType.CALL_MEDIA: {
|
|
123
|
-
log.log(`Received call media mobiusEvent for call: ${correlationId}`, {
|
|
124
|
-
file: CALL_MANAGER_FILE,
|
|
125
|
-
method: 'dequeueWsEvents',
|
|
126
|
-
});
|
|
127
|
-
let activeCall;
|
|
128
|
-
if (correlationId) {
|
|
129
|
-
activeCall = this.getCall(correlationId);
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
const newId = Object.keys(this.callCollection).find((id) => this.callCollection[id].getCallId() === callId);
|
|
133
|
-
if (newId) {
|
|
134
|
-
log.info(`Found the call Object with a matching callId: ${callId} from our records with correlationId: ${newId}`, {
|
|
135
|
-
file: CALL_MANAGER_FILE,
|
|
136
|
-
method: 'dequeueWsEvents',
|
|
137
|
-
});
|
|
138
|
-
activeCall = this.getCall(newId);
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
const lineId = this.getLineId(mobiusEvent.data.deviceId);
|
|
142
|
-
activeCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId, lineId);
|
|
143
|
-
log.log(`New incoming call created with correlationId from ROAP Message: ${activeCall.getCorrelationId()}`, {
|
|
144
|
-
file: CALL_MANAGER_FILE,
|
|
145
|
-
method: 'dequeueWsEvents',
|
|
146
|
-
});
|
|
147
|
-
activeCall.setCallId(callId);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (activeCall) {
|
|
151
|
-
log.info(`SDP from mobius ${mobiusEvent.data.message?.sdp}`, {
|
|
152
|
-
file: CALL_MANAGER_FILE,
|
|
153
|
-
method: 'dequeueWsEvents',
|
|
154
|
-
});
|
|
155
|
-
log.log(`ROAP message from mobius with type: ${mobiusEvent.data.message?.messageType}, seq: ${mobiusEvent.data.message?.seq} , version: ${mobiusEvent.data.message?.version}`, {
|
|
156
|
-
file: CALL_MANAGER_FILE,
|
|
157
|
-
method: 'dequeueWsEvents',
|
|
158
|
-
});
|
|
159
|
-
const mediaState = mobiusEvent.data.message?.messageType;
|
|
160
|
-
switch (mediaState) {
|
|
161
|
-
case MediaState.OFFER: {
|
|
162
|
-
log.log('Received OFFER', {
|
|
163
|
-
file: CALL_MANAGER_FILE,
|
|
164
|
-
method: 'dequeueWsEvents',
|
|
165
|
-
});
|
|
166
|
-
activeCall.sendMediaStateMachineEvt({
|
|
167
|
-
type: 'E_RECV_ROAP_OFFER',
|
|
168
|
-
data: mobiusEvent.data.message,
|
|
169
|
-
});
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
case MediaState.ANSWER: {
|
|
173
|
-
log.log('Received ANSWER', {
|
|
174
|
-
file: CALL_MANAGER_FILE,
|
|
175
|
-
method: 'dequeueWsEvents',
|
|
176
|
-
});
|
|
177
|
-
activeCall.sendMediaStateMachineEvt({
|
|
178
|
-
type: 'E_RECV_ROAP_ANSWER',
|
|
179
|
-
data: mobiusEvent.data.message,
|
|
180
|
-
});
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
case MediaState.OFFER_REQUEST: {
|
|
184
|
-
log.log('Received OFFER_REQUEST', {
|
|
185
|
-
file: CALL_MANAGER_FILE,
|
|
186
|
-
method: 'dequeueWsEvents',
|
|
187
|
-
});
|
|
188
|
-
activeCall.sendMediaStateMachineEvt({
|
|
189
|
-
type: 'E_RECV_ROAP_OFFER_REQUEST',
|
|
190
|
-
data: mobiusEvent.data.message,
|
|
191
|
-
});
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
case MediaState.OK: {
|
|
195
|
-
log.log('Received OK', {
|
|
196
|
-
file: CALL_MANAGER_FILE,
|
|
197
|
-
method: 'dequeueWsEvents',
|
|
198
|
-
});
|
|
199
|
-
const mediaOk = {
|
|
200
|
-
received: true,
|
|
201
|
-
message: mobiusEvent.data.message,
|
|
202
|
-
};
|
|
203
|
-
activeCall.sendMediaStateMachineEvt({
|
|
204
|
-
type: 'E_ROAP_OK',
|
|
205
|
-
data: mediaOk,
|
|
206
|
-
});
|
|
207
|
-
break;
|
|
208
|
-
}
|
|
209
|
-
case MediaState.ERROR: {
|
|
210
|
-
log.log('Received Error...', {
|
|
211
|
-
file: CALL_MANAGER_FILE,
|
|
212
|
-
method: 'dequeueWsEvents',
|
|
213
|
-
});
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
default: {
|
|
217
|
-
log.log(`Unknown Media mobiusEvent: ${mediaState} `, {
|
|
218
|
-
file: CALL_MANAGER_FILE,
|
|
219
|
-
method: 'dequeueWsEvents',
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
log.log(`CorrelationId: ${correlationId} doesn't exist , discarding..`, {
|
|
226
|
-
file: CALL_MANAGER_FILE,
|
|
227
|
-
method: 'dequeueWsEvents',
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
case MobiusEventType.CALL_CONNECTED: {
|
|
233
|
-
log.log(`Received call connect for call: ${correlationId}`, {
|
|
234
|
-
file: CALL_MANAGER_FILE,
|
|
235
|
-
method: 'dequeueWsEvents',
|
|
236
|
-
});
|
|
237
|
-
const call = this.getCall(correlationId);
|
|
238
|
-
call.sendCallStateMachineEvt({ type: 'E_RECV_CALL_CONNECT', data: mobiusEvent.data });
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
case MobiusEventType.CALL_DISCONNECTED: {
|
|
242
|
-
log.log(`Received call disconnect for call: ${correlationId}`, {
|
|
243
|
-
file: CALL_MANAGER_FILE,
|
|
244
|
-
method: 'dequeueWsEvents',
|
|
245
|
-
});
|
|
246
|
-
const call = this.getCall(correlationId);
|
|
247
|
-
if (call) {
|
|
248
|
-
call.sendCallStateMachineEvt({ type: 'E_RECV_CALL_DISCONNECT' });
|
|
249
|
-
}
|
|
250
|
-
break;
|
|
251
|
-
}
|
|
252
|
-
default: {
|
|
253
|
-
log.log(`Unknown Call Event mobiusEvent: ${mobiusEvent.data.eventType}`, {
|
|
254
|
-
file: CALL_MANAGER_FILE,
|
|
255
|
-
method: 'dequeueWsEvents',
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
endCall = (correlationId) => {
|
|
261
|
-
const call = this.getCall(correlationId);
|
|
262
|
-
if (call) {
|
|
263
|
-
call.end();
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
getCall = (correlationId) => {
|
|
267
|
-
return this.callCollection[correlationId];
|
|
268
|
-
};
|
|
269
|
-
getActiveCalls = () => {
|
|
270
|
-
return this.callCollection;
|
|
271
|
-
};
|
|
272
|
-
updateLine(deviceId, line) {
|
|
273
|
-
this.lineDict[deviceId] = line;
|
|
274
|
-
}
|
|
275
|
-
getLineId(deviceId) {
|
|
276
|
-
return this.lineDict[deviceId].lineId;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
export const getCallManager = (webex, indicator) => {
|
|
280
|
-
if (!callManager) {
|
|
281
|
-
callManager = new CallManager(webex, indicator);
|
|
282
|
-
}
|
|
283
|
-
return callManager;
|
|
284
|
-
};
|
|
1
|
+
import { CALL_MANAGER_FILE } from '../constants';
|
|
2
|
+
import { CALLING_CLIENT_EVENT_KEYS, LINE_EVENT_KEYS } from '../../Events/types';
|
|
3
|
+
import { Eventing } from '../../Events/impl';
|
|
4
|
+
import SDKConnector from '../../SDKConnector';
|
|
5
|
+
import { CallDirection } from '../../common/types';
|
|
6
|
+
import { MediaState, MobiusEventType, } from './types';
|
|
7
|
+
import { createCall } from './call';
|
|
8
|
+
import log from '../../Logger';
|
|
9
|
+
let callManager;
|
|
10
|
+
export class CallManager extends Eventing {
|
|
11
|
+
sdkConnector;
|
|
12
|
+
webex;
|
|
13
|
+
callCollection;
|
|
14
|
+
activeMobiusUrl;
|
|
15
|
+
serviceIndicator;
|
|
16
|
+
lineDict;
|
|
17
|
+
constructor(webex, indicator) {
|
|
18
|
+
super();
|
|
19
|
+
this.sdkConnector = SDKConnector;
|
|
20
|
+
this.serviceIndicator = indicator;
|
|
21
|
+
if (!this.sdkConnector.getWebex()) {
|
|
22
|
+
SDKConnector.setWebex(webex);
|
|
23
|
+
}
|
|
24
|
+
this.lineDict = {};
|
|
25
|
+
this.webex = this.sdkConnector.getWebex();
|
|
26
|
+
this.callCollection = {};
|
|
27
|
+
this.activeMobiusUrl = '';
|
|
28
|
+
this.listenForWsEvents();
|
|
29
|
+
}
|
|
30
|
+
createCall = (destination, direction, deviceId, lineId) => {
|
|
31
|
+
log.log('Creating call object', {});
|
|
32
|
+
const newCall = createCall(this.activeMobiusUrl, this.webex, destination, direction, deviceId, lineId, (correlationId) => {
|
|
33
|
+
delete this.callCollection[correlationId];
|
|
34
|
+
const activeCalls = Object.keys(this.getActiveCalls()).length;
|
|
35
|
+
log.info(`DELETE:: Deleted corelationId: ${newCall.getCorrelationId()} from CallManager, Number of call records :- ${activeCalls}`, {});
|
|
36
|
+
if (activeCalls === 0) {
|
|
37
|
+
this.emit(CALLING_CLIENT_EVENT_KEYS.ALL_CALLS_CLEARED);
|
|
38
|
+
}
|
|
39
|
+
}, this.serviceIndicator);
|
|
40
|
+
this.callCollection[newCall.getCorrelationId()] = newCall;
|
|
41
|
+
log.log(`New call created with correlationId: ${newCall.getCorrelationId()}`, {});
|
|
42
|
+
log.info(`ADD:: Added corelationId: ${newCall.getCorrelationId()} to CallManager , Number of call records now:- ${Object.keys(this.getActiveCalls()).length}`, {});
|
|
43
|
+
return newCall;
|
|
44
|
+
};
|
|
45
|
+
updateActiveMobius(url) {
|
|
46
|
+
this.activeMobiusUrl = url;
|
|
47
|
+
}
|
|
48
|
+
listenForWsEvents() {
|
|
49
|
+
this.sdkConnector.registerListener('event:mobius', async (event) => {
|
|
50
|
+
this.dequeueWsEvents(event);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
dequeueWsEvents(event) {
|
|
54
|
+
const mobiusEvent = event;
|
|
55
|
+
const { callId, correlationId } = mobiusEvent.data;
|
|
56
|
+
switch (mobiusEvent.data.eventType) {
|
|
57
|
+
case MobiusEventType.CALL_SETUP: {
|
|
58
|
+
log.log(`Received call Setup message for call: ${callId}`, {
|
|
59
|
+
file: CALL_MANAGER_FILE,
|
|
60
|
+
method: 'dequeueWsEvents',
|
|
61
|
+
});
|
|
62
|
+
if (mobiusEvent.data.midCallService) {
|
|
63
|
+
mobiusEvent.data.midCallService.forEach((midCallEvent) => {
|
|
64
|
+
const call = this.getCall(correlationId);
|
|
65
|
+
if (call) {
|
|
66
|
+
call.handleMidCallEvent(midCallEvent);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
log.log(`Dropping midcall event of type: ${midCallEvent.eventType} as it doesn't match with any existing call`, {
|
|
70
|
+
file: CALL_MANAGER_FILE,
|
|
71
|
+
method: 'dequeueWsEvents',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const newId = Object.keys(this.callCollection).find((id) => this.callCollection[id].getCallId() === callId);
|
|
78
|
+
let newCall;
|
|
79
|
+
if (!newId) {
|
|
80
|
+
const lineId = this.getLineId(mobiusEvent.data.deviceId);
|
|
81
|
+
newCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId, lineId);
|
|
82
|
+
log.log(`New incoming call created with correlationId from Call Setup message: ${newCall.getCorrelationId()}`, {
|
|
83
|
+
file: CALL_MANAGER_FILE,
|
|
84
|
+
method: 'dequeueWsEvents',
|
|
85
|
+
});
|
|
86
|
+
newCall.setCallId(callId);
|
|
87
|
+
if (mobiusEvent.data.broadworksCorrelationInfo) {
|
|
88
|
+
log.log(`Found broadworksCorrelationInfo: ${mobiusEvent.data.broadworksCorrelationInfo}`, {
|
|
89
|
+
file: CALL_MANAGER_FILE,
|
|
90
|
+
method: 'dequeueWsEvents',
|
|
91
|
+
});
|
|
92
|
+
newCall.setBroadworksCorrelationInfo(mobiusEvent.data.broadworksCorrelationInfo);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
log.info(`Found the call Object with a matching callId: ${callId} from our records with correlationId: ${newId}`, {
|
|
97
|
+
file: CALL_MANAGER_FILE,
|
|
98
|
+
method: 'dequeueWsEvents',
|
|
99
|
+
});
|
|
100
|
+
newCall = this.getCall(newId);
|
|
101
|
+
}
|
|
102
|
+
if (mobiusEvent.data.callerId) {
|
|
103
|
+
log.info('Processing Caller-Id data', {
|
|
104
|
+
file: CALL_MANAGER_FILE,
|
|
105
|
+
method: 'dequeueWsEvents',
|
|
106
|
+
});
|
|
107
|
+
newCall.startCallerIdResolution(mobiusEvent.data.callerId);
|
|
108
|
+
}
|
|
109
|
+
this.emit(LINE_EVENT_KEYS.INCOMING_CALL, newCall);
|
|
110
|
+
newCall.sendCallStateMachineEvt({ type: 'E_RECV_CALL_SETUP', data: mobiusEvent.data });
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
case MobiusEventType.CALL_PROGRESS: {
|
|
114
|
+
log.log(`Received call progress mobiusEvent for call: ${correlationId}`, {
|
|
115
|
+
file: CALL_MANAGER_FILE,
|
|
116
|
+
method: 'dequeueWsEvents',
|
|
117
|
+
});
|
|
118
|
+
const call = this.getCall(correlationId);
|
|
119
|
+
call.sendCallStateMachineEvt({ type: 'E_RECV_CALL_PROGRESS', data: mobiusEvent.data });
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case MobiusEventType.CALL_MEDIA: {
|
|
123
|
+
log.log(`Received call media mobiusEvent for call: ${correlationId}`, {
|
|
124
|
+
file: CALL_MANAGER_FILE,
|
|
125
|
+
method: 'dequeueWsEvents',
|
|
126
|
+
});
|
|
127
|
+
let activeCall;
|
|
128
|
+
if (correlationId) {
|
|
129
|
+
activeCall = this.getCall(correlationId);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const newId = Object.keys(this.callCollection).find((id) => this.callCollection[id].getCallId() === callId);
|
|
133
|
+
if (newId) {
|
|
134
|
+
log.info(`Found the call Object with a matching callId: ${callId} from our records with correlationId: ${newId}`, {
|
|
135
|
+
file: CALL_MANAGER_FILE,
|
|
136
|
+
method: 'dequeueWsEvents',
|
|
137
|
+
});
|
|
138
|
+
activeCall = this.getCall(newId);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
const lineId = this.getLineId(mobiusEvent.data.deviceId);
|
|
142
|
+
activeCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId, lineId);
|
|
143
|
+
log.log(`New incoming call created with correlationId from ROAP Message: ${activeCall.getCorrelationId()}`, {
|
|
144
|
+
file: CALL_MANAGER_FILE,
|
|
145
|
+
method: 'dequeueWsEvents',
|
|
146
|
+
});
|
|
147
|
+
activeCall.setCallId(callId);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (activeCall) {
|
|
151
|
+
log.info(`SDP from mobius ${mobiusEvent.data.message?.sdp}`, {
|
|
152
|
+
file: CALL_MANAGER_FILE,
|
|
153
|
+
method: 'dequeueWsEvents',
|
|
154
|
+
});
|
|
155
|
+
log.log(`ROAP message from mobius with type: ${mobiusEvent.data.message?.messageType}, seq: ${mobiusEvent.data.message?.seq} , version: ${mobiusEvent.data.message?.version}`, {
|
|
156
|
+
file: CALL_MANAGER_FILE,
|
|
157
|
+
method: 'dequeueWsEvents',
|
|
158
|
+
});
|
|
159
|
+
const mediaState = mobiusEvent.data.message?.messageType;
|
|
160
|
+
switch (mediaState) {
|
|
161
|
+
case MediaState.OFFER: {
|
|
162
|
+
log.log('Received OFFER', {
|
|
163
|
+
file: CALL_MANAGER_FILE,
|
|
164
|
+
method: 'dequeueWsEvents',
|
|
165
|
+
});
|
|
166
|
+
activeCall.sendMediaStateMachineEvt({
|
|
167
|
+
type: 'E_RECV_ROAP_OFFER',
|
|
168
|
+
data: mobiusEvent.data.message,
|
|
169
|
+
});
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
case MediaState.ANSWER: {
|
|
173
|
+
log.log('Received ANSWER', {
|
|
174
|
+
file: CALL_MANAGER_FILE,
|
|
175
|
+
method: 'dequeueWsEvents',
|
|
176
|
+
});
|
|
177
|
+
activeCall.sendMediaStateMachineEvt({
|
|
178
|
+
type: 'E_RECV_ROAP_ANSWER',
|
|
179
|
+
data: mobiusEvent.data.message,
|
|
180
|
+
});
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
case MediaState.OFFER_REQUEST: {
|
|
184
|
+
log.log('Received OFFER_REQUEST', {
|
|
185
|
+
file: CALL_MANAGER_FILE,
|
|
186
|
+
method: 'dequeueWsEvents',
|
|
187
|
+
});
|
|
188
|
+
activeCall.sendMediaStateMachineEvt({
|
|
189
|
+
type: 'E_RECV_ROAP_OFFER_REQUEST',
|
|
190
|
+
data: mobiusEvent.data.message,
|
|
191
|
+
});
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case MediaState.OK: {
|
|
195
|
+
log.log('Received OK', {
|
|
196
|
+
file: CALL_MANAGER_FILE,
|
|
197
|
+
method: 'dequeueWsEvents',
|
|
198
|
+
});
|
|
199
|
+
const mediaOk = {
|
|
200
|
+
received: true,
|
|
201
|
+
message: mobiusEvent.data.message,
|
|
202
|
+
};
|
|
203
|
+
activeCall.sendMediaStateMachineEvt({
|
|
204
|
+
type: 'E_ROAP_OK',
|
|
205
|
+
data: mediaOk,
|
|
206
|
+
});
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
case MediaState.ERROR: {
|
|
210
|
+
log.log('Received Error...', {
|
|
211
|
+
file: CALL_MANAGER_FILE,
|
|
212
|
+
method: 'dequeueWsEvents',
|
|
213
|
+
});
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
default: {
|
|
217
|
+
log.log(`Unknown Media mobiusEvent: ${mediaState} `, {
|
|
218
|
+
file: CALL_MANAGER_FILE,
|
|
219
|
+
method: 'dequeueWsEvents',
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
log.log(`CorrelationId: ${correlationId} doesn't exist , discarding..`, {
|
|
226
|
+
file: CALL_MANAGER_FILE,
|
|
227
|
+
method: 'dequeueWsEvents',
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
case MobiusEventType.CALL_CONNECTED: {
|
|
233
|
+
log.log(`Received call connect for call: ${correlationId}`, {
|
|
234
|
+
file: CALL_MANAGER_FILE,
|
|
235
|
+
method: 'dequeueWsEvents',
|
|
236
|
+
});
|
|
237
|
+
const call = this.getCall(correlationId);
|
|
238
|
+
call.sendCallStateMachineEvt({ type: 'E_RECV_CALL_CONNECT', data: mobiusEvent.data });
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
case MobiusEventType.CALL_DISCONNECTED: {
|
|
242
|
+
log.log(`Received call disconnect for call: ${correlationId}`, {
|
|
243
|
+
file: CALL_MANAGER_FILE,
|
|
244
|
+
method: 'dequeueWsEvents',
|
|
245
|
+
});
|
|
246
|
+
const call = this.getCall(correlationId);
|
|
247
|
+
if (call) {
|
|
248
|
+
call.sendCallStateMachineEvt({ type: 'E_RECV_CALL_DISCONNECT' });
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
default: {
|
|
253
|
+
log.log(`Unknown Call Event mobiusEvent: ${mobiusEvent.data.eventType}`, {
|
|
254
|
+
file: CALL_MANAGER_FILE,
|
|
255
|
+
method: 'dequeueWsEvents',
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
endCall = (correlationId) => {
|
|
261
|
+
const call = this.getCall(correlationId);
|
|
262
|
+
if (call) {
|
|
263
|
+
call.end();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
getCall = (correlationId) => {
|
|
267
|
+
return this.callCollection[correlationId];
|
|
268
|
+
};
|
|
269
|
+
getActiveCalls = () => {
|
|
270
|
+
return this.callCollection;
|
|
271
|
+
};
|
|
272
|
+
updateLine(deviceId, line) {
|
|
273
|
+
this.lineDict[deviceId] = line;
|
|
274
|
+
}
|
|
275
|
+
getLineId(deviceId) {
|
|
276
|
+
return this.lineDict[deviceId].lineId;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export const getCallManager = (webex, indicator) => {
|
|
280
|
+
if (!callManager) {
|
|
281
|
+
callManager = new CallManager(webex, indicator);
|
|
282
|
+
}
|
|
283
|
+
return callManager;
|
|
284
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './call';
|
|
2
|
-
export * from './callManager';
|
|
1
|
+
export * from './call';
|
|
2
|
+
export * from './callManager';
|