@webex/calling 0.0.1-next.5 → 0.0.1-next.7

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.
@@ -4,7 +4,7 @@ import log from '../Logger';
4
4
  import { serviceErrorCodeHandler } from '../common/Utils';
5
5
  import { CALL_HISTORY_FILE, FROM_DATE, HISTORY, LIMIT, NUMBER_OF_DAYS } from './constants';
6
6
  import { STATUS_CODE, SUCCESS_MESSAGE, USER_SESSIONS } from '../common/constants';
7
- import { EVENT_KEYS, MOBIUS_EVENT_KEYS, } from '../Events/types';
7
+ import { COMMON_EVENT_KEYS, MOBIUS_EVENT_KEYS, } from '../Events/types';
8
8
  import { Eventing } from '../Events/impl';
9
9
  export class CallHistory extends Eventing {
10
10
  sdkConnector;
@@ -76,7 +76,7 @@ export class CallHistory extends Eventing {
76
76
  registerSessionsListener() {
77
77
  this.sdkConnector.registerListener(MOBIUS_EVENT_KEYS.CALL_SESSION_EVENT_INCLUSIVE, async (event) => {
78
78
  if (event && event.data.userSessions.userSessions) {
79
- this.emit(EVENT_KEYS.CALL_HISTORY_USER_SESSION_INFO, event);
79
+ this.emit(COMMON_EVENT_KEYS.CALL_HISTORY_USER_SESSION_INFO, event);
80
80
  }
81
81
  });
82
82
  }
@@ -1,16 +1,14 @@
1
1
  import * as Media from '@webex/internal-media-core';
2
2
  import { Mutex } from 'async-mutex';
3
3
  import { filterMobiusUris, handleCallingClientErrors, validateServiceData } from '../common/Utils';
4
- import { ERROR_TYPE } from '../Errors/types';
5
4
  import { LOGGER } from '../Logger/types';
6
5
  import SDKConnector from '../SDKConnector';
7
6
  import { Eventing } from '../Events/impl';
8
- import { EVENT_KEYS, MOBIUS_EVENT_KEYS, SessionType, } from '../Events/types';
9
- import { MobiusStatus, CallDirection, ServiceIndicator, ALLOWED_SERVICES, HTTP_METHODS, } from '../common/types';
7
+ import { MOBIUS_EVENT_KEYS, SessionType, CALLING_CLIENT_EVENT_KEYS, } from '../Events/types';
8
+ import { ServiceIndicator, ALLOWED_SERVICES, HTTP_METHODS, } from '../common/types';
10
9
  import log from '../Logger';
11
10
  import { getCallManager } from './calling/callManager';
12
- import { CALLING_CLIENT_FILE, VALID_PHONE, CALLS_CLEARED_HANDLER_UTIL, CALLING_USER_AGENT, CISCO_DEVICE_URL, DISCOVERY_URL, GET_MOBIUS_SERVERS_UTIL, IP_ENDPOINT, SPARK_USER_AGENT, URL_ENDPOINT, NETWORK_FLAP_TIMEOUT, } from './constants';
13
- import { CallingClientError } from '../Errors';
11
+ import { CALLING_CLIENT_FILE, CALLS_CLEARED_HANDLER_UTIL, CALLING_USER_AGENT, CISCO_DEVICE_URL, DISCOVERY_URL, GET_MOBIUS_SERVERS_UTIL, IP_ENDPOINT, SPARK_USER_AGENT, URL_ENDPOINT, NETWORK_FLAP_TIMEOUT, } from './constants';
14
12
  import Line from './line';
15
13
  import { LINE_EVENTS, LineStatus } from './line/types';
16
14
  import { METRIC_EVENT, REG_ACTION, METRIC_TYPE } from '../Metrics/types';
@@ -47,7 +45,6 @@ export class CallingClient extends Eventing {
47
45
  this.backupMobiusUris = [];
48
46
  this.registerSessionsListener();
49
47
  log.setLogger(logLevel, CALLING_CLIENT_FILE);
50
- this.incomingCallListener();
51
48
  this.registerCallsClearedListener();
52
49
  }
53
50
  async init() {
@@ -55,16 +52,6 @@ export class CallingClient extends Eventing {
55
52
  await this.createLine();
56
53
  this.detectNetworkChange();
57
54
  }
58
- incomingCallListener() {
59
- const logContext = {
60
- file: CALLING_CLIENT_FILE,
61
- method: this.incomingCallListener.name,
62
- };
63
- log.log('Listening for incoming calls... ', logContext);
64
- this.callManager.on(EVENT_KEYS.INCOMING_CALL, (callObj) => {
65
- this.emit(EVENT_KEYS.INCOMING_CALL, callObj);
66
- });
67
- }
68
55
  async detectNetworkChange() {
69
56
  let retry = false;
70
57
  const line = Object.values(this.lineDict)[0];
@@ -113,7 +100,7 @@ export class CallingClient extends Eventing {
113
100
  catch (err) {
114
101
  handleCallingClientErrors(err, (clientError) => {
115
102
  this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
116
- this.emit(EVENT_KEYS.ERROR, clientError);
103
+ this.emit(CALLING_CLIENT_EVENT_KEYS.ERROR, clientError);
117
104
  }, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
118
105
  regionInfo.clientRegion = '';
119
106
  regionInfo.countryCode = '';
@@ -163,7 +150,7 @@ export class CallingClient extends Eventing {
163
150
  catch (err) {
164
151
  handleCallingClientErrors(err, (clientError) => {
165
152
  this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
166
- this.emit(EVENT_KEYS.ERROR, clientError);
153
+ this.emit(CALLING_CLIENT_EVENT_KEYS.ERROR, clientError);
167
154
  }, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
168
155
  useDefault = true;
169
156
  }
@@ -184,7 +171,7 @@ export class CallingClient extends Eventing {
184
171
  method: this.registerCallsClearedListener.name,
185
172
  };
186
173
  log.log('Registering listener for all calls cleared event', logContext);
187
- this.callManager.on(EVENT_KEYS.ALL_CALLS_CLEARED, this.callsClearedHandler);
174
+ this.callManager.on(CALLING_CLIENT_EVENT_KEYS.ALL_CALLS_CLEARED, this.callsClearedHandler);
188
175
  }
189
176
  callsClearedHandler = async () => {
190
177
  const { registration } = Object.values(this.lineDict)[0];
@@ -203,35 +190,6 @@ export class CallingClient extends Eventing {
203
190
  getLoggingLevel() {
204
191
  return log.getLogLevel();
205
192
  }
206
- getCall = (correlationId) => {
207
- return this.callManager.getCall(correlationId);
208
- };
209
- makeCall = (dest) => {
210
- let call;
211
- const { registration } = Object.values(this.lineDict)[0];
212
- if (dest) {
213
- const match = dest.address.match(VALID_PHONE);
214
- if (match && match[0].length === dest.address.length) {
215
- const sanitizedNumber = dest.address
216
- .replace(/[^[*+]\d#]/gi, '')
217
- .replace(/\s+/gi, '')
218
- .replace(/-/gi, '');
219
- const formattedDest = {
220
- type: dest.type,
221
- address: `tel:${sanitizedNumber}`,
222
- };
223
- call = this.callManager.createCall(formattedDest, CallDirection.OUTBOUND, registration.getDeviceInfo().device?.deviceId);
224
- log.log(`New call created, callId: ${call.getCallId()}`, {});
225
- }
226
- else {
227
- log.warn('Invalid phone number detected', {});
228
- const err = new CallingClientError('An invalid phone number was detected. Check the number and try again.', {}, ERROR_TYPE.CALL_ERROR, MobiusStatus.ACTIVE);
229
- this.emit(EVENT_KEYS.ERROR, err);
230
- }
231
- return call;
232
- }
233
- return undefined;
234
- };
235
193
  getSDKConnector() {
236
194
  return this.sdkConnector;
237
195
  }
@@ -249,7 +207,7 @@ export class CallingClient extends Eventing {
249
207
  sessionArr.splice(i, 1);
250
208
  }
251
209
  }
252
- this.emit(EVENT_KEYS.USER_SESSION_INFO, event);
210
+ this.emit(CALLING_CLIENT_EVENT_KEYS.USER_SESSION_INFO, event);
253
211
  }
254
212
  });
255
213
  }
@@ -260,6 +218,28 @@ export class CallingClient extends Eventing {
260
218
  getLines() {
261
219
  return this.lineDict;
262
220
  }
221
+ getActiveCalls() {
222
+ const activeCalls = {};
223
+ const calls = this.callManager.getActiveCalls();
224
+ Object.keys(calls).forEach((correlationId) => {
225
+ const call = calls[correlationId];
226
+ if (!activeCalls[call.lineId]) {
227
+ activeCalls[call.lineId] = [];
228
+ }
229
+ activeCalls[call.lineId].push(call);
230
+ });
231
+ return activeCalls;
232
+ }
233
+ getConnectedCall() {
234
+ let connectCall;
235
+ const calls = this.callManager.getActiveCalls();
236
+ Object.keys(calls).forEach((correlationId) => {
237
+ if (calls[correlationId].isConnected() && !calls[correlationId].isHeld()) {
238
+ connectCall = calls[correlationId];
239
+ }
240
+ });
241
+ return connectCall;
242
+ }
263
243
  }
264
244
  export const createClient = async (webex, config) => {
265
245
  const callingClientInstance = new CallingClient(webex, config);
@@ -8,7 +8,7 @@ import { createCallError } from '../../Errors/catalog/CallError';
8
8
  import { CALL_ENDPOINT_RESOURCE, CALL_FILE, CALL_HOLD_SERVICE, CALL_STATUS_RESOURCE, CALL_TRANSFER_SERVICE, CALLING_USER_AGENT, CALLS_ENDPOINT_RESOURCE, CISCO_DEVICE_URL, DEFAULT_LOCAL_CALL_ID, DEFAULT_SESSION_TIMER, DEVICES_ENDPOINT_RESOURCE, HOLD_ENDPOINT, INITIAL_SEQ_NUMBER, MEDIA_ENDPOINT_RESOURCE, RESUME_ENDPOINT, SPARK_USER_AGENT, SUPPLEMENTARY_SERVICES_TIMEOUT, TRANSFER_ENDPOINT, } from '../constants';
9
9
  import SDKConnector from '../../SDKConnector';
10
10
  import { Eventing } from '../../Events/impl';
11
- import { EVENT_KEYS, MEDIA_CONNECTION_EVENT_KEYS, MOBIUS_MIDCALL_STATE, SUPPLEMENTARY_SERVICES, } from '../../Events/types';
11
+ import { CALL_EVENT_KEYS, MEDIA_CONNECTION_EVENT_KEYS, MOBIUS_MIDCALL_STATE, SUPPLEMENTARY_SERVICES, } from '../../Events/types';
12
12
  import { DisconnectCause, DisconnectCode, MidCallEventType, MobiusCallState, RoapScenario, TransferType, } from './types';
13
13
  import log from '../../Logger';
14
14
  import { createCallerId } from './CallerId';
@@ -23,6 +23,7 @@ export class Call extends Eventing {
23
23
  callId;
24
24
  correlationId;
25
25
  deviceId;
26
+ lineId;
26
27
  disconnectReason;
27
28
  callStateMachine;
28
29
  mediaStateMachine;
@@ -54,13 +55,14 @@ export class Call extends Eventing {
54
55
  isHeld() {
55
56
  return this.held;
56
57
  }
57
- constructor(activeUrl, webex, destination, direction, deviceId, deleteCb, indicator) {
58
+ constructor(activeUrl, webex, destination, direction, deviceId, lineId, deleteCb, indicator) {
58
59
  super();
59
60
  this.destination = destination;
60
61
  this.direction = direction;
61
62
  this.sdkConnector = SDKConnector;
62
63
  this.deviceId = deviceId;
63
64
  this.serviceIndicator = indicator;
65
+ this.lineId = lineId;
64
66
  if (!this.sdkConnector.getWebex()) {
65
67
  SDKConnector.setWebex(webex);
66
68
  }
@@ -88,7 +90,7 @@ export class Call extends Eventing {
88
90
  correlationId: this.correlationId,
89
91
  callerId: this.callerInfo,
90
92
  };
91
- this.emit(EVENT_KEYS.CALLER_ID, emitObj);
93
+ this.emit(CALL_EVENT_KEYS.CALLER_ID, emitObj);
92
94
  });
93
95
  this.remoteRoapMessage = null;
94
96
  this.disconnectReason = { code: DisconnectCode.NORMAL, cause: DisconnectCause.NORMAL };
@@ -581,7 +583,7 @@ export class Call extends Eventing {
581
583
  });
582
584
  const errData = e;
583
585
  handleCallErrors((error) => {
584
- this.emit(EVENT_KEYS.CALL_ERROR, error);
586
+ this.emit(CALL_EVENT_KEYS.CALL_ERROR, error);
585
587
  this.submitCallErrorMetric(error);
586
588
  this.sendCallStateMachineEvt({ type: 'E_UNKNOWN', data: errData });
587
589
  }, ERROR_LAYER.CALL_CONTROL, (interval) => undefined, this.getCorrelationId(), errData, this.handleOutgoingCallSetup.name, CALL_FILE);
@@ -606,7 +608,7 @@ export class Call extends Eventing {
606
608
  method: this.handleCallHold.name,
607
609
  });
608
610
  const callError = createCallError('An error occurred while placing the call on hold. Wait a moment and try again.', errorContext, ERROR_TYPE.TIMEOUT, this.getCorrelationId(), ERROR_LAYER.CALL_CONTROL);
609
- this.emit(EVENT_KEYS.HOLD_ERROR, callError);
611
+ this.emit(CALL_EVENT_KEYS.HOLD_ERROR, callError);
610
612
  this.submitCallErrorMetric(callError);
611
613
  }, SUPPLEMENTARY_SERVICES_TIMEOUT);
612
614
  }
@@ -618,7 +620,7 @@ export class Call extends Eventing {
618
620
  });
619
621
  const errData = e;
620
622
  handleCallErrors((error) => {
621
- this.emit(EVENT_KEYS.HOLD_ERROR, error);
623
+ this.emit(CALL_EVENT_KEYS.HOLD_ERROR, error);
622
624
  this.submitCallErrorMetric(error);
623
625
  this.sendCallStateMachineEvt({ type: 'E_CALL_ESTABLISHED', data: errData });
624
626
  }, ERROR_LAYER.CALL_CONTROL, (interval) => undefined, this.getCorrelationId(), errData, this.handleOutgoingCallSetup.name, CALL_FILE);
@@ -643,7 +645,7 @@ export class Call extends Eventing {
643
645
  method: this.handleCallResume.name,
644
646
  });
645
647
  const callError = createCallError('An error occurred while resuming the call. Wait a moment and try again.', errorContext, ERROR_TYPE.TIMEOUT, this.getCorrelationId(), ERROR_LAYER.CALL_CONTROL);
646
- this.emit(EVENT_KEYS.RESUME_ERROR, callError);
648
+ this.emit(CALL_EVENT_KEYS.RESUME_ERROR, callError);
647
649
  this.submitCallErrorMetric(callError);
648
650
  }, SUPPLEMENTARY_SERVICES_TIMEOUT);
649
651
  }
