@webex/calling 0.0.1-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/README.md +67 -0
  2. package/dist/module/CallHistory/CallHistory.js +84 -0
  3. package/dist/module/CallHistory/callHistoryFixtures.js +307 -0
  4. package/dist/module/CallHistory/constants.js +9 -0
  5. package/dist/module/CallHistory/types.js +1 -0
  6. package/dist/module/CallSettings/CallSettings.js +65 -0
  7. package/dist/module/CallSettings/UcmBackendConnector.js +100 -0
  8. package/dist/module/CallSettings/WxCallBackendConnector.js +287 -0
  9. package/dist/module/CallSettings/constants.js +11 -0
  10. package/dist/module/CallSettings/testFixtures.js +62 -0
  11. package/dist/module/CallSettings/types.js +1 -0
  12. package/dist/module/CallingClient/CallingClient.js +268 -0
  13. package/dist/module/CallingClient/callRecordFixtures.js +93 -0
  14. package/dist/module/CallingClient/calling/CallerId/index.js +169 -0
  15. package/dist/module/CallingClient/calling/CallerId/types.js +1 -0
  16. package/dist/module/CallingClient/calling/call.js +1649 -0
  17. package/dist/module/CallingClient/calling/callManager.js +274 -0
  18. package/dist/module/CallingClient/calling/index.js +2 -0
  19. package/dist/module/CallingClient/calling/types.js +53 -0
  20. package/dist/module/CallingClient/callingClientFixtures.js +38 -0
  21. package/dist/module/CallingClient/constants.js +122 -0
  22. package/dist/module/CallingClient/line/index.js +110 -0
  23. package/dist/module/CallingClient/line/types.js +14 -0
  24. package/dist/module/CallingClient/registration/index.js +1 -0
  25. package/dist/module/CallingClient/registration/register.js +507 -0
  26. package/dist/module/CallingClient/registration/registerFixtures.js +28 -0
  27. package/dist/module/CallingClient/registration/types.js +1 -0
  28. package/dist/module/CallingClient/types.js +1 -0
  29. package/dist/module/Contacts/ContactsClient.js +487 -0
  30. package/dist/module/Contacts/constants.js +20 -0
  31. package/dist/module/Contacts/contactFixtures.js +284 -0
  32. package/dist/module/Contacts/types.js +10 -0
  33. package/dist/module/Errors/catalog/CallError.js +26 -0
  34. package/dist/module/Errors/catalog/CallingDeviceError.js +18 -0
  35. package/dist/module/Errors/catalog/ExtendedError.js +10 -0
  36. package/dist/module/Errors/catalog/LineError.js +24 -0
  37. package/dist/module/Errors/index.js +2 -0
  38. package/dist/module/Errors/types.js +48 -0
  39. package/dist/module/Events/impl/index.js +19 -0
  40. package/dist/module/Events/types.js +74 -0
  41. package/dist/module/Logger/index.js +114 -0
  42. package/dist/module/Logger/types.js +25 -0
  43. package/dist/module/Metrics/index.js +232 -0
  44. package/dist/module/Metrics/types.js +37 -0
  45. package/dist/module/SDKConnector/index.js +39 -0
  46. package/dist/module/SDKConnector/types.js +1 -0
  47. package/dist/module/SDKConnector/utils.js +12 -0
  48. package/dist/module/Voicemail/BroadworksBackendConnector.js +289 -0
  49. package/dist/module/Voicemail/UcmBackendConnector.js +275 -0
  50. package/dist/module/Voicemail/Voicemail.js +110 -0
  51. package/dist/module/Voicemail/WxCallBackendConnector.js +279 -0
  52. package/dist/module/Voicemail/constants.js +29 -0
  53. package/dist/module/Voicemail/types.js +1 -0
  54. package/dist/module/Voicemail/voicemailFixture.js +449 -0
  55. package/dist/module/common/Utils.js +802 -0
  56. package/dist/module/common/constants.js +40 -0
  57. package/dist/module/common/index.js +1 -0
  58. package/dist/module/common/testUtil.js +938 -0
  59. package/dist/module/common/types.js +57 -0
  60. package/dist/module/index.js +8 -0
  61. package/dist/types/CallHistory/CallHistory.d.ts +19 -0
  62. package/dist/types/CallHistory/CallHistory.d.ts.map +1 -0
  63. package/dist/types/CallHistory/callHistoryFixtures.d.ts +95 -0
  64. package/dist/types/CallHistory/callHistoryFixtures.d.ts.map +1 -0
  65. package/dist/types/CallHistory/constants.d.ts +10 -0
  66. package/dist/types/CallHistory/constants.d.ts.map +1 -0
  67. package/dist/types/CallHistory/types.d.ts +21 -0
  68. package/dist/types/CallHistory/types.d.ts.map +1 -0
  69. package/dist/types/CallSettings/CallSettings.d.ts +20 -0
  70. package/dist/types/CallSettings/CallSettings.d.ts.map +1 -0
  71. package/dist/types/CallSettings/UcmBackendConnector.d.ts +20 -0
  72. package/dist/types/CallSettings/UcmBackendConnector.d.ts.map +1 -0
  73. package/dist/types/CallSettings/WxCallBackendConnector.d.ts +22 -0
  74. package/dist/types/CallSettings/WxCallBackendConnector.d.ts.map +1 -0
  75. package/dist/types/CallSettings/constants.d.ts +12 -0
  76. package/dist/types/CallSettings/constants.d.ts.map +1 -0
  77. package/dist/types/CallSettings/testFixtures.d.ts +16 -0
  78. package/dist/types/CallSettings/testFixtures.d.ts.map +1 -0
  79. package/dist/types/CallSettings/types.d.ts +108 -0
  80. package/dist/types/CallSettings/types.d.ts.map +1 -0
  81. package/dist/types/CallingClient/CallingClient.d.ts +38 -0
  82. package/dist/types/CallingClient/CallingClient.d.ts.map +1 -0
  83. package/dist/types/CallingClient/callRecordFixtures.d.ts +4 -0
  84. package/dist/types/CallingClient/callRecordFixtures.d.ts.map +1 -0
  85. package/dist/types/CallingClient/calling/CallerId/index.d.ts +18 -0
  86. package/dist/types/CallingClient/calling/CallerId/index.d.ts.map +1 -0
  87. package/dist/types/CallingClient/calling/CallerId/types.d.ts +42 -0
  88. package/dist/types/CallingClient/calling/CallerId/types.d.ts.map +1 -0
  89. package/dist/types/CallingClient/calling/call.d.ts +95 -0
  90. package/dist/types/CallingClient/calling/call.d.ts.map +1 -0
  91. package/dist/types/CallingClient/calling/callManager.d.ts +22 -0
  92. package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -0
  93. package/dist/types/CallingClient/calling/index.d.ts +3 -0
  94. package/dist/types/CallingClient/calling/index.d.ts.map +1 -0
  95. package/dist/types/CallingClient/calling/types.d.ts +204 -0
  96. package/dist/types/CallingClient/calling/types.d.ts.map +1 -0
  97. package/dist/types/CallingClient/callingClientFixtures.d.ts +19 -0
  98. package/dist/types/CallingClient/callingClientFixtures.d.ts.map +1 -0
  99. package/dist/types/CallingClient/constants.d.ts +123 -0
  100. package/dist/types/CallingClient/constants.d.ts.map +1 -0
  101. package/dist/types/CallingClient/line/index.d.ts +39 -0
  102. package/dist/types/CallingClient/line/index.d.ts.map +1 -0
  103. package/dist/types/CallingClient/line/types.d.ts +51 -0
  104. package/dist/types/CallingClient/line/types.d.ts.map +1 -0
  105. package/dist/types/CallingClient/registration/index.d.ts +2 -0
  106. package/dist/types/CallingClient/registration/index.d.ts.map +1 -0
  107. package/dist/types/CallingClient/registration/register.d.ts +65 -0
  108. package/dist/types/CallingClient/registration/register.d.ts.map +1 -0
  109. package/dist/types/CallingClient/registration/registerFixtures.d.ts +29 -0
  110. package/dist/types/CallingClient/registration/registerFixtures.d.ts.map +1 -0
  111. package/dist/types/CallingClient/registration/types.d.ts +21 -0
  112. package/dist/types/CallingClient/registration/types.d.ts.map +1 -0
  113. package/dist/types/CallingClient/types.d.ts +30 -0
  114. package/dist/types/CallingClient/types.d.ts.map +1 -0
  115. package/dist/types/Contacts/ContactsClient.d.ts +28 -0
  116. package/dist/types/Contacts/ContactsClient.d.ts.map +1 -0
  117. package/dist/types/Contacts/constants.d.ts +20 -0
  118. package/dist/types/Contacts/constants.d.ts.map +1 -0
  119. package/dist/types/Contacts/contactFixtures.d.ts +281 -0
  120. package/dist/types/Contacts/contactFixtures.d.ts.map +1 -0
  121. package/dist/types/Contacts/types.d.ts +75 -0
  122. package/dist/types/Contacts/types.d.ts.map +1 -0
  123. package/dist/types/Errors/catalog/CallError.d.ts +12 -0
  124. package/dist/types/Errors/catalog/CallError.d.ts.map +1 -0
  125. package/dist/types/Errors/catalog/CallingDeviceError.d.ts +11 -0
  126. package/dist/types/Errors/catalog/CallingDeviceError.d.ts.map +1 -0
  127. package/dist/types/Errors/catalog/ExtendedError.d.ts +7 -0
  128. package/dist/types/Errors/catalog/ExtendedError.d.ts.map +1 -0
  129. package/dist/types/Errors/catalog/LineError.d.ts +11 -0
  130. package/dist/types/Errors/catalog/LineError.d.ts.map +1 -0
  131. package/dist/types/Errors/index.d.ts +3 -0
  132. package/dist/types/Errors/index.d.ts.map +1 -0
  133. package/dist/types/Errors/types.d.ts +61 -0
  134. package/dist/types/Errors/types.d.ts.map +1 -0
  135. package/dist/types/Events/impl/index.d.ts +9 -0
  136. package/dist/types/Events/impl/index.d.ts.map +1 -0
  137. package/dist/types/Events/types.d.ts +284 -0
  138. package/dist/types/Events/types.d.ts.map +1 -0
  139. package/dist/types/Logger/index.d.ts +13 -0
  140. package/dist/types/Logger/index.d.ts.map +1 -0
  141. package/dist/types/Logger/types.d.ts +26 -0
  142. package/dist/types/Logger/types.d.ts.map +1 -0
  143. package/dist/types/Metrics/index.d.ts +6 -0
  144. package/dist/types/Metrics/index.d.ts.map +1 -0
  145. package/dist/types/Metrics/types.d.ts +43 -0
  146. package/dist/types/Metrics/types.d.ts.map +1 -0
  147. package/dist/types/SDKConnector/index.d.ts +13 -0
  148. package/dist/types/SDKConnector/index.d.ts.map +1 -0
  149. package/dist/types/SDKConnector/types.d.ts +129 -0
  150. package/dist/types/SDKConnector/types.d.ts.map +1 -0
  151. package/dist/types/SDKConnector/utils.d.ts +6 -0
  152. package/dist/types/SDKConnector/utils.d.ts.map +1 -0
  153. package/dist/types/Voicemail/BroadworksBackendConnector.d.ts +28 -0
  154. package/dist/types/Voicemail/BroadworksBackendConnector.d.ts.map +1 -0
  155. package/dist/types/Voicemail/UcmBackendConnector.d.ts +35 -0
  156. package/dist/types/Voicemail/UcmBackendConnector.d.ts.map +1 -0
  157. package/dist/types/Voicemail/Voicemail.d.ts +28 -0
  158. package/dist/types/Voicemail/Voicemail.d.ts.map +1 -0
  159. package/dist/types/Voicemail/WxCallBackendConnector.d.ts +24 -0
  160. package/dist/types/Voicemail/WxCallBackendConnector.d.ts.map +1 -0
  161. package/dist/types/Voicemail/constants.d.ts +30 -0
  162. package/dist/types/Voicemail/constants.d.ts.map +1 -0
  163. package/dist/types/Voicemail/types.d.ts +134 -0
  164. package/dist/types/Voicemail/types.d.ts.map +1 -0
  165. package/dist/types/Voicemail/voicemailFixture.d.ts +350 -0
  166. package/dist/types/Voicemail/voicemailFixture.d.ts.map +1 -0
  167. package/dist/types/common/Utils.d.ts +35 -0
  168. package/dist/types/common/Utils.d.ts.map +1 -0
  169. package/dist/types/common/constants.d.ts +41 -0
  170. package/dist/types/common/constants.d.ts.map +1 -0
  171. package/dist/types/common/index.d.ts +2 -0
  172. package/dist/types/common/index.d.ts.map +1 -0
  173. package/dist/types/common/testUtil.d.ts +3612 -0
  174. package/dist/types/common/testUtil.d.ts.map +1 -0
  175. package/dist/types/common/types.d.ts +192 -0
  176. package/dist/types/common/types.d.ts.map +1 -0
  177. package/dist/types/index.d.ts +9 -0
  178. package/dist/types/index.d.ts.map +1 -0
  179. package/package.json +161 -0
