@webex/contact-center 3.12.0-next.16 → 3.12.0-next.161

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 (328) hide show
  1. package/.sdd/manifest.json +887 -0
  2. package/AGENTS.md +94 -0
  3. package/ai-docs/ARCHITECTURE.md +168 -0
  4. package/ai-docs/CONTRACTS.md +62 -0
  5. package/ai-docs/GETTING_STARTED.md +168 -0
  6. package/ai-docs/GLOSSARY.md +43 -0
  7. package/ai-docs/README.md +138 -0
  8. package/ai-docs/REVIEW_CHECKLIST.md +41 -0
  9. package/ai-docs/RULES.md +444 -0
  10. package/ai-docs/SECURITY.md +52 -0
  11. package/ai-docs/SERVICE_STATE.md +52 -0
  12. package/ai-docs/SPEC_INDEX.md +65 -0
  13. package/ai-docs/adr/0001-spec-source-policy.md +55 -0
  14. package/ai-docs/adr/README.md +8 -0
  15. package/ai-docs/adr/_adr-template.md +31 -0
  16. package/ai-docs/contact-center-spec.md +385 -0
  17. package/ai-docs/features/consult-transfer-list-policy/spec/feature-spec.md +362 -0
  18. package/ai-docs/features/contact-owner-change-refactor.md +78 -0
  19. package/ai-docs/features/generated-spec-conformance-fidelity-remediation/spec/feature-spec.md +117 -0
  20. package/ai-docs/features/residual-warning-coverage-completion/spec/feature-spec.md +203 -0
  21. package/ai-docs/features/validator-code-fidelity-drift-fix/spec/feature-spec.md +315 -0
  22. package/ai-docs/patterns/event-driven-patterns.md +485 -0
  23. package/ai-docs/patterns/testing-patterns.md +480 -0
  24. package/ai-docs/patterns/typescript-patterns.md +365 -0
  25. package/ai-docs/templates/README.md +102 -0
  26. package/ai-docs/templates/documentation/create-agents-md.md +240 -0
  27. package/ai-docs/templates/documentation/create-architecture-md.md +295 -0
  28. package/ai-docs/templates/existing-service/bug-fix.md +254 -0
  29. package/ai-docs/templates/existing-service/feature-enhancement.md +450 -0
  30. package/ai-docs/templates/new-method/00-master.md +80 -0
  31. package/ai-docs/templates/new-method/01-requirements.md +232 -0
  32. package/ai-docs/templates/new-method/02-implementation.md +295 -0
  33. package/ai-docs/templates/new-method/03-tests.md +201 -0
  34. package/ai-docs/templates/new-method/04-validation.md +141 -0
  35. package/ai-docs/templates/new-service/00-master.md +109 -0
  36. package/ai-docs/templates/new-service/01-pre-questions.md +159 -0
  37. package/ai-docs/templates/new-service/02-code-generation.md +346 -0
  38. package/ai-docs/templates/new-service/03-integration.md +178 -0
  39. package/ai-docs/templates/new-service/04-test-generation.md +205 -0
  40. package/ai-docs/templates/new-service/05-validation.md +145 -0
  41. package/dist/cc.js +888 -49
  42. package/dist/cc.js.map +1 -1
  43. package/dist/config.js +13 -0
  44. package/dist/config.js.map +1 -1
  45. package/dist/constants.js +38 -3
  46. package/dist/constants.js.map +1 -1
  47. package/dist/index.js +54 -17
  48. package/dist/index.js.map +1 -1
  49. package/dist/metrics/MetricsManager.js +16 -0
  50. package/dist/metrics/MetricsManager.js.map +1 -1
  51. package/dist/metrics/behavioral-events.js +185 -0
  52. package/dist/metrics/behavioral-events.js.map +1 -1
  53. package/dist/metrics/constants.js +54 -4
  54. package/dist/metrics/constants.js.map +1 -1
  55. package/dist/services/AddressBook.js +18 -15
  56. package/dist/services/AddressBook.js.map +1 -1
  57. package/dist/services/AnswerCallOnWebexService.js +202 -0
  58. package/dist/services/AnswerCallOnWebexService.js.map +1 -0
  59. package/dist/services/ApiAiAssistant.js +369 -14
  60. package/dist/services/ApiAiAssistant.js.map +1 -1
  61. package/dist/services/EntryPoint.js +46 -68
  62. package/dist/services/EntryPoint.js.map +1 -1
  63. package/dist/services/Queue.js +27 -22
  64. package/dist/services/Queue.js.map +1 -1
  65. package/dist/services/UserPreference.js +427 -0
  66. package/dist/services/UserPreference.js.map +1 -0
  67. package/dist/services/WebCallingService.js +10 -2
  68. package/dist/services/WebCallingService.js.map +1 -1
  69. package/dist/services/WebexCrossClientService.js +225 -0
  70. package/dist/services/WebexCrossClientService.js.map +1 -0
  71. package/dist/services/WxAppTelephonyMercurySync.js +111 -0
  72. package/dist/services/WxAppTelephonyMercurySync.js.map +1 -0
  73. package/dist/services/config/Util.js +48 -48
  74. package/dist/services/config/Util.js.map +1 -1
  75. package/dist/services/config/constants.js +56 -78
  76. package/dist/services/config/constants.js.map +1 -1
  77. package/dist/services/config/index.js +100 -226
  78. package/dist/services/config/index.js.map +1 -1
  79. package/dist/services/config/types.js +93 -24
  80. package/dist/services/config/types.js.map +1 -1
  81. package/dist/services/constants.js +11 -1
  82. package/dist/services/constants.js.map +1 -1
  83. package/dist/services/core/Err.js.map +1 -1
  84. package/dist/services/core/Utils.js +131 -32
  85. package/dist/services/core/Utils.js.map +1 -1
  86. package/dist/services/core/WebexRequest.js +6 -2
  87. package/dist/services/core/WebexRequest.js.map +1 -1
  88. package/dist/services/core/aqm-reqs.js +17 -11
  89. package/dist/services/core/aqm-reqs.js.map +1 -1
  90. package/dist/services/core/constants.js +9 -1
  91. package/dist/services/core/constants.js.map +1 -1
  92. package/dist/services/core/types.js.map +1 -1
  93. package/dist/services/core/websocket/WebSocketManager.js +19 -2
  94. package/dist/services/core/websocket/WebSocketManager.js.map +1 -1
  95. package/dist/services/core/websocket/types.js.map +1 -1
  96. package/dist/services/index.js +1 -1
  97. package/dist/services/index.js.map +1 -1
  98. package/dist/services/task/Task.js +955 -0
  99. package/dist/services/task/Task.js.map +1 -0
  100. package/dist/services/task/TaskFactory.js +50 -0
  101. package/dist/services/task/TaskFactory.js.map +1 -0
  102. package/dist/services/task/TaskManager.js +1272 -605
  103. package/dist/services/task/TaskManager.js.map +1 -1
  104. package/dist/services/task/TaskUtils.js +221 -27
  105. package/dist/services/task/TaskUtils.js.map +1 -1
  106. package/dist/services/task/WebexCallingUtils.js +70 -0
  107. package/dist/services/task/WebexCallingUtils.js.map +1 -0
  108. package/dist/services/task/constants.js +19 -2
  109. package/dist/services/task/constants.js.map +1 -1
  110. package/dist/services/task/contact.js +29 -0
  111. package/dist/services/task/contact.js.map +1 -1
  112. package/dist/services/task/digital/Digital.js +78 -0
  113. package/dist/services/task/digital/Digital.js.map +1 -0
  114. package/dist/services/task/state-machine/TaskStateMachine.js +982 -0
  115. package/dist/services/task/state-machine/TaskStateMachine.js.map +1 -0
  116. package/dist/services/task/state-machine/actions.js +572 -0
  117. package/dist/services/task/state-machine/actions.js.map +1 -0
  118. package/dist/services/task/state-machine/constants.js +161 -0
  119. package/dist/services/task/state-machine/constants.js.map +1 -0
  120. package/dist/services/task/state-machine/guards.js +379 -0
  121. package/dist/services/task/state-machine/guards.js.map +1 -0
  122. package/dist/services/task/state-machine/index.js +53 -0
  123. package/dist/services/task/state-machine/index.js.map +1 -0
  124. package/dist/services/task/state-machine/types.js +54 -0
  125. package/dist/services/task/state-machine/types.js.map +1 -0
  126. package/dist/services/task/state-machine/uiControlsComputer.js +703 -0
  127. package/dist/services/task/state-machine/uiControlsComputer.js.map +1 -0
  128. package/dist/services/task/taskDataNormalizer.js +99 -0
  129. package/dist/services/task/taskDataNormalizer.js.map +1 -0
  130. package/dist/services/task/types.js +215 -5
  131. package/dist/services/task/types.js.map +1 -1
  132. package/dist/services/task/voice/Voice.js +1504 -0
  133. package/dist/services/task/voice/Voice.js.map +1 -0
  134. package/dist/services/task/voice/WebRTC.js +152 -0
  135. package/dist/services/task/voice/WebRTC.js.map +1 -0
  136. package/dist/services/task/voice/wxAppOfferObservability.js +145 -0
  137. package/dist/services/task/voice/wxAppOfferObservability.js.map +1 -0
  138. package/dist/services/task/voice/wxAppVoiceMethods.js +395 -0
  139. package/dist/services/task/voice/wxAppVoiceMethods.js.map +1 -0
  140. package/dist/services/wxAppDiagnosticLogging.js +159 -0
  141. package/dist/services/wxAppDiagnosticLogging.js.map +1 -0
  142. package/dist/services/wxAppTelephonyUtils.js +19 -0
  143. package/dist/services/wxAppTelephonyUtils.js.map +1 -0
  144. package/dist/types/cc.d.ts +152 -9
  145. package/dist/types/config.d.ts +13 -0
  146. package/dist/types/constants.d.ts +36 -1
  147. package/dist/types/index.d.ts +54 -20
  148. package/dist/types/metrics/MetricsManager.d.ts +6 -0
  149. package/dist/types/metrics/constants.d.ts +48 -1
  150. package/dist/types/services/AddressBook.d.ts +2 -1
  151. package/dist/types/services/AnswerCallOnWebexService.d.ts +38 -0
  152. package/dist/types/services/ApiAiAssistant.d.ts +67 -5
  153. package/dist/types/services/EntryPoint.d.ts +7 -5
  154. package/dist/types/services/Queue.d.ts +5 -3
  155. package/dist/types/services/UserPreference.d.ts +118 -0
  156. package/dist/types/services/WebexCrossClientService.d.ts +32 -0
  157. package/dist/types/services/WxAppTelephonyMercurySync.d.ts +28 -0
  158. package/dist/types/services/config/Util.d.ts +4 -8
  159. package/dist/types/services/config/constants.d.ts +49 -76
  160. package/dist/types/services/config/index.d.ts +16 -64
  161. package/dist/types/services/config/types.d.ts +240 -114
  162. package/dist/types/services/constants.d.ts +9 -0
  163. package/dist/types/services/core/Err.d.ts +2 -0
  164. package/dist/types/services/core/Utils.d.ts +43 -13
  165. package/dist/types/services/core/WebexRequest.d.ts +1 -0
  166. package/dist/types/services/core/constants.d.ts +7 -0
  167. package/dist/types/services/core/types.d.ts +2 -0
  168. package/dist/types/services/core/websocket/WebSocketManager.d.ts +1 -0
  169. package/dist/types/services/core/websocket/types.d.ts +1 -1
  170. package/dist/types/services/index.d.ts +1 -1
  171. package/dist/types/services/task/Task.d.ts +186 -0
  172. package/dist/types/services/task/TaskFactory.d.ts +14 -0
  173. package/dist/types/services/task/TaskUtils.d.ts +54 -2
  174. package/dist/types/services/task/WebexCallingUtils.d.ts +11 -0
  175. package/dist/types/services/task/constants.d.ts +17 -0
  176. package/dist/types/services/task/contact.d.ts +4 -0
  177. package/dist/types/services/task/digital/Digital.d.ts +23 -0
  178. package/dist/types/services/task/state-machine/TaskStateMachine.d.ts +1442 -0
  179. package/dist/types/services/task/state-machine/actions.d.ts +10 -0
  180. package/dist/types/services/task/state-machine/constants.d.ts +107 -0
  181. package/dist/types/services/task/state-machine/guards.d.ts +103 -0
  182. package/dist/types/services/task/state-machine/index.d.ts +13 -0
  183. package/dist/types/services/task/state-machine/types.d.ts +277 -0
  184. package/dist/types/services/task/state-machine/uiControlsComputer.d.ts +9 -0
  185. package/dist/types/services/task/taskDataNormalizer.d.ts +10 -0
  186. package/dist/types/services/task/types.d.ts +738 -66
  187. package/dist/types/services/task/voice/Voice.d.ts +241 -0
  188. package/dist/types/services/task/voice/WebRTC.d.ts +54 -0
  189. package/dist/types/services/task/voice/wxAppOfferObservability.d.ts +39 -0
  190. package/dist/types/services/task/voice/wxAppVoiceMethods.d.ts +68 -0
  191. package/dist/types/services/wxAppDiagnosticLogging.d.ts +63 -0
  192. package/dist/types/services/wxAppTelephonyUtils.d.ts +5 -0
  193. package/dist/types/types.d.ts +213 -11
  194. package/dist/types/utils/PageCache.d.ts +20 -3
  195. package/dist/types/webex.d.ts +1 -0
  196. package/dist/types.js +168 -6
  197. package/dist/types.js.map +1 -1
  198. package/dist/utils/PageCache.js +19 -5
  199. package/dist/utils/PageCache.js.map +1 -1
  200. package/dist/webex.js +22 -2
  201. package/dist/webex.js.map +1 -1
  202. package/package.json +16 -12
  203. package/src/cc.ts +1137 -67
  204. package/src/config.ts +13 -0
  205. package/src/constants.ts +39 -1
  206. package/src/index.ts +62 -15
  207. package/src/metrics/MetricsManager.ts +16 -0
  208. package/src/metrics/ai-docs/AGENTS.md +350 -0
  209. package/src/metrics/ai-docs/ARCHITECTURE.md +338 -0
  210. package/src/metrics/ai-docs/metrics-spec.md +971 -0
  211. package/src/metrics/behavioral-events.ts +190 -0
  212. package/src/metrics/constants.ts +59 -4
  213. package/src/services/AddressBook.ts +17 -6
  214. package/src/services/AnswerCallOnWebexService.ts +239 -0
  215. package/src/services/ApiAiAssistant.ts +494 -15
  216. package/src/services/EntryPoint.ts +59 -60
  217. package/src/services/Queue.ts +29 -12
  218. package/src/services/UserPreference.ts +509 -0
  219. package/src/services/WebCallingService.ts +16 -2
  220. package/src/services/WebexCrossClientService.ts +298 -0
  221. package/src/services/WxAppTelephonyMercurySync.ts +142 -0
  222. package/src/services/agent/ai-docs/AGENTS.md +240 -0
  223. package/src/services/agent/ai-docs/ARCHITECTURE.md +304 -0
  224. package/src/services/agent/ai-docs/agent-spec.md +505 -0
  225. package/src/services/ai-docs/AGENTS.md +386 -0
  226. package/src/services/ai-docs/services-spec.md +512 -0
  227. package/src/services/config/Util.ts +54 -84
  228. package/src/services/config/ai-docs/AGENTS.md +250 -0
  229. package/src/services/config/ai-docs/ARCHITECTURE.md +413 -0
  230. package/src/services/config/ai-docs/config-spec.md +669 -0
  231. package/src/services/config/constants.ts +63 -85
  232. package/src/services/config/index.ts +116 -277
  233. package/src/services/config/types.ts +229 -125
  234. package/src/services/constants.ts +10 -0
  235. package/src/services/core/Err.ts +1 -0
  236. package/src/services/core/Utils.ts +151 -37
  237. package/src/services/core/WebexRequest.ts +3 -1
  238. package/src/services/core/ai-docs/AGENTS.md +381 -0
  239. package/src/services/core/ai-docs/ARCHITECTURE.md +698 -0
  240. package/src/services/core/ai-docs/core-spec.md +797 -0
  241. package/src/services/core/aqm-reqs.ts +18 -12
  242. package/src/services/core/constants.ts +8 -0
  243. package/src/services/core/types.ts +33 -1
  244. package/src/services/core/websocket/WebSocketManager.ts +28 -2
  245. package/src/services/core/websocket/types.ts +1 -1
  246. package/src/services/index.ts +1 -1
  247. package/src/services/task/Task.ts +1211 -0
  248. package/src/services/task/TaskFactory.ts +82 -0
  249. package/src/services/task/TaskManager.ts +1585 -724
  250. package/src/services/task/TaskUtils.ts +316 -25
  251. package/src/services/task/WebexCallingUtils.ts +136 -0
  252. package/src/services/task/ai-docs/AGENTS.md +457 -0
  253. package/src/services/task/ai-docs/ARCHITECTURE.md +595 -0
  254. package/src/services/task/ai-docs/task-spec.md +1501 -0
  255. package/src/services/task/constants.ts +18 -0
  256. package/src/services/task/contact.ts +30 -0
  257. package/src/services/task/digital/Digital.ts +102 -0
  258. package/src/services/task/state-machine/TaskStateMachine.ts +1320 -0
  259. package/src/services/task/state-machine/actions.ts +741 -0
  260. package/src/services/task/state-machine/ai-docs/AGENTS.md +460 -0
  261. package/src/services/task/state-machine/ai-docs/ARCHITECTURE.md +1156 -0
  262. package/src/services/task/state-machine/ai-docs/task-state-machine-spec.md +2247 -0
  263. package/src/services/task/state-machine/constants.ts +172 -0
  264. package/src/services/task/state-machine/guards.ts +442 -0
  265. package/src/services/task/state-machine/index.ts +28 -0
  266. package/src/services/task/state-machine/types.ts +258 -0
  267. package/src/services/task/state-machine/uiControlsComputer.ts +1135 -0
  268. package/src/services/task/taskDataNormalizer.ts +137 -0
  269. package/src/services/task/types.ts +918 -70
  270. package/src/services/task/voice/Voice.ts +1878 -0
  271. package/src/services/task/voice/WebRTC.ts +194 -0
  272. package/src/services/task/voice/wxAppOfferObservability.ts +204 -0
  273. package/src/services/task/voice/wxAppVoiceMethods.ts +575 -0
  274. package/src/services/wxAppDiagnosticLogging.ts +286 -0
  275. package/src/services/wxAppTelephonyUtils.ts +14 -0
  276. package/src/types.ts +272 -13
  277. package/src/utils/AGENTS.md +289 -0
  278. package/src/utils/PageCache.ts +38 -5
  279. package/src/utils/ai-docs/utils-spec.md +391 -0
  280. package/src/webex.js +10 -0
  281. package/test/unit/fixtures/aiSummaryTestUtils.ts +40 -0
  282. package/test/unit/spec/cc.ts +3553 -107
  283. package/test/unit/spec/index.ts +885 -0
  284. package/test/unit/spec/logger-proxy.ts +70 -0
  285. package/test/unit/spec/metrics/MetricsManager.ts +25 -0
  286. package/test/unit/spec/metrics/behavioral-events.ts +60 -0
  287. package/test/unit/spec/services/AddressBook.ts +37 -6
  288. package/test/unit/spec/services/AnswerCallOnWebexService.ts +264 -0
  289. package/test/unit/spec/services/ApiAiAssistant.ts +442 -23
  290. package/test/unit/spec/services/EntryPoint.ts +87 -40
  291. package/test/unit/spec/services/Queue.ts +123 -12
  292. package/test/unit/spec/services/UserPreference.ts +401 -0
  293. package/test/unit/spec/services/WebCallingService.ts +45 -1
  294. package/test/unit/spec/services/WebexCrossClientService.ts +509 -0
  295. package/test/unit/spec/services/WxAppTelephonyMercurySync.ts +136 -0
  296. package/test/unit/spec/services/config/Util.ts +501 -0
  297. package/test/unit/spec/services/config/index.ts +317 -547
  298. package/test/unit/spec/services/core/Utils.ts +447 -8
  299. package/test/unit/spec/services/core/WebexRequest.ts +8 -7
  300. package/test/unit/spec/services/core/aqm-reqs.ts +142 -1
  301. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +129 -53
  302. package/test/unit/spec/services/task/AutoWrapup.ts +63 -0
  303. package/test/unit/spec/services/task/Task.ts +2723 -0
  304. package/test/unit/spec/services/task/TaskFactory.ts +116 -0
  305. package/test/unit/spec/services/task/TaskManager.ts +4734 -1769
  306. package/test/unit/spec/services/task/TaskUtils.ts +307 -0
  307. package/test/unit/spec/services/task/WebexCallingUtils.ts +153 -0
  308. package/test/unit/spec/services/task/contact.ts +33 -0
  309. package/test/unit/spec/services/task/digital/Digital.ts +105 -0
  310. package/test/unit/spec/services/task/state-machine/TaskStateMachine.ts +4060 -0
  311. package/test/unit/spec/services/task/state-machine/guards.ts +839 -0
  312. package/test/unit/spec/services/task/state-machine/types.ts +18 -0
  313. package/test/unit/spec/services/task/state-machine/uiControlsComputer.ts +3101 -0
  314. package/test/unit/spec/services/task/taskTestUtils.ts +87 -0
  315. package/test/unit/spec/services/task/voice/Voice.ts +2355 -0
  316. package/test/unit/spec/services/task/voice/WebRTC.ts +235 -0
  317. package/test/unit/spec/services/task/voice/wxAppOfferObservability.ts +361 -0
  318. package/test/unit/spec/services/task/voice/wxAppVoiceMethods.ts +719 -0
  319. package/test/unit/spec/services/wxAppDiagnosticLogging.ts +179 -0
  320. package/test/unit/spec/wellnessSampleUtils.ts +288 -0
  321. package/typedoc.md +1 -1
  322. package/umd/contact-center.min.js +2 -2
  323. package/umd/contact-center.min.js.map +1 -1
  324. package/dist/services/task/index.js +0 -1530
  325. package/dist/services/task/index.js.map +0 -1
  326. package/dist/types/services/task/index.d.ts +0 -650
  327. package/src/services/task/index.ts +0 -1806
  328. package/test/unit/spec/services/task/index.ts +0 -2205