@@ -655,7 +657,7 @@ export class Call extends Eventing {
655
657
  });
656
658
  const errData = e;
657
659
  handleCallErrors((error) => {
658
- this.emit(EVENT_KEYS.RESUME_ERROR, error);
660
+ this.emit(CALL_EVENT_KEYS.RESUME_ERROR, error);
659
661
  this.submitCallErrorMetric(error);
660
662
  this.sendCallStateMachineEvt({ type: 'E_CALL_ESTABLISHED', data: errData });
661
663
  }, ERROR_LAYER.CALL_CONTROL, (interval) => undefined, this.getCorrelationId(), errData, this.handleOutgoingCallSetup.name, CALL_FILE);
@@ -687,7 +689,7 @@ export class Call extends Eventing {
687
689
  });
688
690
  this.startCallerIdResolution(data.callerId);
689
691
  }
690
- this.emit(EVENT_KEYS.PROGRESS, this.correlationId);
692
+ this.emit(CALL_EVENT_KEYS.PROGRESS, this.correlationId);
691
693
  }
692
694
  handleIncomingRoapOfferRequest(context, event) {
693
695
  log.info(`handleIncomingRoapOfferRequest: ${this.getCorrelationId()} `, {
@@ -739,7 +741,7 @@ export class Call extends Eventing {
739
741
  });
740
742
  const errData = err;
741
743
  handleCallErrors((error) => {
742
- this.emit(EVENT_KEYS.CALL_ERROR, error);
744
+ this.emit(CALL_EVENT_KEYS.CALL_ERROR, error);
743
745
  this.submitCallErrorMetric(error);
744
746
  this.sendCallStateMachineEvt({ type: 'E_UNKNOWN', data: errData });
745
747
  }, ERROR_LAYER.CALL_CONTROL, (interval) => undefined, this.getCorrelationId(), errData, this.handleOutgoingCallAlerting.name, CALL_FILE);
@@ -750,7 +752,7 @@ export class Call extends Eventing {
750
752
  file: CALL_FILE,
751
753
  method: this.handleIncomingCallConnect.name,
752
754
  });
753
- this.emit(EVENT_KEYS.CONNECT, this.correlationId);
755
+ this.emit(CALL_EVENT_KEYS.CONNECT, this.correlationId);
754
756
  if (this.earlyMedia || this.mediaNegotiationCompleted) {
755
757
  this.mediaNegotiationCompleted = false;
756
758
  this.sendCallStateMachineEvt({ type: 'E_CALL_ESTABLISHED' });
@@ -783,7 +785,7 @@ export class Call extends Eventing {
783
785
  });
784
786
  const errData = err;
785
787
  handleCallErrors((error) => {
786
- this.emit(EVENT_KEYS.CALL_ERROR, error);
788
+ this.emit(CALL_EVENT_KEYS.CALL_ERROR, error);
787
789
  this.submitCallErrorMetric(error);
788
790
  this.sendCallStateMachineEvt({ type: 'E_UNKNOWN', data: errData });
789
791
  }, ERROR_LAYER.CALL_CONTROL, (interval) => undefined, this.getCorrelationId(), errData, this.handleOutgoingCallConnect.name, CALL_FILE);
@@ -818,7 +820,7 @@ export class Call extends Eventing {
818
820
  }
819
821
  this.sendMediaStateMachineEvt({ type: 'E_ROAP_TEARDOWN' });
820
822
  this.sendCallStateMachineEvt({ type: 'E_CALL_CLEARED' });
821
- this.emit(EVENT_KEYS.DISCONNECT, this.correlationId);
823
+ this.emit(CALL_EVENT_KEYS.DISCONNECT, this.correlationId);
822
824
  }