@@ -0,0 +1,287 @@
1
+ import SDKConnector from '../SDKConnector';
2
+ import log from '../Logger';
3
+ import { HTTP_METHODS, DecodeType, CALLING_BACKEND } from '../common/types';
4
+ import { SERVICES_ENDPOINT, STATUS_CODE, SUCCESS_MESSAGE, XML_TYPE, WEBEX_CALLING_CONNECTOR_FILE, } from '../common/constants';
5
+ import { CALL_SETTINGS_FILE, CALL_WAITING_ENDPOINT, CF_ENDPOINT, DND_ENDPOINT, ORG_ENDPOINT, PEOPLE_ENDPOINT, USER_ENDPOINT, VM_ENDPOINT, XSI_VERSION, } from './constants';
6
+ import { getXsiActionEndpoint, inferIdFromUuid, serviceErrorCodeHandler } from '../common/Utils';
7
+ export class WxCallBackendConnector {
8
+ sdkConnector;
9
+ webex;
10
+ userId;
11
+ personId;
12
+ orgId;
13
+ xsiEndpoint;
14
+ hydraEndpoint;
15
+ VOICEMAIL = 'VOICEMAIL';
16
+ constructor(webex, logger) {
17
+ this.sdkConnector = SDKConnector;
18
+ if (!this.sdkConnector.getWebex()) {
19
+ SDKConnector.setWebex(webex);
20
+ }
21
+ this.webex = this.sdkConnector.getWebex();
22
+ this.hydraEndpoint = this.webex.internal.services._serviceUrls.hydra;
23
+ log.setLogger(logger.level, WEBEX_CALLING_CONNECTOR_FILE);
24
+ this.userId = this.webex.internal.device.userId;
25
+ this.personId = inferIdFromUuid(this.webex.internal.device.userId, DecodeType.PEOPLE);
26
+ this.orgId = inferIdFromUuid(this.webex.internal.device.orgId, DecodeType.ORGANIZATION);
27
+ }
28
+ async getCallWaitingSetting() {
29
+ const loggerContext = {
30
+ file: CALL_SETTINGS_FILE,
31
+ method: 'getCallWaitingSetting',
32
+ };
33
+ try {
34
+ if (!this.xsiEndpoint) {
35
+ this.xsiEndpoint = await getXsiActionEndpoint(this.webex, loggerContext, CALLING_BACKEND.WXC);
36
+ log.info(`xsiEndpoint: ${this.xsiEndpoint}`, loggerContext);
37
+ }
38
+ const callWaitingUrl = `${this.xsiEndpoint}/${XSI_VERSION}/${USER_ENDPOINT}/${this.userId}/${SERVICES_ENDPOINT}/${CALL_WAITING_ENDPOINT}`;
39
+ const response = await fetch(`${callWaitingUrl}`, {
40
+ method: HTTP_METHODS.GET,
41
+ headers: {
42
+ Authorization: await this.webex.credentials.getUserToken(),
43
+ },
44
+ });
45
+ if (!response.ok) {
46
+ throw new Error(`${response.status}`);
47
+ }
48
+ const xmlData = await response.text();
49
+ const parser = new DOMParser();
50
+ const xmlDOM = parser.parseFromString(xmlData, XML_TYPE);
51
+ const callWaitingDetails = xmlDOM.getElementsByTagName('active');
52
+ const status = callWaitingDetails[0].childNodes[0].textContent;
53
+ const toggleSetting = {
54
+ enabled: status === 'true',
55
+ };
56
+ const responseDetails = {
57
+ statusCode: 200,
58
+ data: {
59
+ callSetting: toggleSetting,
60
+ },
61
+ message: SUCCESS_MESSAGE,
62
+ };
63
+ return responseDetails;
64
+ }
65
+ catch (err) {
66
+ const errorInfo = {
67
+ statusCode: err instanceof Error ? Number(err.message) : '',
68
+ };
69
+ const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
70
+ return errorStatus;
71
+ }
72
+ }
73
+ async getDoNotDisturbSetting() {
74
+ const loggerContext = {
75
+ file: CALL_SETTINGS_FILE,
76
+ method: 'getDoNotDisturbSetting',
77
+ };
78
+ try {
79
+ const resp = await this.webex.request({
80
+ uri: `${this.hydraEndpoint}/${PEOPLE_ENDPOINT}/${this.personId}/${DND_ENDPOINT}?${ORG_ENDPOINT}=${this.orgId}`,
81
+ method: HTTP_METHODS.GET,
82
+ });
83
+ const dndSettingResponse = resp.body;
84
+ const responseDetails = {
85
+ statusCode: Number(resp[STATUS_CODE]),
86
+ data: {
87
+ callSetting: dndSettingResponse,
88
+ },
89
+ message: SUCCESS_MESSAGE,
90
+ };
91
+ return responseDetails;
92
+ }
93
+ catch (err) {
94
+ const errorInfo = err;
95
+ const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
96
+ return errorStatus;
97
+ }
98
+ }
99
+ async setDoNotDisturbSetting(enabled) {
100
+ const loggerContext = {
101
+ file: CALL_SETTINGS_FILE,
102
+ method: 'setDoNotDisturbSetting',
103
+ };
104
+ try {
105
+ const dndRequestBody = {
106
+ enabled,
107
+ ringSplashEnabled: false,
108
+ };
109
+ const resp = await this.webex.request({
110
+ uri: `${this.hydraEndpoint}/${PEOPLE_ENDPOINT}/${this.personId}/${DND_ENDPOINT}?${ORG_ENDPOINT}=${this.orgId}`,
111
+ method: HTTP_METHODS.PUT,
112
+ body: dndRequestBody,
113
+ });
114
+ const responseDetails = {
115
+ statusCode: Number(resp[STATUS_CODE]),
116
+ data: {
117
+ callSetting: dndRequestBody,
118
+ },
119
+ message: SUCCESS_MESSAGE,
120
+ };
121
+ return responseDetails;
122
+ }
123
+ catch (err) {
124
+ const errorInfo = err;
125
+ const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
126
+ return errorStatus;
127
+ }
128
+ }
129
+ async getCallForwardSetting() {
130
+ const loggerContext = {
131
+ file: CALL_SETTINGS_FILE,
132
+ method: 'getCallForwardingSetting',
133
+ };
134
+ try {
135
+ const resp = await this.webex.request({
136
+ uri: `${this.hydraEndpoint}/${PEOPLE_ENDPOINT}/${this.personId}/${CF_ENDPOINT}?${ORG_ENDPOINT}=${this.orgId}`,
137
+ method: HTTP_METHODS.GET,
138
+ });
139
+ const cfResponse = resp.body;
140
+ const responseDetails = {
141
+ statusCode: Number(resp[STATUS_CODE]),
142
+ data: {
143
+ callSetting: cfResponse,
144
+ },
145
+ message: SUCCESS_MESSAGE,
146
+ };
147
+ return responseDetails;
148
+ }
149
+ catch (err) {
150
+ const errorInfo = err;
151
+ const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
152
+ return errorStatus;
153
+ }
154
+ }
155
+ async setCallForwardSetting(callForwardingRequest) {
156
+ const loggerContext = {
157
+ file: CALL_SETTINGS_FILE,
158
+ method: 'setCallForwardingSetting',
159
+ };
160
+ try {
161
+ const resp = await this.webex.request({
162
+ uri: `${this.hydraEndpoint}/${PEOPLE_ENDPOINT}/${this.personId}/${CF_ENDPOINT}?${ORG_ENDPOINT}=${this.orgId}`,
163
+ method: HTTP_METHODS.PUT,
164
+ body: callForwardingRequest,
165
+ });
166
+ const responseDetails = {
167
+ statusCode: Number(resp[STATUS_CODE]),
168
+ data: {
169
+ callSetting: callForwardingRequest,
170
+ },
171
+ message: SUCCESS_MESSAGE,
172
+ };
173
+ return responseDetails;
174
+ }
175
+ catch (err) {
176
+ const errorInfo = err;
177
+ const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
178
+ return errorStatus;
179
+ }
180
+ }
181
+ async getVoicemailSetting() {
182
+ const loggerContext = {
183
+ file: CALL_SETTINGS_FILE,
184
+ method: 'getVoicemailSetting',
185
+ };
186
+ try {
187
+ const resp = await this.webex.request({
188
+ uri: `${this.hydraEndpoint}/${PEOPLE_ENDPOINT}/${this.personId}/${VM_ENDPOINT}?${ORG_ENDPOINT}=${this.orgId}`,
189
+ method: HTTP_METHODS.GET,
190
+ });
191
+ const vmResponse = resp.body;
192
+ const responseDetails = {
193
+ statusCode: Number(resp[STATUS_CODE]),
194
+ data: {
195
+ callSetting: vmResponse,
196
+ },
197
+ message: SUCCESS_MESSAGE,
198
+ };
199
+ return responseDetails;
200
+ }
201
+ catch (err) {
202
+ const errorInfo = err;
203
+ const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
204
+ return errorStatus;
205
+ }
206
+ }
207
+ async setVoicemailSetting(voicemailRequest) {
208
+ const loggerContext = {
209
+ file: CALL_SETTINGS_FILE,
210
+ method: 'setVoicemailSetting',
211
+ };
212
+ try {
213
+ const resp = await this.webex.request({
214
+ uri: `${this.hydraEndpoint}/${PEOPLE_ENDPOINT}/${this.personId}/${VM_ENDPOINT}?${ORG_ENDPOINT}=${this.orgId}`,
215
+ method: HTTP_METHODS.PUT,
216
+ body: voicemailRequest,
217
+ });
218
+ const responseDetails = {
219
+ statusCode: Number(resp[STATUS_CODE]),
220
+ data: {
221
+ callSetting: voicemailRequest,
222
+ },
223
+ message: SUCCESS_MESSAGE,
224
+ };
225
+ return responseDetails;
226
+ }
227
+ catch (err) {
228
+ const errorInfo = err;
229
+ const errorStatus = serviceErrorCodeHandler(errorInfo, loggerContext);
230
+ return errorStatus;
231
+ }
232
+ }
233
+ async getCallForwardAlwaysSetting() {
234
+ const loggerContext = {
235
+ file: WEBEX_CALLING_CONNECTOR_FILE,
236
+ method: this.getCallForwardAlwaysSetting.name,
237
+ };
238
+ const cfResponse = await this.getCallForwardSetting();
239
+ if (cfResponse.statusCode === 200) {
240
+ const cfa = cfResponse.data.callSetting.callForwarding.always;
241
+ if (cfa.enabled) {
242
+ if (cfa.destination) {
243
+ const response = {
244
+ ...cfResponse,
245
+ data: {
246
+ callSetting: cfa,
247
+ },
248
+ };
249
+ return response;
250
+ }
251
+ log.warn(`CFA is enabled, but destination is not set`, loggerContext);
252
+ }
253
+ const vmResponse = await this.getVoicemailSetting();
254
+ if (vmResponse.statusCode === 200) {
255
+ const vm = vmResponse.data.callSetting;
256
+ if (vm.enabled && vm.sendAllCalls.enabled) {
257
+ const response = {
258
+ ...cfResponse,
259
+ data: {
260
+ callSetting: {
261
+ ...cfa,
262
+ enabled: true,
263
+ destination: this.VOICEMAIL,
264
+ },
265
+ },
266
+ };
267
+ return response;
268
+ }
269
+ const response = {
270
+ ...cfResponse,
271
+ data: {
272
+ callSetting: {
273
+ ...cfa,
274
+ enabled: false,
275
+ destination: undefined,
276
+ },
277
+ },
278
+ };
279
+ return response;
280
+ }
281
+ log.warn(`Unable to retrieve voicemail settings.`, loggerContext);
282
+ vmResponse.data.error = 'Unable to retrieve voicemail settings.';
283
+ return vmResponse;
284
+ }
285
+ return cfResponse;
286
+ }
287
+ }
@@ -0,0 +1,11 @@
1
+ export const CALL_SETTINGS_FILE = 'CallSettings';
2
+ export const PEOPLE_ENDPOINT = 'people';
3
+ export const USER_ENDPOINT = 'user';
4
+ export const ORG_ENDPOINT = 'orgId';
5
+ export const DND_ENDPOINT = 'features/doNotDisturb';
6
+ export const CF_ENDPOINT = 'features/callForwarding';
7
+ export const VM_ENDPOINT = 'features/voicemail';
8
+ export const CALL_WAITING_ENDPOINT = 'CallWaiting';
9
+ export const XSI_VERSION = 'v2.0';
10
+ export const WEBEX_APIS_INT_URL = 'https://integration.webexapis.com/v1/uc/config';
11
+ export const WEBEX_APIS_PROD_URL = 'https://webexapis.com/v1/uc/config';
@@ -0,0 +1,62 @@
1
+ export const xsiEndpointUrlResponse = {
2
+ items: [
3
+ {
4
+ id: 'Y2lzY',
5
+ displayName: 'Atlas_Test_WxC_SI_AS10_VAR_WebrtcMobius_DND',
6
+ created: '2022-03-16T11:20:04.561Z',
7
+ xsiDomain: 'api-proxy-si.net',
8
+ xsiActionsEndpoint: 'https://api-proxy-si.broadcloudpbx.net/com.broadsoft.xsi-actions',
9
+ xsiEventsEndpoint: 'https://api-proxy-si.broadcloudpbx.net/com.broadsoft.xsi-events',
10
+ xsiEventsChannelEndpoint: 'https://api-proxy-si.broadcloudpbx.net/com.broadsoft.async/com.broadsoft.xsi-events',
11
+ },
12
+ ],
13
+ };
14
+ export const callForwardPayload = {
15
+ callForwarding: {
16
+ always: {
17
+ enabled: true,
18
+ destination: '123456789',
19
+ ringReminderEnabled: false,
20
+ destinationVoicemailEnabled: false,
21
+ },
22
+ busy: {
23
+ enabled: false,
24
+ },
25
+ noAnswer: {
26
+ enabled: true,
27
+ destination: '123123',
28
+ numberOfRings: 3,
29
+ },
30
+ },
31
+ businessContinuity: {
32
+ enabled: false,
33
+ },
34
+ };
35
+ export const dummyEmail = 'abc@test.com';
36
+ export const voicemailPayload = {
37
+ enabled: true,
38
+ sendAllCalls: {
39
+ enabled: true,
40
+ },
41
+ sendBusyCalls: {
42
+ enabled: true,
43
+ },
44
+ sendUnansweredCalls: {
45
+ enabled: true,
46
+ numberOfRings: 3,
47
+ },
48
+ notifications: {
49
+ enabled: true,
50
+ destination: dummyEmail,
51
+ },
52
+ emailCopyOfMessage: {
53
+ enabled: true,
54
+ emailId: dummyEmail,
55
+ },
56
+ messageStorage: {
57
+ mwiEnabled: true,
58
+ storageType: 'INTERNAL',
59
+ externalEmail: dummyEmail,
60
+ },
61
+ voiceMessageForwardingEnabled: false,
62
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,268 @@
1
+ import * as Media from '@webex/internal-media-core';
2
+ import { Mutex } from 'async-mutex';
3
+ import { filterMobiusUris, handleCallingClientErrors, validateServiceData } from '../common/Utils';
4
+ import { ERROR_TYPE } from '../Errors/types';
5
+ import { LOGGER } from '../Logger/types';
6
+ import SDKConnector from '../SDKConnector';
7
+ 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';
10
+ import log from '../Logger';
11
+ 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';
14
+ import Line from './line';
15
+ import { LINE_EVENTS, LineStatus } from './line/types';
16
+ import { METRIC_EVENT, REG_ACTION, METRIC_TYPE } from '../Metrics/types';
17
+ import { getMetricManager } from '../Metrics';
18
+ export class CallingClient extends Eventing {
19
+ sdkConnector;
20
+ webex;
21
+ mutex;
22
+ callManager;
23
+ metricManager;
24
+ sdkConfig;
25
+ primaryMobiusUris;
26
+ backupMobiusUris;
27
+ mediaEngine;
28
+ lineDict = {};
29
+ constructor(webex, config) {
30
+ super();
31
+ this.sdkConnector = SDKConnector;
32
+ if (!this.sdkConnector.getWebex()) {
33
+ SDKConnector.setWebex(webex);
34
+ }
35
+ this.mutex = new Mutex();
36
+ this.webex = this.sdkConnector.getWebex();
37
+ this.sdkConfig = config;
38
+ const serviceData = this.sdkConfig?.serviceData?.indicator
39
+ ? this.sdkConfig.serviceData
40
+ : { indicator: ServiceIndicator.CALLING, domain: '' };
41
+ const logLevel = this.sdkConfig?.logger?.level ? this.sdkConfig.logger.level : LOGGER.ERROR;
42
+ validateServiceData(serviceData);
43
+ this.callManager = getCallManager(this.webex, serviceData.indicator);
44
+ this.metricManager = getMetricManager(this.webex, serviceData.indicator);
45
+ this.mediaEngine = Media;
46
+ this.primaryMobiusUris = [];
47
+ this.backupMobiusUris = [];
48
+ this.registerSessionsListener();
49
+ log.setLogger(logLevel, CALLING_CLIENT_FILE);
50
+ this.incomingCallListener();
51
+ this.registerCallsClearedListener();
52
+ }
53
+ async init() {
54
+ await this.getMobiusServers();
55
+ await this.createLine();
56
+ this.detectNetworkChange();
57
+ }
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
+ async detectNetworkChange() {
69
+ let retry = false;
70
+ const line = Object.values(this.lineDict)[0];
71
+ setInterval(async () => {
72
+ if (!this.webex.internal.mercury.connected &&
73
+ !retry &&
74
+ !Object.keys(this.callManager.getActiveCalls()).length) {
75
+ log.warn(`Network has flapped, waiting for mercury connection to be up`, {
76
+ file: CALLING_CLIENT_FILE,
77
+ method: this.detectNetworkChange.name,
78
+ });
79
+ line.lineEmitter(LINE_EVENTS.UNREGISTERED);
80
+ line.registration.clearKeepaliveTimer();
81
+ retry = true;
82
+ }
83
+ if (retry && this.webex.internal.mercury.connected) {
84
+ retry = await line.registration.handleConnectionRestoration(retry);
85
+ }
86
+ }, NETWORK_FLAP_TIMEOUT);
87
+ }
88
+ async getClientRegionInfo() {
89
+ const regionInfo = {};
90
+ try {
91
+ const temp = await this.webex.request({
92
+ uri: `${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}${IP_ENDPOINT}`,
93
+ method: HTTP_METHODS.GET,
94
+ headers: {
95
+ [CISCO_DEVICE_URL]: this.webex.internal.device.url,
96
+ [SPARK_USER_AGENT]: CALLING_USER_AGENT,
97
+ },
98
+ service: ALLOWED_SERVICES.MOBIUS,
99
+ });
100
+ const myIP = temp.body.ipv4;
101
+ const response = await this.webex.request({
102
+ uri: `${DISCOVERY_URL}/${myIP}`,
103
+ method: HTTP_METHODS.GET,
104
+ addAuthHeader: false,
105
+ headers: {
106
+ [SPARK_USER_AGENT]: null,
107
+ },
108
+ });
109
+ const clientRegionInfo = response.body;
110
+ regionInfo.clientRegion = clientRegionInfo?.clientRegion ? clientRegionInfo.clientRegion : '';
111
+ regionInfo.countryCode = clientRegionInfo?.countryCode ? clientRegionInfo.countryCode : '';
112
+ }
113
+ catch (err) {
114
+ handleCallingClientErrors(err, (clientError) => {
115
+ this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
116
+ this.emit(EVENT_KEYS.ERROR, clientError);
117
+ }, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
118
+ regionInfo.clientRegion = '';
119
+ regionInfo.countryCode = '';
120
+ }
121
+ return regionInfo;
122
+ }
123
+ async getMobiusServers() {
124
+ let useDefault = false;
125
+ let clientRegion;
126
+ let countryCode;
127
+ if (this.sdkConfig?.discovery?.country && this.sdkConfig?.discovery?.region) {
128
+ log.info('Updating region and country from the SDK config', {
129
+ file: CALLING_CLIENT_FILE,
130
+ method: GET_MOBIUS_SERVERS_UTIL,
131
+ });
132
+ clientRegion = this.sdkConfig?.discovery?.region;
133
+ countryCode = this.sdkConfig?.discovery?.country;
134
+ }
135
+ else {
136
+ log.info('Updating region and country through Region discovery', {
137
+ file: CALLING_CLIENT_FILE,
138
+ method: GET_MOBIUS_SERVERS_UTIL,
139
+ });
140
+ const regionInfo = await this.getClientRegionInfo();
141
+ clientRegion = regionInfo.clientRegion;
142
+ countryCode = regionInfo.countryCode;
143
+ }
144
+ if (clientRegion && countryCode) {
145
+ log.log(`Found Region: ${clientRegion} and country: ${countryCode}, going to fetch Mobius server`, '');
146
+ try {
147
+ const temp = await this.webex.request({
148
+ uri: `${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}?regionCode=${clientRegion}&countryCode=${countryCode}`,
149
+ method: HTTP_METHODS.GET,
150
+ headers: {
151
+ [CISCO_DEVICE_URL]: this.webex.internal.device.url,
152
+ [SPARK_USER_AGENT]: CALLING_USER_AGENT,
153
+ },
154
+ service: ALLOWED_SERVICES.MOBIUS,
155
+ });
156
+ log.log('Mobius Server found for the region', '');
157
+ const mobiusServers = temp.body;
158
+ const mobiusUris = filterMobiusUris(mobiusServers, this.webex.internal.services._serviceUrls.mobius);
159
+ this.primaryMobiusUris = mobiusUris.primary;
160
+ this.backupMobiusUris = mobiusUris.backup;
161
+ log.info(`Final list of Mobius Servers, primary: ${mobiusUris.primary} and backup: ${mobiusUris.backup}`, '');
162
+ }
163
+ catch (err) {
164
+ handleCallingClientErrors(err, (clientError) => {
165
+ this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
166
+ this.emit(EVENT_KEYS.ERROR, clientError);
167
+ }, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
168
+ useDefault = true;
169
+ }
170
+ }
171
+ else {
172
+ useDefault = true;
173
+ }
174
+ if (useDefault) {
175
+ log.warn('Error in finding Mobius Servers. Will use the default URL.', '');
176
+ this.primaryMobiusUris = [
177
+ `${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}`,
178
+ ];
179
+ }
180
+ }
181
+ registerCallsClearedListener() {
182
+ const logContext = {
183
+ file: CALLING_CLIENT_FILE,
184
+ method: this.registerCallsClearedListener.name,
185
+ };
186
+ log.log('Registering listener for all calls cleared event', logContext);
187
+ this.callManager.on(EVENT_KEYS.ALL_CALLS_CLEARED, this.callsClearedHandler);
188
+ }
189
+ callsClearedHandler = async () => {
190
+ const { registration } = Object.values(this.lineDict)[0];
191
+ if (!registration.isDeviceRegistered()) {
192
+ await this.mutex.runExclusive(async () => {
193
+ if (registration.isReconnectPending()) {
194
+ log.log('All calls cleared, reconnecting', {
195
+ file: CALLING_CLIENT_FILE,
196
+ method: CALLS_CLEARED_HANDLER_UTIL,
197
+ });
198
+ await registration.reconnectOnFailure(CALLS_CLEARED_HANDLER_UTIL);
199
+ }
200
+ });
201
+ }
202
+ };
203
+ getLoggingLevel() {
204
+ return log.getLogLevel();
205
+ }
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
+ getSDKConnector() {
236
+ return this.sdkConnector;
237
+ }
238
+ registerSessionsListener() {
239
+ this.sdkConnector.registerListener(MOBIUS_EVENT_KEYS.CALL_SESSION_EVENT_INCLUSIVE, async (event) => {
240
+ if (event && event.data.userSessions.userSessions) {
241
+ const sessionArr = event?.data.userSessions.userSessions;
242
+ if (sessionArr.length === 1) {
243
+ if (sessionArr[0].sessionType !== SessionType.WEBEX_CALLING) {
244
+ return;
245
+ }
246
+ }
247
+ for (let i = 0; i < sessionArr.length; i += 1) {
248
+ if (sessionArr[i].sessionType !== SessionType.WEBEX_CALLING) {
249
+ sessionArr.splice(i, 1);
250
+ }
251
+ }
252
+ this.emit(EVENT_KEYS.USER_SESSION_INFO, event);
253
+ }
254
+ });
255
+ }
256
+ async createLine() {
257
+ const line = new Line(this.webex.internal.device.userId, this.webex.internal.device.url, LineStatus.INACTIVE, this.mutex, this.primaryMobiusUris, this.backupMobiusUris, this.getLoggingLevel(), this.sdkConfig?.serviceData);
258
+ this.lineDict[line.lineId] = line;
259
+ }
260
+ getLines() {
261
+ return this.lineDict;
262
+ }
263
+ }
264
+ export const createClient = async (webex, config) => {
265
+ const callingClientInstance = new CallingClient(webex, config);
266
+ await callingClientInstance.init();
267
+ return callingClientInstance;
268
+ };