amazon-connect-reference-dialer 1.0.0 → 1.4.2

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.

Potentially problematic release.


This version of amazon-connect-reference-dialer might be problematic. Click here for more details.

Files changed (239) hide show
  1. package/.babelrc +10 -0
  2. package/.eslintrc +24 -0
  3. package/Dockerfile +12 -0
  4. package/LICENSE +21 -0
  5. package/README.md +8 -0
  6. package/README.salesforce.md +50 -0
  7. package/config/appconfig.json +10 -0
  8. package/config/config.js +46 -0
  9. package/docker-compose.yml +16 -0
  10. package/index.js +46 -0
  11. package/nodemon.json +3 -0
  12. package/package.json +5 -4
  13. package/src/client/App.js +20 -0
  14. package/src/client/api/acManager.js +79 -0
  15. package/src/client/api/agentHandler.js +46 -0
  16. package/src/client/api/audioFrequencyMonitor.js +62 -0
  17. package/src/client/api/csioHandler.js +204 -0
  18. package/src/client/api/databaseManager.js +59 -0
  19. package/src/client/api/eventhandler.js +278 -0
  20. package/src/client/api/feedbackHandler.js +21 -0
  21. package/src/client/api/manager/agent.js +203 -0
  22. package/src/client/api/manager/connection.js +181 -0
  23. package/src/client/api/manager/contact.js +114 -0
  24. package/src/client/api/mediaManager.js +138 -0
  25. package/src/client/api/networkStrengthMonitor.js +64 -0
  26. package/src/client/api/precalltest.js +37 -0
  27. package/src/client/api/sessionManager.js +312 -0
  28. package/src/client/configs/consts.js +158 -0
  29. package/src/client/container/agentduration/duration.js +63 -0
  30. package/src/client/container/agentduration/index.js +3 -0
  31. package/src/client/container/agentview/conferenceconnection/agentview.css +100 -0
  32. package/src/client/container/agentview/conferenceconnection/components/bothhold.js +20 -0
  33. package/src/client/container/agentview/conferenceconnection/components/bothjoined.js +25 -0
  34. package/src/client/container/agentview/conferenceconnection/components/dialnumber.js +21 -0
  35. package/src/client/container/agentview/conferenceconnection/components/holdall.js +20 -0
  36. package/src/client/container/agentview/conferenceconnection/components/join.js +21 -0
  37. package/src/client/container/agentview/conferenceconnection/components/oneHoldOtherConnected.js +37 -0
  38. package/src/client/container/agentview/conferenceconnection/components/resumeall.js +21 -0
  39. package/src/client/container/agentview/conferenceconnection/components/swap.js +21 -0
  40. package/src/client/container/agentview/conferenceconnection/components/togglemute.js +23 -0
  41. package/src/client/container/agentview/conferenceconnection/index.js +3 -0
  42. package/src/client/container/agentview/conferenceconnection/lowerBody.js +154 -0
  43. package/src/client/container/agentview/conferenceconnection/main.js +22 -0
  44. package/src/client/container/agentview/conferenceconnection/primaryconnection.js +109 -0
  45. package/src/client/container/agentview/conferenceconnection/quickFeedback.js +118 -0
  46. package/src/client/container/agentview/conferenceconnection/thirdpartyconnection.js +107 -0
  47. package/src/client/container/agentview/conferenceconnection/upperBody.js +36 -0
  48. package/src/client/container/agentview/footer.js +190 -0
  49. package/src/client/container/agentview/index.js +3 -0
  50. package/src/client/container/agentview/main.js +39 -0
  51. package/src/client/container/agentview/primaryconnection/agentMutedLabel.js +23 -0
  52. package/src/client/container/agentview/primaryconnection/agentStatusAndAudioLabel.js +28 -0
  53. package/src/client/container/agentview/primaryconnection/agentview.css +73 -0
  54. package/src/client/container/agentview/primaryconnection/index.js +3 -0
  55. package/src/client/container/agentview/primaryconnection/lowerBody.js +159 -0
  56. package/src/client/container/agentview/primaryconnection/main.js +22 -0
  57. package/src/client/container/agentview/primaryconnection/peerAndAgentDuration.js +48 -0
  58. package/src/client/container/agentview/primaryconnection/quickFeedback.js +123 -0
  59. package/src/client/container/agentview/primaryconnection/upperBody.js +59 -0
  60. package/src/client/container/agentview/thirdparyconnection/agentMutedLabel.js +23 -0
  61. package/src/client/container/agentview/thirdparyconnection/agentStatusAndAudioLabel.js +28 -0
  62. package/src/client/container/agentview/thirdparyconnection/agentview.css +73 -0
  63. package/src/client/container/agentview/thirdparyconnection/index.js +3 -0
  64. package/src/client/container/agentview/thirdparyconnection/lowerBody.js +139 -0
  65. package/src/client/container/agentview/thirdparyconnection/main.js +22 -0
  66. package/src/client/container/agentview/thirdparyconnection/peerAndAgentDuration.js +49 -0
  67. package/src/client/container/agentview/thirdparyconnection/quickFeedback.js +118 -0
  68. package/src/client/container/agentview/thirdparyconnection/upperBody.js +59 -0
  69. package/src/client/container/audiolabelview/controller.js +104 -0
  70. package/src/client/container/audiolabelview/localaudiolevel.js +157 -0
  71. package/src/client/container/audiolabelview/noaudio.js +86 -0
  72. package/src/client/container/audiolabelview/remoteaudiolevel.js +110 -0
  73. package/src/client/container/audiolabelview/settingpageaudiolevel.js +154 -0
  74. package/src/client/container/common/contactField.js +30 -0
  75. package/src/client/container/common/each.contact.js +41 -0
  76. package/src/client/container/common/findContact.js +31 -0
  77. package/src/client/container/connectivitycheckview/body.js +113 -0
  78. package/src/client/container/connectivitycheckview/components/fractionalLoss.js +57 -0
  79. package/src/client/container/connectivitycheckview/components/mediaConnectivity.js +41 -0
  80. package/src/client/container/connectivitycheckview/components/roundTripTime.js +57 -0
  81. package/src/client/container/connectivitycheckview/components/rttgraph/rttgraph.js +176 -0
  82. package/src/client/container/connectivitycheckview/components/rttgraph/utils.js +96 -0
  83. package/src/client/container/connectivitycheckview/components/throughput.js +53 -0
  84. package/src/client/container/connectivitycheckview/components/throughputMessage.js +36 -0
  85. package/src/client/container/connectivitycheckview/connectivitycheck.css +44 -0
  86. package/src/client/container/connectivitycheckview/footer.js +43 -0
  87. package/src/client/container/connectivitycheckview/index.js +3 -0
  88. package/src/client/container/connectivitycheckview/loading/loading.css +73 -0
  89. package/src/client/container/connectivitycheckview/loading/loading.js +15 -0
  90. package/src/client/container/connectivitycheckview/main.js +19 -0
  91. package/src/client/container/dialerview/body.js +135 -0
  92. package/src/client/container/dialerview/dialpad.css +104 -0
  93. package/src/client/container/dialerview/dialpad.js +29 -0
  94. package/src/client/container/dialerview/index.js +3 -0
  95. package/src/client/container/dialerview/main.js +19 -0
  96. package/src/client/container/errors/error.css +30 -0
  97. package/src/client/container/errors/error.js +58 -0
  98. package/src/client/container/errors/index.js +3 -0
  99. package/src/client/container/footer/components/acceptOrReject.js +26 -0
  100. package/src/client/container/footer/components/availableOrEnd.js +28 -0
  101. package/src/client/container/footer/components/connectivitycheck.js +21 -0
  102. package/src/client/container/footer/components/downloadlogs.js +23 -0
  103. package/src/client/container/footer/components/info.js +22 -0
  104. package/src/client/container/footer/components/language.js +22 -0
  105. package/src/client/container/footer/components/reportcall.js +35 -0
  106. package/src/client/container/footer/components/version.js +22 -0
  107. package/src/client/container/header/header.css +46 -0
  108. package/src/client/container/header/header.js +135 -0
  109. package/src/client/container/header/index.js +3 -0
  110. package/src/client/container/home.js +129 -0
  111. package/src/client/container/login/body.js +67 -0
  112. package/src/client/container/login/ccpinputbox.js +23 -0
  113. package/src/client/container/login/footer.js +19 -0
  114. package/src/client/container/login/index.js +2 -0
  115. package/src/client/container/login/login.css +134 -0
  116. package/src/client/container/login/main.js +23 -0
  117. package/src/client/container/networkstrengthview/index.js +3 -0
  118. package/src/client/container/networkstrengthview/loading/loading.css +74 -0
  119. package/src/client/container/networkstrengthview/loading/loading.js +15 -0
  120. package/src/client/container/networkstrengthview/networkstrength.js +102 -0
  121. package/src/client/container/popups/confirmreport/confirmreport.css +47 -0
  122. package/src/client/container/popups/confirmreport/confirmreport.js +55 -0
  123. package/src/client/container/popups/quality/quality.css +32 -0
  124. package/src/client/container/popups/quality/quality.js +44 -0
  125. package/src/client/container/quickconnects/body.js +141 -0
  126. package/src/client/container/quickconnects/close.js +23 -0
  127. package/src/client/container/quickconnects/index.js +3 -0
  128. package/src/client/container/quickconnects/main.js +18 -0
  129. package/src/client/container/quickconnects/quickconnects.css +95 -0
  130. package/src/client/container/reportissueview/body.js +73 -0
  131. package/src/client/container/reportissueview/feedbackRatings.js +37 -0
  132. package/src/client/container/reportissueview/footer.js +20 -0
  133. package/src/client/container/reportissueview/index.js +3 -0
  134. package/src/client/container/reportissueview/issueNotes.js +22 -0
  135. package/src/client/container/reportissueview/issues.js +44 -0
  136. package/src/client/container/reportissueview/main.js +105 -0
  137. package/src/client/container/reportissueview/predefinedIssues.js +38 -0
  138. package/src/client/container/reportissueview/reportissue.css +102 -0
  139. package/src/client/container/settingsview/body.js +156 -0
  140. package/src/client/container/settingsview/components/audiooutputdevice.js +25 -0
  141. package/src/client/container/settingsview/components/deskphone.js +29 -0
  142. package/src/client/container/settingsview/components/desktopsettings.js +38 -0
  143. package/src/client/container/settingsview/components/dropdown-options.js +44 -0
  144. package/src/client/container/settingsview/components/phonetype.js +14 -0
  145. package/src/client/container/settingsview/components/settings.js +23 -0
  146. package/src/client/container/settingsview/components/softphone.js +30 -0
  147. package/src/client/container/settingsview/components/softphonesettings.js +35 -0
  148. package/src/client/container/settingsview/footer.js +96 -0
  149. package/src/client/container/settingsview/index.js +3 -0
  150. package/src/client/container/settingsview/main.js +20 -0
  151. package/src/client/container/settingsview/settings.css +126 -0
  152. package/src/client/container/statechangeview/body.js +61 -0
  153. package/src/client/container/statechangeview/footer.js +43 -0
  154. package/src/client/container/statechangeview/index.js +3 -0
  155. package/src/client/container/statechangeview/main.js +21 -0
  156. package/src/client/container/statechangeview/statuschange.css +47 -0
  157. package/src/client/container/transfercall/body.js +139 -0
  158. package/src/client/container/transfercall/close.js +23 -0
  159. package/src/client/container/transfercall/index.js +3 -0
  160. package/src/client/container/transfercall/main.js +18 -0
  161. package/src/client/container/transfercall/transfercall.css +99 -0
  162. package/src/client/index.js +13 -0
  163. package/src/client/reducers/acReducer.js +277 -0
  164. package/src/client/reducers/reducer.js +8 -0
  165. package/src/client/reducers.js +2 -0
  166. package/src/client/res/images/agent-voice-freq-icon.svg +61 -0
  167. package/src/client/res/images/change-status-icon.svg +16 -0
  168. package/src/client/res/images/csio-logo.png +0 -0
  169. package/src/client/res/images/csioLogo.png +0 -0
  170. package/src/client/res/images/dialer-setting-icon.svg +15 -0
  171. package/src/client/res/images/fa-circle-mark.svg +3 -0
  172. package/src/client/res/images/fa-circle-unmark.svg +3 -0
  173. package/src/client/res/images/fa-close-or-dismiss.svg +17 -0
  174. package/src/client/res/images/fa-danger.svg +3 -0
  175. package/src/client/res/images/fa-dial-button.svg +13 -0
  176. package/src/client/res/images/fa-dial-number.svg +15 -0
  177. package/src/client/res/images/fa-download.svg +3 -0
  178. package/src/client/res/images/fa-hold.svg +13 -0
  179. package/src/client/res/images/fa-ico-join.svg +27 -0
  180. package/src/client/res/images/fa-ico-swap.svg +27 -0
  181. package/src/client/res/images/fa-info.svg +3 -0
  182. package/src/client/res/images/fa-input-sound.svg +5 -0
  183. package/src/client/res/images/fa-language.svg +3 -0
  184. package/src/client/res/images/fa-mark-false.svg +3 -0
  185. package/src/client/res/images/fa-mark-true.svg +3 -0
  186. package/src/client/res/images/fa-mic-freq-temporary.gif +0 -0
  187. package/src/client/res/images/fa-mic.svg +3 -0
  188. package/src/client/res/images/fa-mini-endcall.svg +48 -0
  189. package/src/client/res/images/fa-mini-hold.svg +47 -0
  190. package/src/client/res/images/fa-mini-resume.svg +45 -0
  191. package/src/client/res/images/fa-mute.svg +13 -0
  192. package/src/client/res/images/fa-network-strength-1.svg +5 -0
  193. package/src/client/res/images/fa-network-strength-2.svg +6 -0
  194. package/src/client/res/images/fa-network-strength-3.svg +6 -0
  195. package/src/client/res/images/fa-network-strength-4.svg +6 -0
  196. package/src/client/res/images/fa-network-strength-5.svg +5 -0
  197. package/src/client/res/images/fa-network-strength-unknown-2.svg +9 -0
  198. package/src/client/res/images/fa-network-strength-unknown.svg +6 -0
  199. package/src/client/res/images/fa-quick-connect.svg +15 -0
  200. package/src/client/res/images/fa-refresh.svg +3 -0
  201. package/src/client/res/images/fa-resume.svg +3 -0
  202. package/src/client/res/images/fa-return.svg +3 -0
  203. package/src/client/res/images/fa-three-dots.svg +32 -0
  204. package/src/client/res/images/fa-tick-green.svg +3 -0
  205. package/src/client/res/images/fa-tick-mark.svg +3 -0
  206. package/src/client/res/images/fa-transfer.svg +3 -0
  207. package/src/client/res/images/fa-version.svg +4 -0
  208. package/src/client/res/images/fa-voice-no-freq.svg +5 -0
  209. package/src/client/res/images/favicon.ico +0 -0
  210. package/src/client/res/images/muted-icon.svg +13 -0
  211. package/src/client/res/images/network-strength-icon.svg +13 -0
  212. package/src/client/res/images/peer-voice-freq-icon.svg +26 -0
  213. package/src/client/res/images/star-white.svg +6 -0
  214. package/src/client/res/images/star-yellow.svg +6 -0
  215. package/src/client/res/scss/global.css +14 -0
  216. package/src/client/router.js +17 -0
  217. package/src/client/store.js +11 -0
  218. package/src/client/utils/acutils.js +114 -0
  219. package/src/client/utils/agetStateMap.js +36 -0
  220. package/src/client/utils/feedback.js +3 -0
  221. package/src/client/utils/initialStateManager.js +14 -0
  222. package/src/server/index.js +53 -0
  223. package/src/server/logger.js +93 -0
  224. package/src/server/public/fonts/AmazonEmber_Lt.ttf +0 -0
  225. package/src/server/public/fonts/AmazonEmber_Rg.ttf +0 -0
  226. package/src/server/public/img/favicon.ico +0 -0
  227. package/src/server/public/js/amazon-connect-pre-shim.js +2 -0
  228. package/src/server/router/compare.js +36 -0
  229. package/src/server/router/index.js +36 -0
  230. package/src/server/router/stock.js +33 -0
  231. package/src/server/views/_heap_prod.ejs +8 -0
  232. package/src/server/views/_hotjar_prod.ejs +14 -0
  233. package/src/server/views/_hotjar_test.ejs +12 -0
  234. package/src/server/views/compare.ejs +69 -0
  235. package/src/server/views/index.ejs +69 -0
  236. package/src/server/views/stock.ejs +101 -0
  237. package/webpack.common.config.js +48 -0
  238. package/webpack.dev.config.js +21 -0
  239. package/webpack.prod.config.js +10 -0