823
825
  async handleOutgoingCallDisconnect(event) {
824
826
  this.setDisconnectReason();
@@ -851,7 +853,7 @@ export class Call extends Eventing {
851
853
  file: CALL_FILE,
852
854
  method: this.handleCallEstablished.name,
853
855
  });
854
- this.emit(EVENT_KEYS.ESTABLISHED, this.correlationId);
856
+ this.emit(CALL_EVENT_KEYS.ESTABLISHED, this.correlationId);
855
857
  this.earlyMedia = false;
856
858
  this.connected = true;
857
859
  if (this.sessionTimer) {
@@ -875,7 +877,7 @@ export class Call extends Eventing {
875
877
  clearInterval(this.sessionTimer);
876
878
  }
877
879
  handleCallErrors((callError) => {
878
- this.emit(EVENT_KEYS.CALL_ERROR, callError);
880
+ this.emit(CALL_EVENT_KEYS.CALL_ERROR, callError);
879
881
  this.submitCallErrorMetric(callError);
880
882
  }, ERROR_LAYER.CALL_CONTROL, (interval) => {
881
883
  setTimeout(() => {
@@ -930,7 +932,7 @@ export class Call extends Eventing {
930
932
  return (error) => {
931
933
  switch (this.callStateMachine.state.value) {
932
934
  case 'S_CALL_HOLD':
933
- this.emit(EVENT_KEYS.HOLD_ERROR, error);
935
+ this.emit(CALL_EVENT_KEYS.HOLD_ERROR, error);
934
936
  if (this.supplementaryServicesTimer) {
935
937
  clearTimeout(this.supplementaryServicesTimer);
936
938
  this.supplementaryServicesTimer = undefined;
@@ -939,12 +941,12 @@ export class Call extends Eventing {
939
941
  this.sendCallStateMachineEvt({ type: 'E_CALL_ESTABLISHED', data: errData });
940
942
  return;
941
943
  case 'S_CALL_RESUME':
942
- this.emit(EVENT_KEYS.RESUME_ERROR, error);
944
+ this.emit(CALL_EVENT_KEYS.RESUME_ERROR, error);
943
945
  this.submitCallErrorMetric(error);
944
946
  this.sendCallStateMachineEvt({ type: 'E_CALL_ESTABLISHED', data: errData });
945
947
  return;
946
948
  default:
947
- this.emit(EVENT_KEYS.CALL_ERROR, error);
949
+ this.emit(CALL_EVENT_KEYS.CALL_ERROR, error);
948
950
  this.submitCallErrorMetric(error);
949
951
  if (!this.connected) {
950
952
  this.sendMediaStateMachineEvt({ type: 'E_ROAP_ERROR', data: errData });
@@ -1043,7 +1045,7 @@ export class Call extends Eventing {
1043
1045
  });
1044
1046
  const errData = err;
1045
1047
  handleCallErrors((error) => {
1046
- this.emit(EVENT_KEYS.CALL_ERROR, error);
1048
+ this.emit(CALL_EVENT_KEYS.CALL_ERROR, error);
1047
1049
  this.submitCallErrorMetric(error);
1048
1050
  }, ERROR_LAYER.MEDIA, (interval) => undefined, this.getCorrelationId(), errData, this.handleRoapError.name, CALL_FILE);
1049
1051
  }
@@ -1382,7 +1384,7 @@ export class Call extends Eventing {
1382
1384
  });
1383
1385
  const errData = e;
1384
1386
  handleCallErrors((error) => {
1385
- this.emit(EVENT_KEYS.TRANSFER_ERROR, error);
1387
+ this.emit(CALL_EVENT_KEYS.TRANSFER_ERROR, error);
1386
1388
  this.submitCallErrorMetric(error, TRANSFER_ACTION.BLIND);
1387
1389
  }, ERROR_LAYER.CALL_CONTROL, (interval) => undefined, this.getCorrelationId(), errData, this.completeTransfer.name, CALL_FILE);
1388
1390
  }
@@ -1407,7 +1409,7 @@ export class Call extends Eventing {
1407
1409
  });
1408
1410
  const errData = e;
1409
1411
  handleCallErrors((error) => {
1410
- this.emit(EVENT_KEYS.TRANSFER_ERROR, error);
1412
+ this.emit(CALL_EVENT_KEYS.TRANSFER_ERROR, error);
1411
1413
  this.submitCallErrorMetric(error, TRANSFER_ACTION.CONSULT);
1412
1414
  }, ERROR_LAYER.CALL_CONTROL, (interval) => undefined, this.getCorrelationId(), errData, this.completeTransfer.name, CALL_FILE);
1413
1415
  }
@@ -1500,7 +1502,7 @@ export class Call extends Eventing {
1500
1502
  mediaTrackListener() {
1501
1503
  this.mediaConnection.on(Event.REMOTE_TRACK_ADDED, (e) => {
1502
1504
  if (e.type === MEDIA_CONNECTION_EVENT_KEYS.MEDIA_TYPE_AUDIO) {
1503
- this.emit(EVENT_KEYS.REMOTE_MEDIA, e.track);
1505
+ this.emit(CALL_EVENT_KEYS.REMOTE_MEDIA, e.track);
1504
1506
  }
1505
1507
  });
1506
1508
  }
@@ -1558,7 +1560,7 @@ export class Call extends Eventing {
1558
1560
  file: CALL_FILE,
1559
1561
  method: 'handleMidCallEvent',
1560
1562
  });
1561
- this.emit(EVENT_KEYS.HELD, this.correlationId);
1563
+ this.emit(CALL_EVENT_KEYS.HELD, this.correlationId);
1562
1564
  this.held = true;
1563
1565
  if (this.supplementaryServicesTimer) {
1564
1566
  clearTimeout(this.supplementaryServicesTimer);
@@ -1571,7 +1573,7 @@ export class Call extends Eventing {
1571
1573
  file: CALL_FILE,
1572
1574
  method: 'handleMidCallEvent',
1573
1575
  });
1574
- this.emit(EVENT_KEYS.RESUMED, this.correlationId);
1576
+ this.emit(CALL_EVENT_KEYS.RESUMED, this.correlationId);
1575
1577
  this.held = false;
1576
1578
  if (this.supplementaryServicesTimer) {
1577
1579
  clearTimeout(this.supplementaryServicesTimer);
@@ -1646,4 +1648,4 @@ export class Call extends Eventing {
1646
1648
  return this.getCallStats();
1647
1649
  }
1648
1650
  }
1649
- export const createCall = (activeUrl, webex, dest, dir, deviceId, deleteCb, indicator) => new Call(activeUrl, webex, dest, dir, deviceId, deleteCb, indicator);
1651
+ export const createCall = (activeUrl, webex, dest, dir, deviceId, lineId, deleteCb, indicator) => new Call(activeUrl, webex, dest, dir, deviceId, lineId, deleteCb, indicator);
@@ -1,5 +1,5 @@
1
1
  import { CALL_MANAGER_FILE } from '../constants';
2
- import { EVENT_KEYS } from '../../Events/types';
2
+ import { CALLING_CLIENT_EVENT_KEYS, LINE_EVENT_KEYS } from '../../Events/types';
3
3
  import { Eventing } from '../../Events/impl';
4
4
  import SDKConnector from '../../SDKConnector';
5
5
  import { CallDirection } from '../../common/types';
@@ -13,6 +13,7 @@ export class CallManager extends Eventing {
13
13
  callCollection;
14
14
  activeMobiusUrl;
15
15
  serviceIndicator;
16
+ lineDict;
16
17
  constructor(webex, indicator) {
17
18
  super();
18
19
  this.sdkConnector = SDKConnector;
@@ -20,19 +21,20 @@ export class CallManager extends Eventing {
20
21
  if (!this.sdkConnector.getWebex()) {
21
22
  SDKConnector.setWebex(webex);
22
23
  }
24
+ this.lineDict = {};
23
25
  this.webex = this.sdkConnector.getWebex();
24
26
  this.callCollection = {};
25
27
  this.activeMobiusUrl = '';
26
28
  this.listenForWsEvents();
27
29
  }
28
- createCall = (destination, direction, deviceId) => {
30
+ createCall = (destination, direction, deviceId, lineId) => {
29
31
  log.log('Creating call object', {});
30
- const newCall = createCall(this.activeMobiusUrl, this.webex, destination, direction, deviceId, (correlationId) => {
32
+ const newCall = createCall(this.activeMobiusUrl, this.webex, destination, direction, deviceId, lineId, (correlationId) => {
31
33
  delete this.callCollection[correlationId];
32
34
  const activeCalls = Object.keys(this.getActiveCalls()).length;
33
35
  log.info(`DELETE:: Deleted corelationId: ${newCall.getCorrelationId()} from CallManager, Number of call records :- ${activeCalls}`, {});
34
36
  if (activeCalls === 0) {
35
- this.emit(EVENT_KEYS.ALL_CALLS_CLEARED);
37
+ this.emit(CALLING_CLIENT_EVENT_KEYS.ALL_CALLS_CLEARED);
36
38
  }
37
39
  }, this.serviceIndicator);
38
40
  this.callCollection[newCall.getCorrelationId()] = newCall;
@@ -75,7 +77,8 @@ export class CallManager extends Eventing {
75
77
  const newId = Object.keys(this.callCollection).find((id) => this.callCollection[id].getCallId() === callId);
76
78
  let newCall;
77
79
  if (!newId) {
78
- newCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId);
80
+ const lineId = this.getLineId(mobiusEvent.data.deviceId);
81
+ newCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId, lineId);
79
82
  log.log(`New incoming call created with correlationId from Call Setup message: ${newCall.getCorrelationId()}`, {
80
83
  file: CALL_MANAGER_FILE,
81
84
  method: 'dequeueWsEvents',
@@ -103,7 +106,7 @@ export class CallManager extends Eventing {
103
106
  });
104
107
  newCall.startCallerIdResolution(mobiusEvent.data.callerId);
105
108
  }
106
- this.emit(EVENT_KEYS.INCOMING_CALL, newCall);
109
+ this.emit(LINE_EVENT_KEYS.INCOMING_CALL, newCall);
107
110
  newCall.sendCallStateMachineEvt({ type: 'E_RECV_CALL_SETUP', data: mobiusEvent.data });
108
111
  break;
109
112
  }
@@ -135,7 +138,8 @@ export class CallManager extends Eventing {
135
138
  activeCall = this.getCall(newId);
136
139
  }
137
140
  else {
138
- activeCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId);
141
+ const lineId = this.getLineId(mobiusEvent.data.deviceId);
142
+ activeCall = this.createCall({}, CallDirection.INBOUND, mobiusEvent.data.deviceId, lineId);
139
143
  log.log(`New incoming call created with correlationId from ROAP Message: ${activeCall.getCorrelationId()}`, {
140
144
  file: CALL_MANAGER_FILE,
141
145
  method: 'dequeueWsEvents',
@@ -265,6 +269,12 @@ export class CallManager extends Eventing {
265
269
  getActiveCalls = () => {
266
270
  return this.callCollection;
267
271
  };
272
+ updateLine(deviceId, line) {
273
+ this.lineDict[deviceId] = line;
274
+ }
275
+ getLineId(deviceId) {
276
+ return this.lineDict[deviceId].lineId;
277
+ }
268
278
  }
269
279
  export const getCallManager = (webex, indicator) => {
270
280
  if (!callManager) {
@@ -1,12 +1,16 @@
1
1
  import { v4 as uuid } from 'uuid';
2
- import { MobiusStatus, ServiceIndicator } from '../../common/types';
3
- import { LINE_EVENTS } from './types';
4
- import { LINE_FILE } from '../constants';
2
+ import { CallDirection, MobiusStatus, ServiceIndicator, } from '../../common/types';
3
+ import { LINE_EVENTS, LineStatus } from './types';
4
+ import { LINE_FILE, VALID_PHONE } from '../constants';
5
5
  import log from '../../Logger';
6
6
  import { createRegistration } from '../registration';
7
7
  import { Eventing } from '../../Events/impl';
8
+ import { LineError } from '../../Errors/catalog/LineError';
8
9
  import { validateServiceData } from '../../common';
9
10
  import SDKConnector from '../../SDKConnector';
11
+ import { LINE_EVENT_KEYS } from '../../Events/types';
12
+ import { getCallManager } from '../calling/callManager';
13
+ import { ERROR_TYPE } from '../../Errors/types';
10
14
  export default class Line extends Eventing {
11
15
  #webex;
12
16
  #mutex;
@@ -29,6 +33,7 @@ export default class Line extends Eventing {
29
33
  rehomingIntervalMax;
30
34
  voicePortalNumber;
31
35
  voicePortalExtension;
36
+ callManager;
32
37
  #primaryMobiusUris;
33
38
  #backupMobiusUris;
34
39
  constructor(userId, clientDeviceUri, status, mutex, primaryMobiusUris, backupMobiusUris, logLevel, serviceDataConfig, phoneNumber, extension, voicemail) {
@@ -52,6 +57,8 @@ export default class Line extends Eventing {
52
57
  this.registration = createRegistration(this.#webex, serviceData, this.#mutex, this.lineEmitter, logLevel);
53
58
  this.registration.setStatus(MobiusStatus.DEFAULT);
54
59
  log.setLogger(logLevel, LINE_FILE);
60
+ this.callManager = getCallManager(this.#webex, serviceData.indicator);
61
+ this.incomingCallListener();
55
62
  }
56
63
  async register() {
57
64
  await this.#mutex.runExclusive(async () => {
@@ -60,6 +67,9 @@ export default class Line extends Eventing {
60
67
  this.registration.setMobiusServers(this.#primaryMobiusUris, this.#backupMobiusUris);
61
68
  await this.registration.triggerRegistration();
62
69
  });
70
+ if (this.mobiusDeviceId) {
71
+ this.callManager.updateLine(this.mobiusDeviceId, this);
72
+ }
63
73
  }
64
74
  async deregister() {
65
75
  this.registration.deregister();
@@ -107,4 +117,42 @@ export default class Line extends Eventing {
107
117
  }
108
118
  getRegistrationStatus = () => this.registration.getStatus();
109
119
  getDeviceId = () => this.registration.getDeviceInfo().device?.deviceId;
120
+ makeCall = (dest) => {
121
+ let call;
122
+ if (dest) {
123
+ const match = dest.address.match(VALID_PHONE);
124
+ if (match && match[0].length === dest.address.length) {
125
+ const sanitizedNumber = dest.address
126
+ .replace(/[^[*+]\d#]/gi, '')
127
+ .replace(/\s+/gi, '')
128
+ .replace(/-/gi, '');
129
+ const formattedDest = {
130
+ type: dest.type,
131
+ address: `tel:${sanitizedNumber}`,
132
+ };
133
+ call = this.callManager.createCall(formattedDest, CallDirection.OUTBOUND, this.registration.getDeviceInfo().device?.deviceId, this.lineId);
134
+ log.log(`New call created, callId: ${call.getCallId()}`, {});
135
+ }
136
+ else {
137
+ log.warn('Invalid phone number detected', {});
138
+ const err = new LineError('An invalid phone number was detected. Check the number and try again.', {}, ERROR_TYPE.CALL_ERROR, LineStatus.ACTIVE);
139
+ this.emit(LINE_EVENTS.ERROR, err);
140
+ }
141
+ return call;
142
+ }
143
+ return undefined;
144
+ };
145
+ incomingCallListener() {
146
+ const logContext = {
147
+ file: LINE_FILE,
148
+ method: this.incomingCallListener.name,
149
+ };
150
+ log.log('Listening for incoming calls... ', logContext);
151
+ this.callManager.on(LINE_EVENT_KEYS.INCOMING_CALL, (callObj) => {
152
+ this.emit(LINE_EVENTS.INCOMING_CALL, callObj);
153
+ });
154
+ }
155
+ getCall = (correlationId) => {
156
+ return this.callManager.getCall(correlationId);
157
+ };
110
158
  }
@@ -11,4 +11,5 @@ export var LINE_EVENTS;
11
11
  LINE_EVENTS["RECONNECTING"] = "reconnecting";
12
12
  LINE_EVENTS["REGISTERED"] = "registered";
13
13
  LINE_EVENTS["UNREGISTERED"] = "unregistered";
14
+ LINE_EVENTS["INCOMING_CALL"] = "line:incoming_call";
14
15
  })(LINE_EVENTS || (LINE_EVENTS = {}));
@@ -1,26 +1,35 @@
1
- export var EVENT_KEYS;
2
- (function (EVENT_KEYS) {
3
- EVENT_KEYS["ALERTING"] = "call:alerting";
4
- EVENT_KEYS["CALL_ERROR"] = "call:error";
5
- EVENT_KEYS["CALLER_ID"] = "call:caller_id";
6
- EVENT_KEYS["CONNECT"] = "call:connect";
7
- EVENT_KEYS["DISCONNECT"] = "call:disconnect";
8
- EVENT_KEYS["ERROR"] = "callingClient:error";
9
- EVENT_KEYS["ESTABLISHED"] = "call:established";
10
- EVENT_KEYS["HELD"] = "call:held";
11
- EVENT_KEYS["HOLD_ERROR"] = "call:hold_error";
12
- EVENT_KEYS["INCOMING_CALL"] = "callingClient:incoming_call";
13
- EVENT_KEYS["OUTGOING_CALL"] = "callingClient:outgoing_call";
14
- EVENT_KEYS["PROGRESS"] = "call:progress";
15
- EVENT_KEYS["REMOTE_MEDIA"] = "call:remote_media";
16
- EVENT_KEYS["RESUME_ERROR"] = "call:resume_error";
17
- EVENT_KEYS["RESUMED"] = "call:resumed";
18
- EVENT_KEYS["TRANSFER_ERROR"] = "call:transfer_error";
19
- EVENT_KEYS["USER_SESSION_INFO"] = "callingClient:user_recent_sessions";
20
- EVENT_KEYS["CB_VOICEMESSAGE_CONTENT_GET"] = "call_back_voicemail_content_get";
21
- EVENT_KEYS["CALL_HISTORY_USER_SESSION_INFO"] = "callHistory:user_recent_sessions";
22
- EVENT_KEYS["ALL_CALLS_CLEARED"] = "callingClient:all_calls_cleared";
23
- })(EVENT_KEYS || (EVENT_KEYS = {}));
1
+ export var COMMON_EVENT_KEYS;
2
+ (function (COMMON_EVENT_KEYS) {
3
+ COMMON_EVENT_KEYS["CB_VOICEMESSAGE_CONTENT_GET"] = "call_back_voicemail_content_get";
4
+ COMMON_EVENT_KEYS["CALL_HISTORY_USER_SESSION_INFO"] = "callHistory:user_recent_sessions";
5
+ })(COMMON_EVENT_KEYS || (COMMON_EVENT_KEYS = {}));
6
+ export var LINE_EVENT_KEYS;
7
+ (function (LINE_EVENT_KEYS) {
8
+ LINE_EVENT_KEYS["INCOMING_CALL"] = "incoming_call";
9
+ })(LINE_EVENT_KEYS || (LINE_EVENT_KEYS = {}));
10
+ export var CALLING_CLIENT_EVENT_KEYS;
11
+ (function (CALLING_CLIENT_EVENT_KEYS) {
12
+ CALLING_CLIENT_EVENT_KEYS["ERROR"] = "callingClient:error";
13
+ CALLING_CLIENT_EVENT_KEYS["OUTGOING_CALL"] = "callingClient:outgoing_call";
14
+ CALLING_CLIENT_EVENT_KEYS["USER_SESSION_INFO"] = "callingClient:user_recent_sessions";
15
+ CALLING_CLIENT_EVENT_KEYS["ALL_CALLS_CLEARED"] = "callingClient:all_calls_cleared";
16
+ })(CALLING_CLIENT_EVENT_KEYS || (CALLING_CLIENT_EVENT_KEYS = {}));
17
+ export var CALL_EVENT_KEYS;
18
+ (function (CALL_EVENT_KEYS) {
19
+ CALL_EVENT_KEYS["ALERTING"] = "alerting";
20
+ CALL_EVENT_KEYS["CALL_ERROR"] = "call_error";
21
+ CALL_EVENT_KEYS["CALLER_ID"] = "caller_id";
22
+ CALL_EVENT_KEYS["CONNECT"] = "connect";
23
+ CALL_EVENT_KEYS["DISCONNECT"] = "disconnect";
24
+ CALL_EVENT_KEYS["ESTABLISHED"] = "established";
25
+ CALL_EVENT_KEYS["HELD"] = "held";
26
+ CALL_EVENT_KEYS["HOLD_ERROR"] = "hold_error";
27
+ CALL_EVENT_KEYS["PROGRESS"] = "progress";
28
+ CALL_EVENT_KEYS["REMOTE_MEDIA"] = "remote_media";
29
+ CALL_EVENT_KEYS["RESUME_ERROR"] = "resume_error";
30
+ CALL_EVENT_KEYS["RESUMED"] = "resumed";
31
+ CALL_EVENT_KEYS["TRANSFER_ERROR"] = "transfer_error";
32
+ })(CALL_EVENT_KEYS || (CALL_EVENT_KEYS = {}));
24
33
  export var SUPPLEMENTARY_SERVICES;
25
34
  (function (SUPPLEMENTARY_SERVICES) {
26
35
  SUPPLEMENTARY_SERVICES["HOLD"] = "hold";
@@ -273,7 +273,9 @@ export class BroadworksBackendConnector {
273
273
  return responseDetails;
274
274
  }
275
275
  catch (err) {
276
- const errorInfo = err;
276
+ const errorInfo = {
277
+ statusCode: err instanceof Error ? Number(err.message) : '',
278
+ };
277
279
  const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
278
280
  return errorStatus;
279
281
  }
@@ -1,7 +1,7 @@
1
1
  import SDKConnector from '../SDKConnector';
2
2
  import { HTTP_METHODS, CALLING_BACKEND, } from '../common/types';
3
3
  import { getVgActionEndpoint, serviceErrorCodeHandler } from '../common/Utils';
4
- import { SUCCESS_MESSAGE, USERS, CONTENT, UCM_CONNECTOR_FILE } from '../common/constants';
4
+ import { SUCCESS_MESSAGE, USERS, CONTENT, UCM_CONNECTOR_FILE, FAILURE_MESSAGE, } from '../common/constants';
5
5
  import log from '../Logger';
6
6
  import { API_V1, LIMIT, OFFSET, SORT_ORDER, VMGATEWAY, VOICEMAILS } from './constants';
7
7
  export class UcmBackendConnector {
@@ -85,7 +85,7 @@ export class UcmBackendConnector {
85
85
  messageinfoArray.push(message);
86
86
  });
87
87
  const responseDetails = {
88
- statusCode: response.statusCode,
88
+ statusCode: Number(response.statusCode),
89
89
  data: {
90
90
  voicemailList: messageinfoArray,
91
91
  },
@@ -163,10 +163,11 @@ export class UcmBackendConnector {
163
163
  });
164
164
  const contentInfo = response?.body;
165
165
  const respHeaders = response.headers;
166
+ const statusCode = response.statusCode;
166
167
  const mediaType = respHeaders?.mediatype;
167
168
  const mediaContent = contentInfo;
168
169
  const responseDetails = {
169
- statusCode: response.statusCode,
170
+ statusCode: Number(statusCode),
170
171
  data: {
171
172
  voicemailContent: {
172
173
  type: mediaType,
@@ -175,6 +176,9 @@ export class UcmBackendConnector {
175
176
  },
176
177
  message: SUCCESS_MESSAGE,
177
178
  };
179
+ if (statusCode !== 200 && statusCode !== 202) {
180
+ responseDetails.message = FAILURE_MESSAGE;
181
+ }
178
182
  return responseDetails;
179
183
  }
180
184
  async voicemailMarkAsRead(messageId) {
@@ -195,7 +199,7 @@ export class UcmBackendConnector {
195
199
  },
196
200
  });
197
201
  const responseDetails = {
198
- statusCode: response.statusCode,
202
+ statusCode: Number(response.statusCode),
199
203
  data: {},
200
204
  message: SUCCESS_MESSAGE,
201
205
  };
@@ -225,7 +229,7 @@ export class UcmBackendConnector {
225
229
  },
226
230
  });
227
231
  const responseDetails = {
228
- statusCode: response.statusCode,
232
+ statusCode: Number(response.statusCode),
229
233
  data: {},
230
234
  message: SUCCESS_MESSAGE,
231
235
  };
@@ -252,7 +256,7 @@ export class UcmBackendConnector {
252
256
  },
253
257
  });
254
258
  const responseDetails = {
255
- statusCode: response.statusCode,
259
+ statusCode: Number(response.statusCode),
256
260
  data: {},
257
261
  message: SUCCESS_MESSAGE,
258
262
  };
@@ -114,7 +114,7 @@ export class WxCallBackendConnector {
114
114
  const mediaContent = mediaDetails.childNodes[2]?.textContent;
115
115
  log.info(`Media type is ${mediaType}`, loggerContext);
116
116
  const responseDetails = {
117
- statusCode: response.statusCode,
117
+ statusCode: Number(response.statusCode),
118
118
  data: {
119
119
  voicemailContent: {
120
120
  type: mediaType,
@@ -183,7 +183,7 @@ export class WxCallBackendConnector {
183
183
  method: HTTP_METHODS.PUT,
184
184
  });
185
185
  const responseDetails = {
186
- statusCode: response.statusCode,
186
+ statusCode: Number(response.statusCode),
187
187
  data: {},
188
188
  message: SUCCESS_MESSAGE,
189
189
  };
@@ -207,7 +207,7 @@ export class WxCallBackendConnector {
207
207
  method: HTTP_METHODS.PUT,
208
208
  });
209
209
  const responseDetails = {
210
- statusCode: response.statusCode,
210
+ statusCode: Number(response.statusCode),
211
211
  data: {},
212
212
  message: SUCCESS_MESSAGE,
213
213
  };
@@ -231,7 +231,7 @@ export class WxCallBackendConnector {
231
231
  method: HTTP_METHODS.DELETE,
232
232
  });
233
233
  const responseDetails = {
234
- statusCode: response.statusCode,
234
+ statusCode: Number(response.statusCode),
235
235
  data: {},
236
236
  message: SUCCESS_MESSAGE,
237
237
  };
@@ -259,7 +259,7 @@ export class WxCallBackendConnector {
259
259
  const status = xmlDOM.getElementsByTagName(TRANSCRIPT_STATUS)[0];
260
260
  const transcript = xmlDOM.getElementsByTagName(TRANSCRIPT_CONTENT)[0];
261
261
  const responseDetails = {
262
- statusCode: response.statusCode,
262
+ statusCode: Number(response.statusCode),
263
263
  data: {
264
264
  voicemailTranscript: transcript?.textContent,
265
265
  },
@@ -1,3 +1,4 @@
1
+ import { FAILURE_MESSAGE, UNPROCESSABLE_CONTENT_CODE } from '../common/constants';
1
2
  export const bwToken = 'bwtoken';
2
3
  export const broadworksTokenType = {
3
4
  body: {
@@ -259,6 +260,38 @@ const MOCK_VOICEMAIL_FIFTH_MESSAGE = {
259
260
  $: `${braodworksUserMessageInfo}/aa237e9e-211a-4a0a-bb58-2a931eca061d`,
260
261
  },
261
262
  };
263
+ export const getEmptyVoicemailListJsonBWRKS = {
264
+ statusCode: 200,
265
+ VoiceMessagingMessages: {
266
+ messageInfoList: {},
267
+ },
268
+ };
269
+ export const getInvalidVoicemailListJsonBWRKS = {
270
+ statusCode: 200,
271
+ VoiceMessagingMessages: {
272
+ messageInfoList: {
273
+ messageInfo: {},
274
+ },
275
+ },
276
+ };
277
+ export const getEmptyVoicemailListJsonWxC = {
278
+ statusCode: 200,
279
+ body: {
280
+ VoiceMessagingMessages: {
281
+ messageInfoList: {},
282
+ },
283
+ },
284
+ };
285
+ export const getInvalidVoicemailListJsonWxC = {
286
+ statusCode: 200,
287
+ body: {
288
+ VoiceMessagingMessages: {
289
+ messageInfoList: {
290
+ messageInfo: {},
291
+ },
292
+ },
293
+ },
294
+ };
262
295
  export const getVoicemailListJsonBWRKS = {
263
296
  statusCode: 200,
264
297
  VoiceMessagingMessages: {
@@ -381,6 +414,20 @@ export const mockUCMVoicemailBody = {
381
414
  items: [MOCK_UCM_VOICEMAIL_FIRST_MESSAGE],
382
415
  },
383
416
  };
417
+ export const mockVoicemailContentResponse = {
418
+ statusCode: 200,
419
+ headers: {
420
+ mediatype: 'audio/wav',
421
+ },
422
+ body: voicemailContent,
423
+ };
424
+ export const voicemailEventProcessingPayload = {
425
+ data: {
426
+ messageId: '1234567890',
427
+ eventType: 'processing',
428
+ status: 'waiting',
429
+ },
430
+ };
384
431
  export const getVoiceMailListJsonUCM = {
385
432
  statusCode: 200,
386
433
  body: {
@@ -407,6 +454,20 @@ export const getDescVoiceMailListJsonUCM = {
407
454
  },
408
455
  },
409
456
  };
457
+ export const responseDetails422 = {
458
+ data: { error: '422 Exception has occurred' },
459
+ message: FAILURE_MESSAGE,
460
+ statusCode: UNPROCESSABLE_CONTENT_CODE,
461
+ };
462
+ export const responseDetails204 = {
463
+ data: { error: '204 Exception has occurred' },
464
+ message: FAILURE_MESSAGE,
465
+ statusCode: 204,
466
+ };
467
+ export const resolveContactArgs = {
468
+ name: { $: 'test' },
469
+ address: { $: 'test address' },
470
+ };
410
471
  export const mockVoicemailTranscriptResponse = {
411
472
  body: '<?xml version="1.0" encoding="UTF-8"?>\n<VoiceMessageTranscript xmlns="http://schema.broadsoft.com/xsi"><status>READY</status><content lang="EN">Hi, uh, testing, voice mail script, so dropping this message to be able to fetch it later.</content></VoiceMessageTranscript>',
412
473
  statusCode: 200,
@@ -79,7 +79,7 @@ export function emitFinalFailure(emitterCb, loggerContext) {
79
79
  }
80
80
  export async function handleRegistrationErrors(err, emitterCb, loggerContext, restoreRegCb) {
81
81
  const lineError = createLineError('', {}, ERROR_TYPE.DEFAULT, LineStatus.INACTIVE);
82
- const errorCode = err.statusCode;
82
+ const errorCode = Number(err.statusCode);
83
83
  let finalError = false;
84
84
  log.warn(`Status code: -> ${errorCode}`, loggerContext);
85
85
  switch (errorCode) {
@@ -111,7 +111,7 @@ export async function handleRegistrationErrors(err, emitterCb, loggerContext, re
111
111
  emitterCb(lineError, finalError);
112
112
  return finalError;
113
113
  }
114
- const code = errorBody.errorCode;
114
+ const code = Number(errorBody.errorCode);
115
115
  log.warn(`Error code found : ${code}`, loggerContext);
116
116
  switch (code) {
117
117
  case DEVICE_ERROR_CODE.DEVICE_LIMIT_EXCEEDED: {
@@ -164,7 +164,7 @@ export async function handleRegistrationErrors(err, emitterCb, loggerContext, re
164
164
  }
165
165
  export async function handleCallingClientErrors(err, emitterCb, loggerContext) {
166
166
  const clientError = createClientError('', {}, ERROR_TYPE.DEFAULT, MobiusStatus.DEFAULT);
167
- const errorCode = err.statusCode;
167
+ const errorCode = Number(err.statusCode);
168
168
  const finalError = false;
169
169
  log.warn(`Status code: -> ${errorCode}`, loggerContext);
170
170
  switch (errorCode) {
@@ -188,7 +188,7 @@ export async function handleCallErrors(emitterCb, errorLayer, retryCb, correlati
188
188
  method: caller,
189
189
  };
190
190
  const callError = createCallError('', loggerContext, ERROR_TYPE.DEFAULT, '', errorLayer);
191
- const errorCode = err.statusCode;
191
+ const errorCode = Number(err.statusCode);
192
192
  log.warn(`Status code: ->${errorCode}`, loggerContext);
193
193
  switch (errorCode) {
194
194
  case ERROR_CODE.UNAUTHORIZED: {
@@ -209,12 +209,12 @@ export async function handleCallErrors(emitterCb, errorLayer, retryCb, correlati
209
209
  return;
210
210
  }
211
211
  if (err.headers && 'retry-after' in err.headers && retryCb) {
212
- const retryInterval = err.headers['retry-after'];
212
+ const retryInterval = Number(err.headers['retry-after']);
213
213
  log.warn(`Retry Interval received: ${retryInterval}`, loggerContext);
214
214
  retryCb(retryInterval);
215
215
  return;
216
216
  }
217
- const code = errorBody.errorCode;
217
+ const code = Number(errorBody.errorCode);
218
218
  let message;
219
219
  switch (code) {
220
220
  case CALL_ERROR_CODE.INVALID_STATUS_UPDATE: {
@@ -286,7 +286,7 @@ export async function handleCallErrors(emitterCb, errorLayer, retryCb, correlati
286
286
  }
287
287
  }
288
288
  export async function serviceErrorCodeHandler(err, loggerContext) {
289
- const errorCode = err.statusCode;
289
+ const errorCode = Number(err.statusCode);
290
290
  const failureMessage = 'FAILURE';
291
291
  switch (errorCode) {
292
292
  case ERROR_CODE.BAD_REQUEST: {
@@ -378,11 +378,11 @@ export async function serviceErrorCodeHandler(err, loggerContext) {
378
378
  return errorDetails;
379
379
  }
380
380
  default: {
381
- log.warn(`422 Exception has occurred`, loggerContext);
381
+ log.warn(`${errorCode || 422} Exception has occurred`, loggerContext);
382
382
  const errorDetails = {
383
- statusCode: 422,
383
+ statusCode: errorCode || 422,
384
384
  data: {
385
- error: '422 Exception has occurred',
385
+ error: `${errorCode || 422} Exception has occurred`,
386
386
  },
387
387
  message: failureMessage,
388
388
  };
@@ -16,6 +16,7 @@ export const SETTINGS = 'settings';
16
16
  export const STATUS_CODE = 'statusCode';
17
17
  export const SUCCESS_MESSAGE = 'SUCCESS';
18
18
  export const SUCCESS_STATUS_CODE = 200;
19
+ export const UNPROCESSABLE_CONTENT_CODE = 422;
19
20
  export const TIME = 'time';
20
21
  export const TOKEN = 'token';
21
22
  export const TRANSCRIPT = 'transcript';
package/package.json CHANGED
@@ -129,5 +129,5 @@
129
129
  "staticpath": "docs",
130
130
  "noprompt": true
131
131
  },
132
- "version": "0.0.1-next.5"
132
+ "version": "0.0.1-next.7"
133
133
  }