@@ -0,0 +1,194 @@
1
+ import {LocalMicrophoneStream, CALL_EVENT_KEYS} from '@webex/calling';
2
+ import {CC_FILE} from '../../../constants';
3
+ import {getErrorDetails} from '../../core/Utils';
4
+ import routingContact from '../contact';
5
+ import {
6
+ TaskData,
7
+ TaskResponse,
8
+ TASK_EVENTS,
9
+ IWebRTC,
10
+ VoiceUIControlOptions,
11
+ VOICE_VARIANT,
12
+ TaskToggleMuteOptions,
13
+ } from '../types';
14
+ import Voice from './Voice';
15
+ import WebCallingService from '../../WebCallingService';
16
+ import type {WrapupData} from '../../config/types';
17
+ import type ApiAIAssistant from '../../ApiAiAssistant';
18
+ import MetricsManager from '../../../metrics/MetricsManager';
19
+ import {METRIC_EVENT_NAMES} from '../../../metrics/constants';
20
+ import LoggerProxy from '../../../logger-proxy';
21
+
22
+ export default class WebRTC extends Voice implements IWebRTC {
23
+ private localAudioStream: LocalMicrophoneStream;
24
+ private webCallingService: WebCallingService;
25
+
26
+ constructor(
27
+ contact: ReturnType<typeof routingContact>,
28
+ webCallingService: WebCallingService,
29
+ data: TaskData,
30
+ callOptions?: VoiceUIControlOptions,
31
+ wrapupData?: WrapupData,
32
+ agentId?: string,
33
+ agentName?: string,
34
+ apiAIAssistant?: ApiAIAssistant
35
+ ) {
36
+ const mergedCallOptions: VoiceUIControlOptions = {
37
+ ...callOptions,
38
+ voiceVariant: VOICE_VARIANT.WEBRTC,
39
+ };
40
+
41
+ super(contact, data, mergedCallOptions, wrapupData, agentId, agentName, apiAIAssistant);
42
+ this.webCallingService = webCallingService;
43
+ this.registerWebCallListeners();
44
+ }
45
+
46
+ private registerWebCallListeners() {
47
+ this.webCallingService.on(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
48
+ }
49
+
50
+ private handleRemoteMedia = (track: MediaStreamTrack) => {
51
+ this.emit(TASK_EVENTS.TASK_MEDIA, track);
52
+ };
53
+
54
+ /**
55
+ * This method is used to unregister the web call listeners.
56
+ * @returns void
57
+ * @example
58
+ * ```typescript
59
+ * task.unregisterWebCallListeners();
60
+ * ```
61
+ */
62
+ public unregisterWebCallListeners() {
63
+ this.webCallingService.off(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleRemoteMedia);
64
+ }
65
+
66
+ /**
67
+ * This is used for incoming task accept by agent.
68
+ *
69
+ * @returns Promise<TaskResponse>
70
+ * @throws Error
71
+ * @example
72
+ * ```typescript
73
+ * task.accept().then(()=>{}).catch(()=>{})
74
+ * ```
75
+ */
76
+ public async accept(): Promise<TaskResponse> {
77
+ LoggerProxy.log(`Accepting WebRTC task for taskId:${this.data.interactionId}`, {
78
+ module: 'WebRTC',
79
+ method: 'accept',
80
+ });
81
+ try {
82
+ this.metricsManager.timeEvent([
83
+ METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS,
84
+ METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED,
85
+ ]);
86
+
87
+ const constraints = {audio: true};
88
+ const localStream = await navigator.mediaDevices.getUserMedia(constraints);
89
+ const audioTrack = localStream.getAudioTracks()[0];
90
+ this.localAudioStream = new LocalMicrophoneStream(new MediaStream([audioTrack]));
91
+ this.webCallingService.answerCall(this.localAudioStream, this.data.interactionId);
92
+
93
+ this.metricsManager.trackEvent(
94
+ METRIC_EVENT_NAMES.TASK_ACCEPT_SUCCESS,
95
+ {
96
+ taskId: this.data.interactionId,
97
+ ...MetricsManager.getCommonTrackingFieldForAQMResponse(this.data),
98
+ },
99
+ ['operational', 'behavioral', 'business']
100
+ );
101
+
102
+ return Promise.resolve();
103
+ } catch (error) {
104
+ this.metricsManager.trackEvent(
105
+ METRIC_EVENT_NAMES.TASK_ACCEPT_FAILED,
106
+ {
107
+ taskId: this.data.interactionId,
108
+ error: error.toString(),
109
+ ...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
110
+ (error as any).details || {}
111
+ ),
112
+ },
113
+ ['operational', 'behavioral', 'business']
114
+ );
115
+ const {error: detailedError} = getErrorDetails(error, 'accept', CC_FILE);
116
+ throw detailedError;
117
+ }
118
+ }
119
+
120
+ /**
121
+ * This is used for the incoming task decline by agent.
122
+ *
123
+ * @returns Promise<TaskResponse>
124
+ * @throws Error
125
+ * @example
126
+ * ```typescript
127
+ * task.decline().then(()=>{}).catch(()=>{})
128
+ * ```
129
+ */
130
+ public async decline(): Promise<TaskResponse> {
131
+ LoggerProxy.log(`Declining WebRTC task for taskId:${this.data.interactionId}`, {
132
+ module: 'WebRTC',
133
+ method: 'decline',
134
+ });
135
+ try {
136
+ this.metricsManager.timeEvent([
137
+ METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
138
+ METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
139
+ ]);
140
+
141
+ this.webCallingService.declineCall(this.data.interactionId);
142
+ this.unregisterWebCallListeners();
143
+
144
+ this.metricsManager.trackEvent(
145
+ METRIC_EVENT_NAMES.TASK_DECLINE_SUCCESS,
146
+ {taskId: this.data.interactionId},
147
+ ['operational', 'behavioral']
148
+ );
149
+
150
+ return Promise.resolve();
151
+ } catch (error) {
152
+ this.metricsManager.trackEvent(
153
+ METRIC_EVENT_NAMES.TASK_DECLINE_FAILED,
154
+ {
155
+ taskId: this.data.interactionId,
156
+ error: error.toString(),
157
+ ...MetricsManager.getCommonTrackingFieldForAQMResponseFailed(
158
+ (error as any).details || {}
159
+ ),
160
+ },
161
+ ['operational', 'behavioral']
162
+ );
163
+ const {error: detailedError} = getErrorDetails(error, 'decline', CC_FILE);
164
+ throw detailedError;
165
+ }
166
+ }
167
+
168
+ /**
169
+ * This is used for the placing the call in mute or unmute by the agent.
170
+ *
171
+ * @throws Error
172
+ * @example
173
+ * ```typescript
174
+ * task.toggleMute().then(()=>{}).catch(()=>{})
175
+ * ```
176
+ */
177
+ public async toggleMute(options?: TaskToggleMuteOptions) {
178
+ if (options) {
179
+ // parameter intentionally unused — WebRTC toggles from local stream state
180
+ }
181
+ LoggerProxy.log(`Toggling mute WebRTC task for taskId:${this.data.interactionId}`, {
182
+ module: 'WebRTC',
183
+ method: 'toggleMute',
184
+ });
185
+ try {
186
+ this.webCallingService.muteUnmuteCall(this.localAudioStream);
187
+
188
+ return Promise.resolve();
189
+ } catch (error) {
190
+ const {error: detailedError} = getErrorDetails(error, 'mute', CC_FILE);
191
+ throw detailedError;
192
+ }
193
+ }
194
+ }
@@ -0,0 +1,204 @@
1
+ import MetricsManager from '../../../metrics/MetricsManager';
2
+ import {METRIC_EVENT_NAMES} from '../../../metrics/constants';
3
+ import {
4
+ deriveWxAppAcceptReason,
5
+ logWxAppOfferDecision,
6
+ logWxAppOfferParticipantMismatch,
7
+ WxAppAcceptReason,
8
+ } from '../../wxAppDiagnosticLogging';
9
+ import {TaskState} from '../state-machine';
10
+ import {VoiceVariant, VOICE_VARIANT} from '../types';
11
+ import {
12
+ getCallingDeviceDetails,
13
+ getWxAppParticipantDiagnostics,
14
+ WxAppVoiceDependencies,
15
+ } from './wxAppVoiceMethods';
16
+
17
+ /** Defer mismatch WARN/metric so transient WS ordering gaps (~200–300 ms) do not false-alarm. */
18
+ export const WXAPP_PARTICIPANT_MISMATCH_GRACE_MS = 500;
19
+
20
+ export type WxAppOfferObservabilityContext = {
21
+ getInteractionId: () => string;
22
+ getTaskState: () => TaskState | undefined;
23
+ getAcceptControl: () => {isVisible: boolean; isEnabled: boolean} | undefined;
24
+ getVoiceVariant: () => VoiceVariant;
25
+ isOutdial: () => boolean;
26
+ isWxAppInboundOffer: () => boolean;
27
+ isWxAppCallingOffer: () => boolean;
28
+ getWxAppAcceptInFlight: () => boolean;
29
+ getWxAppAnswerPending: () => boolean;
30
+ getEnableWxBetterTogether: () => boolean;
31
+ getUsersubPublished: () => boolean;
32
+ getWxAppVoiceDependencies: () => WxAppVoiceDependencies;
33
+ getMetricsManager: () => MetricsManager;
34
+ };
35
+
36
+ /**
37
+ * OFFERED-state wxApp offer diagnostics: acceptReason logging and deferred participant mismatch.
38
+ * Invoked from Voice.updateUiControls — observability only.
39
+ */
40
+ export class WxAppOfferObservability {
41
+ private lastLoggedWxAppAcceptReason?: WxAppAcceptReason;
42
+ private lastLoggedWxAppParticipantMismatch = false;
43
+ private wxAppParticipantMismatchGraceTimer?: ReturnType<typeof setTimeout>;
44
+ private disposed = false;
45
+
46
+ public handleUiControlsUpdate(ctx: WxAppOfferObservabilityContext): void {
47
+ if (this.disposed) {
48
+ return;
49
+ }
50
+
51
+ if (!ctx.getEnableWxBetterTogether()) {
52
+ this.cancelGraceTimer();
53
+
54
+ return;
55
+ }
56
+
57
+ const state = ctx.getTaskState();
58
+ if (state !== TaskState.OFFERED) {
59
+ this.cancelGraceTimer();
60
+
61
+ return;
62
+ }
63
+
64
+ const accept = ctx.getAcceptControl();
65
+ if (!accept?.isVisible) {
66
+ return;
67
+ }
68
+
69
+ const deps = ctx.getWxAppVoiceDependencies();
70
+ const isOutdial = ctx.isOutdial();
71
+ const isWxAppInboundOffer = ctx.isWxAppInboundOffer();
72
+ const isWxAppOutdialOffer = ctx.isWxAppCallingOffer() && isOutdial;
73
+ const deviceDetails = getCallingDeviceDetails(deps);
74
+ const participantDiagnostics = getWxAppParticipantDiagnostics(deps);
75
+ const usersubPublished = ctx.getUsersubPublished();
76
+ const acceptReason = deriveWxAppAcceptReason({
77
+ isWxAppInboundOffer,
78
+ isWxAppOutdialOffer,
79
+ isWebrtc: ctx.getVoiceVariant() === VOICE_VARIANT.WEBRTC,
80
+ isOutdial,
81
+ wxAppAcceptInFlight: ctx.getWxAppAcceptInFlight(),
82
+ wxAppAnswerPending: ctx.getWxAppAnswerPending(),
83
+ enableWxBetterTogether: ctx.getEnableWxBetterTogether(),
84
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
85
+ });
86
+
87
+ if (acceptReason !== this.lastLoggedWxAppAcceptReason) {
88
+ this.lastLoggedWxAppAcceptReason = acceptReason;
89
+
90
+ logWxAppOfferDecision({
91
+ interactionId: ctx.getInteractionId(),
92
+ acceptVisible: accept.isVisible,
93
+ acceptEnabled: accept.isEnabled,
94
+ acceptReason,
95
+ wxAppParticipantDeviceType:
96
+ deviceDetails?.deviceType ?? participantDiagnostics.participantDeviceType,
97
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
98
+ hasDeviceId: participantDiagnostics.hasDeviceId,
99
+ usersubPublished,
100
+ });
101
+ }
102
+
103
+ if (participantDiagnostics.hasValidWxAppParticipant || !usersubPublished) {
104
+ this.cancelGraceTimer();
105
+ } else if (!ctx.isOutdial() && !this.lastLoggedWxAppParticipantMismatch) {
106
+ this.scheduleGraceTimer(ctx);
107
+ }
108
+ }
109
+
110
+ public dispose(): void {
111
+ this.disposed = true;
112
+ this.cancelGraceTimer();
113
+ }
114
+
115
+ private cancelGraceTimer(): void {
116
+ if (this.wxAppParticipantMismatchGraceTimer !== undefined) {
117
+ clearTimeout(this.wxAppParticipantMismatchGraceTimer);
118
+ this.wxAppParticipantMismatchGraceTimer = undefined;
119
+ }
120
+ }
121
+
122
+ private scheduleGraceTimer(ctx: WxAppOfferObservabilityContext): void {
123
+ if (
124
+ this.disposed ||
125
+ this.lastLoggedWxAppParticipantMismatch ||
126
+ this.wxAppParticipantMismatchGraceTimer !== undefined
127
+ ) {
128
+ return;
129
+ }
130
+
131
+ this.wxAppParticipantMismatchGraceTimer = setTimeout(() => {
132
+ this.wxAppParticipantMismatchGraceTimer = undefined;
133
+ this.emitParticipantMismatchIfStillNeeded(ctx);
134
+ }, WXAPP_PARTICIPANT_MISMATCH_GRACE_MS);
135
+ }
136
+
137
+ private emitParticipantMismatchIfStillNeeded(ctx: WxAppOfferObservabilityContext): void {
138
+ if (
139
+ this.disposed ||
140
+ !ctx.getEnableWxBetterTogether() ||
141
+ this.lastLoggedWxAppParticipantMismatch
142
+ ) {
143
+ return;
144
+ }
145
+
146
+ if (ctx.isOutdial()) {
147
+ return;
148
+ }
149
+
150
+ if (ctx.getTaskState() !== TaskState.OFFERED) {
151
+ return;
152
+ }
153
+
154
+ const accept = ctx.getAcceptControl();
155
+ if (!accept?.isVisible) {
156
+ return;
157
+ }
158
+
159
+ const deps = ctx.getWxAppVoiceDependencies();
160
+ const participantDiagnostics = getWxAppParticipantDiagnostics(deps);
161
+ const usersubPublished = ctx.getUsersubPublished();
162
+
163
+ if (!usersubPublished || participantDiagnostics.hasValidWxAppParticipant) {
164
+ return;
165
+ }
166
+
167
+ const isOutdial = ctx.isOutdial();
168
+ const acceptReason = deriveWxAppAcceptReason({
169
+ isWxAppInboundOffer: ctx.isWxAppInboundOffer(),
170
+ isWxAppOutdialOffer: ctx.isWxAppCallingOffer() && isOutdial,
171
+ isWebrtc: ctx.getVoiceVariant() === VOICE_VARIANT.WEBRTC,
172
+ isOutdial,
173
+ wxAppAcceptInFlight: ctx.getWxAppAcceptInFlight(),
174
+ wxAppAnswerPending: ctx.getWxAppAnswerPending(),
175
+ enableWxBetterTogether: ctx.getEnableWxBetterTogether(),
176
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
177
+ });
178
+
179
+ this.lastLoggedWxAppParticipantMismatch = true;
180
+
181
+ logWxAppOfferParticipantMismatch({
182
+ interactionId: ctx.getInteractionId(),
183
+ usersubPublished,
184
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
185
+ hasDeviceId: participantDiagnostics.hasDeviceId,
186
+ participantDeviceType: participantDiagnostics.participantDeviceType,
187
+ acceptVisible: accept.isVisible,
188
+ acceptEnabled: accept.isEnabled,
189
+ acceptReason,
190
+ });
191
+
192
+ ctx.getMetricsManager().trackEvent(
193
+ METRIC_EVENT_NAMES.WXAPP_OFFER_PARTICIPANT_FIELDS_MISSING,
194
+ {
195
+ taskId: ctx.getInteractionId(),
196
+ usersubPublished,
197
+ hasDeviceCallId: participantDiagnostics.hasDeviceCallId,
198
+ hasDeviceId: participantDiagnostics.hasDeviceId,
199
+ acceptReason,
200
+ },
201
+ ['operational', 'behavioral']
202
+ );
203
+ }
204
+ }