@@ -0,0 +1,204 @@
1
+ 'use strict';
2
+ import networkStrengthMonitor from './networkStrengthMonitor';
3
+ import audioFrequencyMonitor from './audioFrequencyMonitor';
4
+
5
+ import lo from 'lodash';
6
+ import databaseManager from './databaseManager';
7
+ import {
8
+ getRandomInt
9
+ } from './../utils/acutils';
10
+ import mediaManager from './mediaManager';
11
+
12
+ const appId = APP_ID || WEB_PACK_APP_ID;
13
+ const appSecret = APP_SECRET || WEB_PACK_APP_SECRET;
14
+ const enableJabraCollection = ENABLE_JABRA_COLLECTION === 'enable';
15
+ const siteIds = ['HQ', 'Remote', 'Home'];
16
+
17
+ const ccpUrl = () => {
18
+ const connectURL = databaseManager.getDefaultConnectURL(CONNECT_URL || WEB_PACK_CONNECT_URL);
19
+ return `https://${connectURL}/connect/ccp#/`;
20
+ };
21
+
22
+ class CSIOHandler {
23
+ constructor () {
24
+ this.callstatsac = undefined;
25
+ this.dispatch = undefined;
26
+ this.localUserId = undefined;
27
+ // eslint-disable-next-line new-cap
28
+ this.agentMonitor = new callstatsAgentMonitor();
29
+ }
30
+
31
+ /**
32
+ * @private
33
+ * @return {string} Return a site id from given site id list
34
+ */
35
+ getRandomSiteId () {
36
+ return siteIds[ getRandomInt(1, siteIds.length) - 1 ];
37
+ }
38
+ // eslint-disable-next-line handle-callback-err
39
+ onCSIOInitialize (err, msg) {
40
+ // console.warn('->', 'onCSIOInitialize', new Date(), err, msg);
41
+ }
42
+
43
+ onCSIOStats (stats) {
44
+ // console.warn('->onCSIOStats', stats);
45
+ if (stats && stats.fabricState === 'terminated') {
46
+ return;
47
+ }
48
+
49
+ if (stats && stats.mediaStreamTracks) {
50
+ let track1 = lo.first(stats.mediaStreamTracks);
51
+ let track2 = lo.last(stats.mediaStreamTracks);
52
+
53
+ // console.warn('~', stats);
54
+ let audioIntputLevel = parseInt(track1.audioIntputLevel || track2.audioIntputLevel || 0, 10);
55
+ let audioOutputLevel = parseInt(track1.audioOutputLevel || track2.audioOutputLevel || 0, 10);
56
+
57
+ let track1Bitrate = parseInt(track1.bitrate || 0, 10);
58
+ let track2Bitrate = parseInt(track2.bitrate || 0, 10);
59
+ let track1RTT = parseInt(track1.rtt || 0, 10);
60
+ // no rtt for inbound tracks.
61
+ // let track2RTT = parseInt(track1.rtt || 0, 10);
62
+
63
+ let track1Fl = parseInt(track1.fractionLoss || 0, 10);
64
+ let track2Fl = parseInt(track2.fractionLoss || 0, 10);
65
+
66
+ // console.warn('-> ', 'on csio stats', stats);
67
+ networkStrengthMonitor.addThroughput(track1Bitrate, track2Bitrate);
68
+ networkStrengthMonitor.addRTT(track1RTT, track1RTT);
69
+ networkStrengthMonitor.addRTT(track1Fl, track2Fl);
70
+ audioFrequencyMonitor.addAudioLevel(audioIntputLevel, false);
71
+ audioFrequencyMonitor.addAudioLevel(audioOutputLevel, true);
72
+ }
73
+ }
74
+
75
+ getRemoteStream () {
76
+ const pc = CallstatsAmazonShim && CallstatsAmazonShim.getPeerConnection();
77
+ if (!pc) {
78
+ return undefined;
79
+ }
80
+ const remoteStreams = pc.getRemoteStreams();
81
+ return remoteStreams && lo.get(remoteStreams, 0, undefined);
82
+ }
83
+
84
+ doPrecallTest () {
85
+ return new Promise((resolve) => {
86
+ if (CallstatsAmazonShim) {
87
+ CallstatsAmazonShim.makePrecallTest((status, result) => {
88
+ // console.warn('-> ', 'on precall test', status, result);
89
+ let testResult = databaseManager.savePrecalltestResult(result);
90
+
91
+ let throughput = lo.get(result, 'throughput', 0);
92
+ let rtt = lo.get(result, 'rtt', 0);
93
+ let fractionalLoss = lo.get(result, 'fractionalLoss', 0);
94
+ networkStrengthMonitor.addThroughput(throughput, throughput);
95
+ networkStrengthMonitor.addRTT(rtt, rtt);
96
+ networkStrengthMonitor.addFractionalLoss(fractionalLoss, fractionalLoss);
97
+ resolve(testResult);
98
+ });
99
+ }
100
+ });
101
+ }
102
+
103
+ onCSIORecommendedConfigCallback (config) {
104
+ // console.warn('->', 'onCSIORecommendedConfigCallback', new Date(), config);
105
+ }
106
+
107
+ onCSIOPrecalltestCallback (status, result) {
108
+ // console.warn('-> ', 'on precall test', status, result);
109
+ databaseManager.savePrecalltestResult(result);
110
+ let throughput = lo.get(result, 'throughput', 0);
111
+ let rtt = lo.get(result, 'rtt', 0);
112
+ let fractionalLoss = lo.get(result, 'fractionalLoss', 0);
113
+ networkStrengthMonitor.addThroughput(throughput, throughput);
114
+ networkStrengthMonitor.addRTT(rtt, rtt);
115
+ networkStrengthMonitor.addFractionalLoss(fractionalLoss, fractionalLoss);
116
+ }
117
+
118
+ dispose () {
119
+ this.dispatch = undefined;
120
+ }
121
+
122
+ register (dispatch = undefined, agent = undefined) {
123
+ this.dispatch && this.dispose();
124
+ this.dispatch = dispatch;
125
+
126
+ if (!agent) {
127
+ // console.error('agent object cannot be empty');
128
+ return;
129
+ }
130
+ if (!CallstatsAmazonShim) {
131
+ // console.error('CallstatsAmazonShim object cannot be empty');
132
+ return;
133
+ }
134
+ const localUserId = agent.getName();
135
+ this.localUserId = localUserId;
136
+ const configParams = {
137
+ siteID: this.getRandomSiteId(),
138
+ enableJabraCollection: enableJabraCollection
139
+ };
140
+
141
+ if (this.callstatsac) {
142
+ this.callstatsac = undefined;
143
+ }
144
+
145
+ this.callstatsac = CallstatsAmazonShim.initialize(connect, appId, appSecret, localUserId, configParams, this.onCSIOInitialize, this.onCSIOStats);
146
+ this.callstatsac.on('recommendedConfig', this.onCSIORecommendedConfigCallback.bind(this));
147
+ this.callstatsac.on('preCallTestResults', this.onCSIOPrecalltestCallback.bind(this));
148
+
149
+ // add agent monitor
150
+ if (this.agentMonitor && typeof this.agentMonitor.initialize === 'function') {
151
+ this.agentMonitor.initialize(connect, ccpUrl(), appId, appSecret, localUserId, configParams);
152
+ }
153
+ }
154
+
155
+ // Quick hack to send feedback in structural way before we have a API for that
156
+ postProcessFeedback (feedbackJSON = {}) {
157
+ let markedFeedback = [];
158
+ for (let currentIssue of feedbackJSON.issueList || []) {
159
+ for (let issue of currentIssue.items || []) {
160
+ if (issue.marked === true) {
161
+ markedFeedback.push(issue.text);
162
+ }
163
+ }
164
+ }
165
+ return markedFeedback;
166
+ }
167
+
168
+ sendFeedback (feedbackJSON = {}) {
169
+ let markedFeedbackList = this.postProcessFeedback(feedbackJSON);
170
+ let feedbackText = `${[feedbackJSON.feedbackText, ...markedFeedbackList].join(' ,')}`;
171
+ const feedback = {
172
+ userId: this.localUserId,
173
+ overall: Math.max(feedbackJSON.feedbackRatings, 1),
174
+ comment: feedbackText
175
+ };
176
+ CallstatsAmazonShim.sendUserFeedback(feedback, msg => {
177
+ // console.warn('on submitted feedback ', msg);
178
+ });
179
+ }
180
+
181
+ sendFeedbackRating (feedbackRating = 1) {
182
+ const feedback = {
183
+ userId: this.localUserId,
184
+ overall: Math.max(feedbackRating, 1)
185
+ };
186
+ CallstatsAmazonShim.sendUserFeedback(feedback, msg => {
187
+ // console.warn('on submitted rating ', msg);
188
+ });
189
+ }
190
+
191
+ sendActiveDeviceList () {
192
+ mediaManager.getDefaultOrPreferredAudioInputDevice()
193
+ .then(activeAudioDevice => {
194
+ const eventData = {
195
+ deviceList: [activeAudioDevice]
196
+ };
197
+ CallstatsAmazonShim.sendFabricEvent(this.callstatsac.fabricEvent.activeDeviceList, eventData);
198
+ })
199
+ .catch(() => {});
200
+ }
201
+ }
202
+
203
+ const csioHandler = new CSIOHandler();
204
+ export default csioHandler;
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+
3
+ const maxElement = 500;
4
+
5
+ class DatabaseManager {
6
+ // eslint-disable-next-line no-useless-constructor
7
+ constructor () {
8
+ }
9
+
10
+ savePrecalltestResult (result) {
11
+ const epochTime = (new Date()).getTime();
12
+ let retval = this.getPrecallTestResult();
13
+ if (retval) {
14
+ if (retval.length > maxElement) {
15
+ retval.shift();
16
+ }
17
+ retval.push({ ...result, epochTime });
18
+ }
19
+
20
+ window.localStorage.setItem('rttResult', JSON.stringify(retval));
21
+ return retval;
22
+ }
23
+
24
+ getPrecallTestResult () {
25
+ let result = window.localStorage.getItem('rttResult') || undefined;
26
+ if (result) {
27
+ return JSON.parse(result);
28
+ }
29
+ return [];
30
+ }
31
+
32
+ saveDefaultDevice (defaultAudioDevice = undefined) {
33
+ window.localStorage.setItem('defaultDevice', JSON.stringify(defaultAudioDevice));
34
+ }
35
+
36
+ getSelectedAudioDevice () {
37
+ return window.localStorage.getItem('defaultDevice') || undefined;
38
+ }
39
+
40
+ setDefaultConnectURL (ccpURL = '') {
41
+ window.localStorage.setItem('defaultConnectURL', ccpURL);
42
+ return ccpURL;
43
+ }
44
+
45
+ getDefaultConnectURL (ccpURL = '') {
46
+ return window.localStorage.getItem('defaultConnectURL') || ccpURL || undefined;
47
+ }
48
+
49
+ setDefaultCountry (defaultCountry = '') {
50
+ window.localStorage.setItem('defaultCountry', defaultCountry);
51
+ }
52
+
53
+ getDefaultCountry () {
54
+ return window.localStorage.getItem('defaultCountry');
55
+ }
56
+ }
57
+
58
+ const databaseManager = new DatabaseManager();
59
+ export default databaseManager;
@@ -0,0 +1,278 @@
1
+ import {
2
+ onCCPError,
3
+ onInitializationStateChange,
4
+ onRemoteStream,
5
+ onStateChange
6
+ } from '../reducers/acReducer';
7
+
8
+ import {
9
+ isCallbackMissed
10
+ } from '../utils/acutils';
11
+
12
+ import csioHandler from './csioHandler';
13
+ import acManager from './acManager';
14
+ import sessionManage from './sessionManager';
15
+ import mediaManager from './mediaManager';
16
+
17
+ // Outbound call = connection.isActive() && connection.isConnecting() && connection.getType() === 'outbound'
18
+ // Incoming call = connection.isActive() && connection.isConnecting() && connection.getType() === 'inbound'
19
+ // Connected = connection.isActive() && connection.isConnected() && isMultipartyCall() === false;
20
+ // Joined = connection.isActive() && connection.isConnected() && isMultipartyCall();
21
+ // Hold = connection.isActive() && connection.isOnHold()
22
+ // Duration = connection.isActive() && connection.getState() && connection.getState().duration
23
+
24
+ let currentAgent;
25
+ let currentContact;
26
+ let currentState;
27
+
28
+ const knownAgentStates = ['Init', 'Default', 'Available', 'Offline', 'AfterCallWork', 'FailedConnectCustomer', 'FailedConnectAgent', 'Quality Issue', 'AgentHungUp'];
29
+ const isError = (e) => {
30
+ if (e && e.errorType && e.errorMessage) {
31
+ return true;
32
+ }
33
+ };
34
+
35
+ const getAgentState = (e) => {
36
+ let { agent, newState } = e;
37
+ const currentAgentStates = sessionManage.getAgentStates();
38
+ // merge the known state and dynamic agent states
39
+ const agentStates = [ ...knownAgentStates, ...currentAgentStates.map(state => state.name) ];
40
+ if (!agentStates.includes(newState)) {
41
+ return undefined;
42
+ }
43
+ const duration = agent.getStateDuration();
44
+ if (isCallbackMissed(agent, newState)) {
45
+ newState = 'Callback missed';
46
+ }
47
+ return {
48
+ state: newState,
49
+ duration: duration,
50
+ agent: agent
51
+ };
52
+ };
53
+
54
+ // eslint-disable-next-line no-unused-vars
55
+ const isMultipartyCall = (contact) => {
56
+ return !!((contact && contact.getActiveInitialConnection() && contact.getSingleActiveThirdPartyConnection()));
57
+ };
58
+
59
+ const isAgentError = (agent = undefined) => {
60
+ const agentState = agent && agent.getState();
61
+ return agentState && agentState.type === 'error';
62
+ };
63
+ const isOutbound = (connection) => {
64
+ return connection && connection.isActive() && connection.isConnected() === false &&
65
+ connection.isConnecting() === true && connection.getType() === 'outbound';
66
+ };
67
+
68
+ const isInbound = (connection) => {
69
+ return connection && connection.isActive() && connection.isConnected() &&
70
+ connection.getType() === 'inbound' &&
71
+ currentAgent.agent.getState().name === 'PendingBusy';
72
+ };
73
+
74
+ const isConnecting = (connection) => {
75
+ return connection && connection.isActive() && connection.isConnected() === false &&
76
+ connection.isConnecting() === true && connection.getType() === 'inbound' &&
77
+ currentAgent.agent.getState().name === 'CallingCustomer';
78
+ };
79
+
80
+ const isInboundCallback = (connection) => {
81
+ return connection && connection.isActive() && connection.isConnected() &&
82
+ connection.getType() === 'inbound' &&
83
+ currentAgent.agent.getState().name === 'Pending';
84
+ };
85
+
86
+ const isMissedCall = (connection) => {
87
+ return connection && connection.isActive() && connection.isConnected() &&
88
+ connection.getType() === 'inbound' &&
89
+ currentAgent.agent.getState().name === 'MissedCallAgent';
90
+ };
91
+
92
+ const isConnected = (connection) => {
93
+ return connection && connection.isActive() && connection.isConnected() &&
94
+ currentAgent.agent.getState().name === 'Busy';
95
+ };
96
+
97
+ const isJoined = (primaryConnectionState, thirdPartyConnectionState) => {
98
+ return primaryConnectionState && thirdPartyConnectionState &&
99
+ ['connected', 'Connected'].includes(primaryConnectionState.state) &&
100
+ primaryConnectionState.state === thirdPartyConnectionState.state;
101
+ };
102
+
103
+ const isHold = (connection) => {
104
+ return connection && connection.isActive() && connection.isOnHold();
105
+ };
106
+
107
+ const getStateDuration = (connection) => {
108
+ let duration = connection && connection.getStatusDuration();
109
+ return duration;
110
+ };
111
+
112
+ const getConnectionState = (contact = undefined, isPrimary = true) => {
113
+ const connection = isPrimary ? contact.getActiveInitialConnection() : contact.getSingleActiveThirdPartyConnection();
114
+ if (!connection) {
115
+ return undefined;
116
+ }
117
+ // console.warn('~', connection.isActive(), connection.isConnected(), connection.isConnecting(), connection.getType(), currentAgent.agent.getState());
118
+ let state;
119
+ if (isOutbound(connection)) {
120
+ state = 'Outbound call';
121
+ } else if (isInbound(connection)) {
122
+ state = 'Inbound call';
123
+ } else if (isMissedCall(connection)) {
124
+ state = 'Missed call';
125
+ } else if (isConnected(connection)) {
126
+ state = 'Connected';
127
+ } else if (isHold(connection)) {
128
+ state = 'On hold';
129
+ } else if (isInboundCallback(connection)) {
130
+ state = 'Callback incoming';
131
+ } else if (isConnecting(connection)) {
132
+ state = 'Connecting';
133
+ }
134
+
135
+ let duration = getStateDuration(connection);
136
+ return {
137
+ state: state,
138
+ duration: duration,
139
+ connection: connection
140
+ };
141
+ };
142
+
143
+ const mayBeUpdateToJoined = (primaryConnectionState = undefined, thirdPartyConnectionState = undefined) => {
144
+ if (isJoined(primaryConnectionState, thirdPartyConnectionState)) {
145
+ primaryConnectionState.state = 'Joined';
146
+ thirdPartyConnectionState.state = 'Joined';
147
+ }
148
+ return {
149
+ primaryConnectionState,
150
+ thirdPartyConnectionState
151
+ };
152
+ };
153
+
154
+ class EventHandler {
155
+ constructor () {
156
+ this.dispatch = undefined;
157
+ }
158
+
159
+ dispose () {
160
+ this.dispatch = undefined;
161
+ }
162
+
163
+ register (dispatch, connect) {
164
+ if (this.dispatch) {
165
+ this.dispose();
166
+ }
167
+ this.dispatch = dispatch;
168
+
169
+ if (connect && connect.core) {
170
+ let bus = connect.core.getEventBus();
171
+
172
+ bus.subscribe('<<all>>', e => {
173
+ if (isError(e)) {
174
+ this.dispatch(onCCPError({ ...e }));
175
+ }
176
+ });
177
+
178
+ // get the agent init to set logged in
179
+ bus.subscribe(connect.AgentEvents.INIT, (e) => {
180
+ // close the login window, since at this stage agent is already initialized
181
+ sessionManage.disposeLoginWindow();
182
+ acManager.setIsLoggedIn(true);
183
+ this.dispatch(onInitializationStateChange(true));
184
+ });
185
+
186
+ // handle shared worker terminated to set agent logged out
187
+ bus.subscribe(connect.EventType.TERMINATED, (e) => {
188
+ acManager.setIsLoggedIn(false);
189
+ window.location.reload();
190
+ });
191
+ bus.subscribe(connect.AgentEvents.ERROR, e => {
192
+ // console.warn('error', e);
193
+ });
194
+ bus.subscribe(connect.AgentEvents.STATE_CHANGE, e => {
195
+ currentAgent = e;
196
+ // console.warn('~agent state change ', getAgentState(e));
197
+ let payload = {
198
+ primaryConnectionState: getAgentState(e),
199
+ thirdPartyConnectionState: undefined
200
+ };
201
+ currentState = payload;
202
+ this.dispatch(onStateChange(payload));
203
+ });
204
+ bus.subscribe(connect.ContactEvents.REFRESH, e => {
205
+ currentContact = e;
206
+ const connection1 = getConnectionState(e, true);
207
+ const connection2 = getConnectionState(e, false);
208
+ const { primaryConnectionState, thirdPartyConnectionState } = mayBeUpdateToJoined(connection1, connection2);
209
+ // console.warn('~REFRESH', primaryConnectionState, thirdPartyConnectionState, isMultipartyCall(e));
210
+ // if there is a agent side error
211
+ // ignore checking connections
212
+ const parseAgentState = () => {
213
+ if (isAgentError(currentAgent.agent)) {
214
+ const agentState = getAgentState(currentAgent);
215
+ if (!agentState) {
216
+ return undefined;
217
+ }
218
+ let payload = {
219
+ primaryConnectionState: agentState,
220
+ thirdPartyConnectionState: undefined
221
+ };
222
+ return payload;
223
+ }
224
+ return undefined;
225
+ };
226
+ const parseConnectState = () => {
227
+ let payload = {
228
+ primaryConnectionState: primaryConnectionState,
229
+ thirdPartyConnectionState: thirdPartyConnectionState
230
+ };
231
+ if ((primaryConnectionState && primaryConnectionState.state) || (thirdPartyConnectionState && thirdPartyConnectionState.state)) {
232
+ return payload;
233
+ }
234
+ return undefined;
235
+ };
236
+
237
+ const parseRest = () => {
238
+ let payload = {
239
+ primaryConnectionState: getAgentState(currentAgent),
240
+ thirdPartyConnectionState: undefined
241
+ };
242
+ return payload;
243
+ };
244
+ let payload = parseAgentState() || parseConnectState() || parseRest();
245
+ currentState = payload;
246
+ this.dispatch(onStateChange(payload));
247
+ });
248
+ bus.subscribe(connect.ContactEvents.ENDED, () => {
249
+ currentContact = undefined;
250
+ mediaManager.setRemoteStream(undefined);
251
+ });
252
+ bus.subscribe(connect.ContactEvents.DESTROYED, () => {
253
+ currentContact = undefined;
254
+ mediaManager.setRemoteStream(undefined);
255
+ });
256
+ bus.subscribe(connect.ContactEvents.CONNECTED, e => {
257
+ const remoteStream = csioHandler.getRemoteStream();
258
+ if (remoteStream) {
259
+ this.dispatch(onRemoteStream(remoteStream));
260
+ mediaManager.setRemoteStream(remoteStream);
261
+ }
262
+ // send active device list
263
+ csioHandler.sendActiveDeviceList();
264
+ });
265
+ }
266
+ }
267
+
268
+ getCurrentContact () {
269
+ return currentContact;
270
+ }
271
+
272
+ getCurrentState () {
273
+ return currentState;
274
+ }
275
+ }
276
+
277
+ const eventHandler = new EventHandler();
278
+ export default eventHandler;
@@ -0,0 +1,21 @@
1
+ class FeedbackHandler {
2
+ constructor () {
3
+ this.feedbackRatings = 0;
4
+ }
5
+
6
+ showFeedbackReports () {
7
+ return this.feedbackRatings >= 1 && this.feedbackRatings <= 3;
8
+ }
9
+
10
+ updateFeedback (feedbackRatings = 0) {
11
+ this.feedbackRatings = feedbackRatings;
12
+ return this.feedbackRatings;
13
+ }
14
+
15
+ getFeedbackRatings () {
16
+ return this.feedbackRatings;
17
+ }
18
+ }
19
+
20
+ const feedbackHandler = new FeedbackHandler();
21
+ export default feedbackHandler;