@webex/plugin-meetings 2.59.1 → 2.59.3-next.1

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 (417) hide show
  1. package/.eslintrc.js +6 -6
  2. package/LICENSE +1 -1
  3. package/README.md +1204 -1204
  4. package/UPGRADING.md +287 -287
  5. package/babel.config.js +3 -3
  6. package/browsers.js +108 -108
  7. package/dist/common/browser-detection.d.ts +9 -9
  8. package/dist/common/browser-detection.js.map +1 -1
  9. package/dist/common/collection.d.ts +48 -48
  10. package/dist/common/collection.js +43 -43
  11. package/dist/common/collection.js.map +1 -1
  12. package/dist/common/config.d.ts +2 -2
  13. package/dist/common/config.js.map +1 -1
  14. package/dist/common/errors/captcha-error.d.ts +15 -15
  15. package/dist/common/errors/captcha-error.js +7 -7
  16. package/dist/common/errors/captcha-error.js.map +1 -1
  17. package/dist/common/errors/intent-to-join.d.ts +16 -16
  18. package/dist/common/errors/intent-to-join.js +7 -7
  19. package/dist/common/errors/intent-to-join.js.map +1 -1
  20. package/dist/common/errors/join-meeting.d.ts +17 -17
  21. package/dist/common/errors/join-meeting.js +8 -8
  22. package/dist/common/errors/join-meeting.js.map +1 -1
  23. package/dist/common/errors/media.d.ts +15 -15
  24. package/dist/common/errors/media.js +7 -7
  25. package/dist/common/errors/media.js.map +1 -1
  26. package/dist/common/errors/parameter.d.ts +15 -15
  27. package/dist/common/errors/parameter.js +7 -7
  28. package/dist/common/errors/parameter.js.map +1 -1
  29. package/dist/common/errors/password-error.d.ts +15 -15
  30. package/dist/common/errors/password-error.js +7 -7
  31. package/dist/common/errors/password-error.js.map +1 -1
  32. package/dist/common/errors/permission.d.ts +14 -14
  33. package/dist/common/errors/permission.js +6 -6
  34. package/dist/common/errors/permission.js.map +1 -1
  35. package/dist/common/errors/reconnection-in-progress.d.ts +9 -9
  36. package/dist/common/errors/reconnection-in-progress.js +6 -6
  37. package/dist/common/errors/reconnection-in-progress.js.map +1 -1
  38. package/dist/common/errors/reconnection.d.ts +15 -15
  39. package/dist/common/errors/reconnection.js +7 -7
  40. package/dist/common/errors/reconnection.js.map +1 -1
  41. package/dist/common/errors/stats.d.ts +15 -15
  42. package/dist/common/errors/stats.js +7 -7
  43. package/dist/common/errors/stats.js.map +1 -1
  44. package/dist/common/errors/webex-errors.d.ts +81 -81
  45. package/dist/common/errors/webex-errors.js +42 -42
  46. package/dist/common/errors/webex-errors.js.map +1 -1
  47. package/dist/common/errors/webex-meetings-error.d.ts +20 -20
  48. package/dist/common/errors/webex-meetings-error.js +12 -12
  49. package/dist/common/errors/webex-meetings-error.js.map +1 -1
  50. package/dist/common/events/events-scope.d.ts +17 -17
  51. package/dist/common/events/events-scope.js +10 -10
  52. package/dist/common/events/events-scope.js.map +1 -1
  53. package/dist/common/events/events.d.ts +12 -12
  54. package/dist/common/events/events.js +4 -4
  55. package/dist/common/events/events.js.map +1 -1
  56. package/dist/common/events/trigger-proxy.d.ts +2 -2
  57. package/dist/common/events/trigger-proxy.js.map +1 -1
  58. package/dist/common/events/util.d.ts +2 -2
  59. package/dist/common/events/util.js.map +1 -1
  60. package/dist/common/logs/logger-config.d.ts +2 -2
  61. package/dist/common/logs/logger-config.js.map +1 -1
  62. package/dist/common/logs/logger-proxy.d.ts +2 -2
  63. package/dist/common/logs/logger-proxy.js.map +1 -1
  64. package/dist/common/logs/request.d.ts +34 -34
  65. package/dist/common/logs/request.js +18 -18
  66. package/dist/common/logs/request.js.map +1 -1
  67. package/dist/common/queue.d.ts +32 -32
  68. package/dist/common/queue.js +18 -18
  69. package/dist/common/queue.js.map +1 -1
  70. package/dist/config.d.ts +73 -73
  71. package/dist/config.js.map +1 -1
  72. package/dist/constants.d.ts +924 -924
  73. package/dist/constants.js +9 -9
  74. package/dist/constants.js.map +1 -1
  75. package/dist/controls-options-manager/constants.d.ts +4 -4
  76. package/dist/controls-options-manager/constants.js.map +1 -1
  77. package/dist/controls-options-manager/enums.d.ts +5 -5
  78. package/dist/controls-options-manager/enums.js.map +1 -1
  79. package/dist/controls-options-manager/index.d.ts +120 -120
  80. package/dist/controls-options-manager/index.js +81 -81
  81. package/dist/controls-options-manager/index.js.map +1 -1
  82. package/dist/controls-options-manager/util.d.ts +7 -7
  83. package/dist/controls-options-manager/util.js.map +1 -1
  84. package/dist/index.d.ts +4 -4
  85. package/dist/index.js.map +1 -1
  86. package/dist/locus-info/controlsUtils.d.ts +2 -2
  87. package/dist/locus-info/controlsUtils.js +21 -21
  88. package/dist/locus-info/controlsUtils.js.map +1 -1
  89. package/dist/locus-info/embeddedAppsUtils.d.ts +2 -2
  90. package/dist/locus-info/embeddedAppsUtils.js +14 -14
  91. package/dist/locus-info/embeddedAppsUtils.js.map +1 -1
  92. package/dist/locus-info/fullState.d.ts +2 -2
  93. package/dist/locus-info/fullState.js.map +1 -1
  94. package/dist/locus-info/hostUtils.d.ts +2 -2
  95. package/dist/locus-info/hostUtils.js +19 -19
  96. package/dist/locus-info/hostUtils.js.map +1 -1
  97. package/dist/locus-info/index.d.ts +269 -269
  98. package/dist/locus-info/index.js +180 -180
  99. package/dist/locus-info/index.js.map +1 -1
  100. package/dist/locus-info/infoUtils.d.ts +2 -2
  101. package/dist/locus-info/infoUtils.js.map +1 -1
  102. package/dist/locus-info/mediaSharesUtils.d.ts +2 -2
  103. package/dist/locus-info/mediaSharesUtils.js +50 -50
  104. package/dist/locus-info/mediaSharesUtils.js.map +1 -1
  105. package/dist/locus-info/parser.d.ts +212 -212
  106. package/dist/locus-info/parser.js +136 -136
  107. package/dist/locus-info/parser.js.map +1 -1
  108. package/dist/locus-info/selfUtils.d.ts +2 -2
  109. package/dist/locus-info/selfUtils.js +52 -52
  110. package/dist/locus-info/selfUtils.js.map +1 -1
  111. package/dist/media/index.d.ts +32 -32
  112. package/dist/media/index.js +145 -145
  113. package/dist/media/index.js.map +1 -1
  114. package/dist/media/properties.d.ts +108 -108
  115. package/dist/media/properties.js +49 -49
  116. package/dist/media/properties.js.map +1 -1
  117. package/dist/media/util.d.ts +2 -2
  118. package/dist/media/util.js.map +1 -1
  119. package/dist/mediaQualityMetrics/config.d.ts +233 -233
  120. package/dist/mediaQualityMetrics/config.js.map +1 -1
  121. package/dist/meeting/effectsState.d.ts +42 -42
  122. package/dist/meeting/effectsState.js +24 -24
  123. package/dist/meeting/effectsState.js.map +1 -1
  124. package/dist/meeting/in-meeting-actions.d.ts +79 -79
  125. package/dist/meeting/in-meeting-actions.js +11 -11
  126. package/dist/meeting/in-meeting-actions.js.map +1 -1
  127. package/dist/meeting/index.d.ts +1621 -1621
  128. package/dist/meeting/index.js +1502 -1505
  129. package/dist/meeting/index.js.map +1 -1
  130. package/dist/meeting/muteState.d.ts +116 -116
  131. package/dist/meeting/muteState.js +85 -85
  132. package/dist/meeting/muteState.js.map +1 -1
  133. package/dist/meeting/request.d.ts +255 -255
  134. package/dist/meeting/request.js +141 -141
  135. package/dist/meeting/request.js.map +1 -1
  136. package/dist/meeting/state.d.ts +9 -9
  137. package/dist/meeting/state.js +30 -30
  138. package/dist/meeting/state.js.map +1 -1
  139. package/dist/meeting/util.d.ts +2 -2
  140. package/dist/meeting/util.js.map +1 -1
  141. package/dist/meeting-info/collection.d.ts +20 -20
  142. package/dist/meeting-info/collection.js +11 -11
  143. package/dist/meeting-info/collection.js.map +1 -1
  144. package/dist/meeting-info/index.d.ts +57 -57
  145. package/dist/meeting-info/index.js +50 -50
  146. package/dist/meeting-info/index.js.map +1 -1
  147. package/dist/meeting-info/meeting-info-v2.d.ts +93 -93
  148. package/dist/meeting-info/meeting-info-v2.js +52 -52
  149. package/dist/meeting-info/meeting-info-v2.js.map +1 -1
  150. package/dist/meeting-info/request.d.ts +22 -22
  151. package/dist/meeting-info/request.js +14 -14
  152. package/dist/meeting-info/request.js.map +1 -1
  153. package/dist/meeting-info/util.d.ts +2 -2
  154. package/dist/meeting-info/util.js +9 -9
  155. package/dist/meeting-info/util.js.map +1 -1
  156. package/dist/meeting-info/utilv2.d.ts +2 -2
  157. package/dist/meeting-info/utilv2.js +20 -20
  158. package/dist/meeting-info/utilv2.js.map +1 -1
  159. package/dist/meetings/collection.d.ts +23 -23
  160. package/dist/meetings/collection.js +14 -14
  161. package/dist/meetings/collection.js.map +1 -1
  162. package/dist/meetings/index.d.ts +296 -296
  163. package/dist/meetings/index.js +259 -259
  164. package/dist/meetings/index.js.map +1 -1
  165. package/dist/meetings/request.d.ts +27 -27
  166. package/dist/meetings/request.js +15 -15
  167. package/dist/meetings/request.js.map +1 -1
  168. package/dist/meetings/util.d.ts +18 -18
  169. package/dist/meetings/util.js +29 -29
  170. package/dist/meetings/util.js.map +1 -1
  171. package/dist/member/index.d.ts +147 -147
  172. package/dist/member/index.js +214 -214
  173. package/dist/member/index.js.map +1 -1
  174. package/dist/member/member.types.d.ts +11 -11
  175. package/dist/member/member.types.js.map +1 -1
  176. package/dist/member/util.d.ts +2 -2
  177. package/dist/member/util.js +60 -60
  178. package/dist/member/util.js.map +1 -1
  179. package/dist/members/collection.d.ts +24 -24
  180. package/dist/members/collection.js +11 -11
  181. package/dist/members/collection.js.map +1 -1
  182. package/dist/members/index.d.ts +298 -298
  183. package/dist/members/index.js +275 -275
  184. package/dist/members/index.js.map +1 -1
  185. package/dist/members/request.d.ts +50 -50
  186. package/dist/members/request.js +27 -27
  187. package/dist/members/request.js.map +1 -1
  188. package/dist/members/util.d.ts +2 -2
  189. package/dist/members/util.js +21 -21
  190. package/dist/members/util.js.map +1 -1
  191. package/dist/metrics/config.d.ts +169 -169
  192. package/dist/metrics/config.js.map +1 -1
  193. package/dist/metrics/constants.d.ts +57 -57
  194. package/dist/metrics/constants.js.map +1 -1
  195. package/dist/metrics/index.d.ts +152 -152
  196. package/dist/metrics/index.js +90 -90
  197. package/dist/metrics/index.js.map +1 -1
  198. package/dist/networkQualityMonitor/index.d.ts +70 -70
  199. package/dist/networkQualityMonitor/index.js +65 -65
  200. package/dist/networkQualityMonitor/index.js.map +1 -1
  201. package/dist/peer-connection-manager/index.d.ts +6 -6
  202. package/dist/peer-connection-manager/index.js +87 -87
  203. package/dist/peer-connection-manager/index.js.map +1 -1
  204. package/dist/peer-connection-manager/util.d.ts +6 -6
  205. package/dist/peer-connection-manager/util.js +9 -9
  206. package/dist/peer-connection-manager/util.js.map +1 -1
  207. package/dist/personal-meeting-room/index.d.ts +47 -47
  208. package/dist/personal-meeting-room/index.js +67 -67
  209. package/dist/personal-meeting-room/index.js.map +1 -1
  210. package/dist/personal-meeting-room/request.d.ts +14 -14
  211. package/dist/personal-meeting-room/request.js +7 -7
  212. package/dist/personal-meeting-room/request.js.map +1 -1
  213. package/dist/personal-meeting-room/util.d.ts +2 -2
  214. package/dist/personal-meeting-room/util.js.map +1 -1
  215. package/dist/reachability/index.d.ts +139 -139
  216. package/dist/reachability/index.js +110 -110
  217. package/dist/reachability/index.js.map +1 -1
  218. package/dist/reachability/request.d.ts +35 -35
  219. package/dist/reachability/request.js +15 -15
  220. package/dist/reachability/request.js.map +1 -1
  221. package/dist/reactions/reactions.d.ts +4 -4
  222. package/dist/reactions/reactions.js.map +1 -1
  223. package/dist/reactions/reactions.type.d.ts +32 -32
  224. package/dist/reactions/reactions.type.js.map +1 -1
  225. package/dist/reconnection-manager/index.d.ts +112 -112
  226. package/dist/reconnection-manager/index.js +112 -112
  227. package/dist/reconnection-manager/index.js.map +1 -1
  228. package/dist/recording-controller/enums.d.ts +7 -7
  229. package/dist/recording-controller/enums.js.map +1 -1
  230. package/dist/recording-controller/index.d.ts +193 -193
  231. package/dist/recording-controller/index.js +127 -127
  232. package/dist/recording-controller/index.js.map +1 -1
  233. package/dist/recording-controller/util.d.ts +13 -13
  234. package/dist/recording-controller/util.js.map +1 -1
  235. package/dist/roap/collection.d.ts +10 -10
  236. package/dist/roap/collection.js.map +1 -1
  237. package/dist/roap/handler.d.ts +47 -47
  238. package/dist/roap/handler.js +27 -27
  239. package/dist/roap/handler.js.map +1 -1
  240. package/dist/roap/index.d.ts +116 -116
  241. package/dist/roap/index.js +111 -111
  242. package/dist/roap/index.js.map +1 -1
  243. package/dist/roap/request.d.ts +35 -35
  244. package/dist/roap/request.js +17 -17
  245. package/dist/roap/request.js.map +1 -1
  246. package/dist/roap/state.d.ts +9 -9
  247. package/dist/roap/state.js +14 -14
  248. package/dist/roap/state.js.map +1 -1
  249. package/dist/roap/turnDiscovery.d.ts +67 -67
  250. package/dist/roap/turnDiscovery.js +46 -46
  251. package/dist/roap/turnDiscovery.js.map +1 -1
  252. package/dist/roap/util.d.ts +2 -2
  253. package/dist/roap/util.js.map +1 -1
  254. package/dist/statsAnalyzer/global.d.ts +126 -126
  255. package/dist/statsAnalyzer/global.js.map +1 -1
  256. package/dist/statsAnalyzer/index.d.ts +190 -190
  257. package/dist/statsAnalyzer/index.js +128 -128
  258. package/dist/statsAnalyzer/index.js.map +1 -1
  259. package/dist/statsAnalyzer/mqaUtil.d.ts +22 -22
  260. package/dist/statsAnalyzer/mqaUtil.js.map +1 -1
  261. package/dist/transcription/index.d.ts +64 -64
  262. package/dist/transcription/index.js +42 -42
  263. package/dist/transcription/index.js.map +1 -1
  264. package/internal-README.md +172 -172
  265. package/jest.config.js +3 -3
  266. package/package.json +22 -21
  267. package/process +1 -1
  268. package/src/common/browser-detection.ts +39 -39
  269. package/src/common/collection.ts +94 -94
  270. package/src/common/config.ts +9 -9
  271. package/src/common/errors/captcha-error.ts +25 -25
  272. package/src/common/errors/intent-to-join.ts +27 -27
  273. package/src/common/errors/join-meeting.ts +32 -32
  274. package/src/common/errors/media.ts +25 -25
  275. package/src/common/errors/parameter.ts +33 -33
  276. package/src/common/errors/password-error.ts +25 -25
  277. package/src/common/errors/permission.ts +24 -24
  278. package/src/common/errors/reconnection-in-progress.ts +8 -8
  279. package/src/common/errors/reconnection.ts +25 -25
  280. package/src/common/errors/stats.ts +25 -25
  281. package/src/common/errors/webex-errors.ts +140 -140
  282. package/src/common/errors/webex-meetings-error.ts +35 -35
  283. package/src/common/events/events-scope.ts +30 -30
  284. package/src/common/events/events.ts +25 -25
  285. package/src/common/events/trigger-proxy.ts +25 -25
  286. package/src/common/events/util.ts +39 -39
  287. package/src/common/logs/logger-config.ts +8 -8
  288. package/src/common/logs/logger-proxy.ts +44 -44
  289. package/src/common/logs/request.ts +65 -65
  290. package/src/common/queue.ts +50 -50
  291. package/src/config.ts +96 -96
  292. package/src/constants.ts +1121 -1121
  293. package/src/controls-options-manager/constants.ts +5 -5
  294. package/src/controls-options-manager/enums.ts +6 -6
  295. package/src/controls-options-manager/index.ts +183 -183
  296. package/src/controls-options-manager/util.ts +20 -20
  297. package/src/index.js +15 -15
  298. package/src/locus-info/controlsUtils.ts +112 -112
  299. package/src/locus-info/embeddedAppsUtils.ts +57 -57
  300. package/src/locus-info/fullState.ts +69 -69
  301. package/src/locus-info/hostUtils.ts +60 -60
  302. package/src/locus-info/index.ts +1303 -1303
  303. package/src/locus-info/infoUtils.ts +101 -101
  304. package/src/locus-info/mediaSharesUtils.ts +173 -173
  305. package/src/locus-info/parser.ts +680 -680
  306. package/src/locus-info/selfUtils.ts +428 -428
  307. package/src/media/index.ts +675 -675
  308. package/src/media/properties.ts +313 -313
  309. package/src/media/util.ts +37 -37
  310. package/src/mediaQualityMetrics/config.ts +382 -382
  311. package/src/meeting/effectsState.ts +209 -209
  312. package/src/meeting/in-meeting-actions.ts +153 -153
  313. package/src/meeting/index.ts +6537 -6543
  314. package/src/meeting/muteState.ts +365 -365
  315. package/src/meeting/request.ts +810 -810
  316. package/src/meeting/state.ts +194 -194
  317. package/src/meeting/util.ts +530 -530
  318. package/src/meeting-info/collection.ts +41 -41
  319. package/src/meeting-info/index.ts +137 -137
  320. package/src/meeting-info/meeting-info-v2.ts +273 -273
  321. package/src/meeting-info/request.ts +46 -46
  322. package/src/meeting-info/util.ts +314 -314
  323. package/src/meeting-info/utilv2.ts +324 -324
  324. package/src/meetings/collection.ts +43 -43
  325. package/src/meetings/index.ts +1128 -1128
  326. package/src/meetings/request.ts +81 -81
  327. package/src/meetings/util.ts +181 -181
  328. package/src/member/index.ts +446 -446
  329. package/src/member/member.types.ts +13 -13
  330. package/src/member/util.ts +286 -286
  331. package/src/members/collection.ts +40 -40
  332. package/src/members/index.ts +900 -900
  333. package/src/members/request.ts +175 -175
  334. package/src/members/util.ts +260 -260
  335. package/src/metrics/config.ts +485 -485
  336. package/src/metrics/constants.ts +61 -61
  337. package/src/metrics/index.ts +543 -543
  338. package/src/networkQualityMonitor/index.ts +211 -211
  339. package/src/peer-connection-manager/index.ts +847 -847
  340. package/src/peer-connection-manager/util.ts +119 -119
  341. package/src/personal-meeting-room/index.ts +157 -157
  342. package/src/personal-meeting-room/request.ts +48 -48
  343. package/src/personal-meeting-room/util.ts +49 -49
  344. package/src/reachability/index.ts +478 -478
  345. package/src/reachability/request.ts +81 -81
  346. package/src/reactions/reactions.ts +104 -104
  347. package/src/reactions/reactions.type.ts +36 -36
  348. package/src/reconnection-manager/index.ts +622 -622
  349. package/src/recording-controller/enums.ts +8 -8
  350. package/src/recording-controller/index.ts +315 -315
  351. package/src/recording-controller/util.ts +58 -58
  352. package/src/roap/collection.ts +62 -62
  353. package/src/roap/handler.ts +294 -294
  354. package/src/roap/index.ts +413 -413
  355. package/src/roap/request.ts +229 -229
  356. package/src/roap/state.ts +156 -156
  357. package/src/roap/turnDiscovery.ts +283 -283
  358. package/src/roap/util.ts +100 -100
  359. package/src/statsAnalyzer/global.ts +128 -128
  360. package/src/statsAnalyzer/index.ts +1266 -1266
  361. package/src/statsAnalyzer/mqaUtil.ts +290 -290
  362. package/src/transcription/index.ts +154 -154
  363. package/test/integration/spec/journey.js +941 -941
  364. package/test/integration/spec/space-meeting.js +457 -457
  365. package/test/integration/spec/transcription.js +55 -55
  366. package/test/unit/spec/common/browser-detection.js +119 -119
  367. package/test/unit/spec/common/queue.js +69 -69
  368. package/test/unit/spec/controls-options-manager/index.js +123 -123
  369. package/test/unit/spec/controls-options-manager/util.js +65 -65
  370. package/test/unit/spec/fixture/locus.js +406 -406
  371. package/test/unit/spec/locus-info/controlsUtils.js +82 -82
  372. package/test/unit/spec/locus-info/embeddedAppsUtils.js +104 -104
  373. package/test/unit/spec/locus-info/index.js +1272 -1272
  374. package/test/unit/spec/locus-info/infoUtils.js +138 -138
  375. package/test/unit/spec/locus-info/lib/BasicSeqCmp.json +975 -975
  376. package/test/unit/spec/locus-info/lib/SeqCmp.json +522 -522
  377. package/test/unit/spec/locus-info/lib/selfConstant.js +286 -286
  378. package/test/unit/spec/locus-info/parser.js +298 -298
  379. package/test/unit/spec/locus-info/selfUtils.js +185 -185
  380. package/test/unit/spec/media/properties.ts +305 -305
  381. package/test/unit/spec/meeting/effectsState.js +281 -281
  382. package/test/unit/spec/meeting/in-meeting-actions.ts +90 -90
  383. package/test/unit/spec/meeting/index.js +5227 -5227
  384. package/test/unit/spec/meeting/muteState.js +430 -430
  385. package/test/unit/spec/meeting/request.js +317 -317
  386. package/test/unit/spec/meeting/utils.js +319 -319
  387. package/test/unit/spec/meeting-info/meetinginfov2.js +376 -376
  388. package/test/unit/spec/meeting-info/request.js +64 -64
  389. package/test/unit/spec/meeting-info/util.js +37 -37
  390. package/test/unit/spec/meeting-info/utilv2.js +330 -330
  391. package/test/unit/spec/meetings/collection.js +52 -52
  392. package/test/unit/spec/meetings/index.js +1375 -1375
  393. package/test/unit/spec/meetings/utils.js +66 -66
  394. package/test/unit/spec/member/index.js +47 -47
  395. package/test/unit/spec/member/util.js +80 -80
  396. package/test/unit/spec/members/index.js +364 -364
  397. package/test/unit/spec/members/request.js +200 -200
  398. package/test/unit/spec/members/utils.js +42 -42
  399. package/test/unit/spec/metrics/index.js +111 -111
  400. package/test/unit/spec/networkQualityMonitor/index.js +99 -99
  401. package/test/unit/spec/peerconnection-manager/index.js +218 -218
  402. package/test/unit/spec/peerconnection-manager/utils.js +49 -49
  403. package/test/unit/spec/peerconnection-manager/utils.test-fixtures.ts +388 -388
  404. package/test/unit/spec/personal-meeting-room/personal-meeting-room.js +29 -29
  405. package/test/unit/spec/reachability/index.ts +50 -50
  406. package/test/unit/spec/reconnection-manager/index.js +206 -206
  407. package/test/unit/spec/recording-controller/index.js +230 -230
  408. package/test/unit/spec/recording-controller/util.js +101 -101
  409. package/test/unit/spec/roap/index.ts +128 -128
  410. package/test/unit/spec/roap/turnDiscovery.ts +372 -372
  411. package/test/unit/spec/roap/util.js +30 -30
  412. package/test/unit/spec/stats-analyzer/index.js +287 -287
  413. package/test/utils/cmr.js +104 -104
  414. package/test/utils/testUtils.js +287 -287
  415. package/test/utils/webex-config.js +77 -77
  416. package/test/utils/webex-test-users.js +82 -82
  417. package/tsconfig.json +5 -5
@@ -1,478 +1,478 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- /* eslint-disable class-methods-use-this */
6
- /* globals window */
7
- import _ from 'lodash';
8
-
9
- import LoggerProxy from '../common/logs/logger-proxy';
10
- import {ICE_GATHERING_STATE, CONNECTION_STATE, REACHABILITY} from '../constants';
11
-
12
- import ReachabilityRequest from './request';
13
-
14
- const DEFAULT_TIMEOUT = 3000;
15
- const VIDEO_MESH_TIMEOUT = 1000;
16
-
17
- /**
18
- * @class Reachability
19
- * @export
20
- */
21
- export default class Reachability {
22
- webex: object;
23
- reachabilityRequest: any;
24
- clusterLatencyResults: any;
25
-
26
- /**
27
- * Creates an instance of Reachability.
28
- * @param {object} webex
29
- * @memberof Reachability
30
- */
31
- constructor(webex: object) {
32
- this.webex = webex;
33
-
34
- /**
35
- * internal request object for the server
36
- * @instance
37
- * @type {Array}
38
- * @private
39
- * @memberof Reachability
40
- */
41
- this.reachabilityRequest = new ReachabilityRequest(this.webex);
42
-
43
- /**
44
- * internal object of clusters latency results
45
- * @instance
46
- * @type {object}
47
- * @private
48
- * @memberof Reachability
49
- */
50
- this.clusterLatencyResults = {};
51
- }
52
-
53
- /**
54
- * fetches reachability data
55
- * @returns {Object} reachability data
56
- * @public
57
- * @async
58
- * @memberof Reachability
59
- */
60
- public async gatherReachability() {
61
- this.setup();
62
-
63
- // Remove stored reachability results to ensure no stale data
64
- if (window?.localStorage?.removeItem) {
65
- window.localStorage.removeItem(REACHABILITY.localStorage);
66
- } else {
67
- LoggerProxy.logger.error(
68
- 'Reachability:index#gatherReachability --> Error in accessing LocalStorage.'
69
- );
70
-
71
- return {};
72
- }
73
-
74
- // Fetch clusters and measure latency
75
- try {
76
- const clusters = await this.reachabilityRequest.getClusters();
77
-
78
- // Perform Reachability Check
79
- const results = await this.performReachabilityCheck(clusters);
80
-
81
- window.localStorage.setItem(REACHABILITY.localStorage, JSON.stringify(results));
82
-
83
- LoggerProxy.logger.log(
84
- 'Reachability:index#gatherReachability --> Reachability checks completed'
85
- );
86
-
87
- return results;
88
- } catch (getClusterError) {
89
- LoggerProxy.logger.error(
90
- `Reachability:index#gatherReachability --> Error in calling getClusters(): ${getClusterError}`
91
- );
92
-
93
- return {};
94
- }
95
- }
96
-
97
- /**
98
- * fetches reachability data and checks for cluster reachability
99
- * @returns {boolean}
100
- * @public
101
- * @memberof Reachability
102
- */
103
- isAnyClusterReachable() {
104
- let reachable = false;
105
- const reachabilityData = window.localStorage.getItem(REACHABILITY.localStorage);
106
-
107
- if (reachabilityData) {
108
- try {
109
- const reachabilityResults = JSON.parse(reachabilityData);
110
-
111
- reachable = Object.values(reachabilityResults).some(
112
- (result: any) => result.udp?.reachable === 'true' || result.tcp?.reachable === 'true'
113
- );
114
- } catch (e) {
115
- LoggerProxy.logger.error(
116
- `Roap:request#attachReachabilityData --> Error in parsing reachability data: ${e}`
117
- );
118
- }
119
- }
120
-
121
- return reachable;
122
- }
123
-
124
- /**
125
- * Generate peerConnection config settings
126
- * @param {object} cluster
127
- * @returns {object} peerConnectionConfig
128
- * @private
129
- * @memberof Reachability
130
- */
131
- private buildPeerConnectionConfig(cluster: any) {
132
- const iceServers = _.uniq([...cluster.udp, ...cluster.tcp]).map((url) => ({
133
- username: '',
134
- credential: '',
135
- urls: [url],
136
- }));
137
-
138
- return {
139
- iceServers: [...iceServers],
140
- iceCandidatePoolSize: '0',
141
- iceTransportPolicy: 'all',
142
- };
143
- }
144
-
145
- /**
146
- * Creates an RTCPeerConnection
147
- * @param {object} cluster
148
- * @returns {RTCPeerConnection} peerConnection
149
- * @private
150
- * @memberof Reachability
151
- */
152
- private createPeerConnection(cluster: any) {
153
- const {key, config} = cluster;
154
-
155
- try {
156
- const peerConnection = new window.RTCPeerConnection(config);
157
-
158
- // @ts-ignore
159
- peerConnection.key = key;
160
-
161
- return peerConnection;
162
- } catch (peerConnectionError) {
163
- LoggerProxy.logger.log(
164
- `Reachability:index#createPeerConnection --> Error creating peerConnection: ${peerConnectionError}`
165
- );
166
-
167
- return null;
168
- }
169
- }
170
-
171
- /**
172
- * Gets total elapsed time
173
- * @param {RTCPeerConnection} peerConnection
174
- * @returns {Number} Milliseconds
175
- * @private
176
- * @memberof Reachability
177
- */
178
- private getElapsedTime(peerConnection: any) {
179
- const startTime = peerConnection.begin;
180
-
181
- delete peerConnection.begin;
182
-
183
- return Date.now() - startTime;
184
- }
185
-
186
- /**
187
- * creates offer and generates localSDP
188
- * @param {object} clusterList cluster List
189
- * @returns {Promise} Reachability latency results
190
- * @private
191
- * @memberof Reachability
192
- */
193
- private getLocalSDPForClusters(clusterList: object) {
194
- let clusters: any[] = [...Object.keys(clusterList)];
195
-
196
- clusters = clusters.map(async (key) => {
197
- const cluster = clusterList[key];
198
- const config = this.buildPeerConnectionConfig(cluster);
199
- const peerConnection = this.createPeerConnection({key, config});
200
- const description = await peerConnection.createOffer({offerToReceiveAudio: true});
201
-
202
- // @ts-ignore
203
- peerConnection.begin = Date.now();
204
- peerConnection.setLocalDescription(description);
205
-
206
- return this.iceGatheringState(
207
- peerConnection,
208
- cluster.isVideoMesh ? VIDEO_MESH_TIMEOUT : DEFAULT_TIMEOUT
209
- ).catch((iceGatheringStateError) => {
210
- LoggerProxy.logger.log(
211
- `Reachability:index#getLocalSDPForClusters --> Error in getLocalSDP : ${iceGatheringStateError}`
212
- );
213
- });
214
- });
215
-
216
- return Promise.all(clusters)
217
- .then(this.parseIceResultsToReachabilityResults)
218
- .then((reachabilityLatencyResults) => {
219
- this.logUnreachableClusters();
220
-
221
- // return results
222
- return reachabilityLatencyResults;
223
- });
224
- }
225
-
226
- /**
227
- * Get list of all unreachable clusters
228
- * @returns {array} Unreachable clusters
229
- * @private
230
- * @memberof Reachability
231
- */
232
- private getUnreachablClusters() {
233
- const unreachableList = [];
234
- const clusters = this.clusterLatencyResults;
235
-
236
- Object.keys(clusters).forEach((key) => {
237
- const cluster = clusters[key];
238
-
239
- if (cluster.unreachable && !cluster.reachable) {
240
- unreachableList.push(key);
241
- }
242
- });
243
-
244
- return unreachableList;
245
- }
246
-
247
- /**
248
- * Attach an event handler for the icegatheringstatechange
249
- * event and measure latency.
250
- * @param {RTCPeerConnection} peerConnection
251
- * @returns {undefined}
252
- * @private
253
- * @memberof Reachability
254
- */
255
- private handleIceGatheringStateChange(peerConnection: RTCPeerConnection) {
256
- peerConnection.onicegatheringstatechange = () => {
257
- const {COMPLETE} = ICE_GATHERING_STATE;
258
-
259
- if (peerConnection.iceConnectionState === COMPLETE) {
260
- const elapsed = this.getElapsedTime(peerConnection);
261
-
262
- // @ts-ignore
263
- LoggerProxy.logger.log(
264
- // @ts-ignore
265
- `Reachability:index#onIceGatheringStateChange --> Successfully pinged ${peerConnection.key}:`,
266
- elapsed
267
- );
268
- this.setLatencyAndClose(peerConnection, elapsed);
269
- }
270
- };
271
- }
272
-
273
- /**
274
- * Attach an event handler for the icecandidate
275
- * event and measure latency.
276
- * @param {RTCPeerConnection} peerConnection
277
- * @returns {undefined}
278
- * @private
279
- * @memberof Reachability
280
- */
281
- private handleOnIceCandidate(peerConnection: RTCPeerConnection) {
282
- peerConnection.onicecandidate = (e) => {
283
- const SERVER_REFLEXIVE = 'srflx';
284
-
285
- if (e.candidate && String(e.candidate.type).toLowerCase() === SERVER_REFLEXIVE) {
286
- const elapsed = this.getElapsedTime(peerConnection);
287
-
288
- LoggerProxy.logger.log(
289
- // @ts-ignore
290
- `Reachability:index#onIceCandidate --> Successfully pinged ${peerConnection.key}:`,
291
- elapsed
292
- );
293
- this.setLatencyAndClose(peerConnection, elapsed);
294
- }
295
- };
296
- }
297
-
298
- /**
299
- * An event handler on an RTCPeerConnection when the state of the ICE
300
- * candidate gathering process changes. Used to measure connection
301
- * speed.
302
- * @private
303
- * @param {RTCPeerConnection} peerConnection
304
- * @param {number} timeout
305
- * @returns {Promise}
306
- */
307
- private iceGatheringState(peerConnection: RTCPeerConnection, timeout: number) {
308
- const ELAPSED = 'elapsed';
309
-
310
- return new Promise((resolve) => {
311
- const peerConnectionProxy = new window.Proxy(peerConnection, {
312
- get(target, property) {
313
- const targetMember = target[property];
314
-
315
- if (typeof targetMember === 'function') {
316
- return targetMember.bind(target);
317
- }
318
-
319
- return targetMember;
320
- },
321
- set: (target, property, value) => {
322
- // only intercept elapsed property
323
- if (property === ELAPSED) {
324
- // @ts-ignore
325
- resolve({clusterId: peerConnection.key, elapsed: value});
326
-
327
- return true;
328
- }
329
-
330
- // pass thru
331
- return window.Reflect.set(target, property, value);
332
- },
333
- });
334
-
335
- // Using peerConnection proxy so handle functions below
336
- // won't be coupled to our promise implementation
337
- this.handleIceGatheringStateChange(peerConnectionProxy);
338
- this.handleOnIceCandidate(peerConnectionProxy);
339
-
340
- // Set maximum timeout
341
- window.setTimeout(() => {
342
- const {CLOSED} = CONNECTION_STATE;
343
-
344
- // Close any open peerConnections
345
- if (peerConnectionProxy.connectionState !== CLOSED) {
346
- this.setLatencyAndClose(peerConnectionProxy, null);
347
- }
348
- }, timeout);
349
- });
350
- }
351
-
352
- /**
353
- * Make a log of unreachable clusters.
354
- * @returns {undefined}
355
- * @private
356
- * @memberof Reachability
357
- */
358
- private logUnreachableClusters() {
359
- const list = this.getUnreachablClusters();
360
-
361
- list.forEach((cluster) => {
362
- LoggerProxy.logger.log(
363
- `Reachability:index#logUnreachableClusters --> No ice candidate for ${cluster}.`
364
- );
365
- });
366
- }
367
-
368
- /**
369
- * Calculates time to establish connection
370
- * @param {array} iceResults iceResults
371
- * @returns {object} reachabilityMap
372
- * @private
373
- * @memberof Reachability
374
- */
375
- private parseIceResultsToReachabilityResults(iceResults: Array<any>) {
376
- const reachabilityMap = {};
377
-
378
- iceResults.forEach(({clusterId, elapsed}) => {
379
- let latencyResult;
380
-
381
- if (elapsed === null) {
382
- latencyResult = {reachable: 'false'};
383
- } else {
384
- latencyResult = {
385
- reachable: 'true',
386
- latencyInMilliseconds: elapsed.toString(),
387
- };
388
- }
389
-
390
- reachabilityMap[clusterId] = {
391
- udp: latencyResult,
392
- tcp: latencyResult,
393
- };
394
- });
395
-
396
- return reachabilityMap;
397
- }
398
-
399
- /**
400
- * fetches reachability data
401
- * @param {object} clusterList
402
- * @returns {Promise<localSDPData>} reachability check results
403
- * @private
404
- * @memberof Reachability
405
- */
406
- private performReachabilityCheck(clusterList: object) {
407
- if (!clusterList || !Object.keys(clusterList).length) {
408
- return Promise.resolve({});
409
- }
410
-
411
- return new Promise((resolve) => {
412
- this.getLocalSDPForClusters(clusterList)
413
- .then((localSDPData) => {
414
- if (!localSDPData || !Object.keys(localSDPData).length) {
415
- // TODO: handle the error condition properly and try retry
416
- LoggerProxy.logger.log(
417
- 'Reachability:index#performReachabilityCheck --> Local SDP is empty or has missing elements..returning'
418
- );
419
- resolve({});
420
- } else {
421
- resolve(localSDPData);
422
- }
423
- })
424
- .catch((error) => {
425
- LoggerProxy.logger.error(
426
- `Reachability:index#performReachabilityCheck --> Error in getLocalSDPForClusters: ${error}`
427
- );
428
- resolve({});
429
- });
430
- });
431
- }
432
-
433
- /**
434
- * Records latency and closes the peerConnection
435
- * @param {RTCPeerConnection} peerConnection
436
- * @param {number} elapsed Latency in milliseconds
437
- * @returns {undefined}
438
- * @private
439
- * @memberof Reachability
440
- */
441
- private setLatencyAndClose(peerConnection: RTCPeerConnection, elapsed: number) {
442
- const REACHABLE = 'reachable';
443
- const UNREACHABLE = 'unreachable';
444
- const {CLOSED} = CONNECTION_STATE;
445
- // @ts-ignore
446
- const {key} = peerConnection;
447
- const resultKey = elapsed === null ? UNREACHABLE : REACHABLE;
448
- const intialState = {[REACHABLE]: 0, [UNREACHABLE]: 0};
449
-
450
- if (peerConnection.connectionState === CLOSED) {
451
- LoggerProxy.logger.log(
452
- `Reachability:index#setLatencyAndClose --> Attempting to set latency of ${elapsed} on closed peerConnection.`
453
- );
454
-
455
- return;
456
- }
457
-
458
- this.clusterLatencyResults[key] = this.clusterLatencyResults[key] || intialState;
459
- this.clusterLatencyResults[key][resultKey] += 1;
460
-
461
- // Set to null in case this fired from
462
- // an event other than onIceCandidate
463
- peerConnection.onicecandidate = null;
464
- peerConnection.close();
465
- // @ts-ignore
466
- peerConnection.elapsed = elapsed;
467
- }
468
-
469
- /**
470
- * utility function
471
- * @returns {undefined}
472
- * @private
473
- * @memberof Reachability
474
- */
475
- private setup() {
476
- this.clusterLatencyResults = {};
477
- }
478
- }
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ /* eslint-disable class-methods-use-this */
6
+ /* globals window */
7
+ import _ from 'lodash';
8
+
9
+ import LoggerProxy from '../common/logs/logger-proxy';
10
+ import {ICE_GATHERING_STATE, CONNECTION_STATE, REACHABILITY} from '../constants';
11
+
12
+ import ReachabilityRequest from './request';
13
+
14
+ const DEFAULT_TIMEOUT = 3000;
15
+ const VIDEO_MESH_TIMEOUT = 1000;
16
+
17
+ /**
18
+ * @class Reachability
19
+ * @export
20
+ */
21
+ export default class Reachability {
22
+ webex: object;
23
+ reachabilityRequest: any;
24
+ clusterLatencyResults: any;
25
+
26
+ /**
27
+ * Creates an instance of Reachability.
28
+ * @param {object} webex
29
+ * @memberof Reachability
30
+ */
31
+ constructor(webex: object) {
32
+ this.webex = webex;
33
+
34
+ /**
35
+ * internal request object for the server
36
+ * @instance
37
+ * @type {Array}
38
+ * @private
39
+ * @memberof Reachability
40
+ */
41
+ this.reachabilityRequest = new ReachabilityRequest(this.webex);
42
+
43
+ /**
44
+ * internal object of clusters latency results
45
+ * @instance
46
+ * @type {object}
47
+ * @private
48
+ * @memberof Reachability
49
+ */
50
+ this.clusterLatencyResults = {};
51
+ }
52
+
53
+ /**
54
+ * fetches reachability data
55
+ * @returns {Object} reachability data
56
+ * @public
57
+ * @async
58
+ * @memberof Reachability
59
+ */
60
+ public async gatherReachability() {
61
+ this.setup();
62
+
63
+ // Remove stored reachability results to ensure no stale data
64
+ if (window?.localStorage?.removeItem) {
65
+ window.localStorage.removeItem(REACHABILITY.localStorage);
66
+ } else {
67
+ LoggerProxy.logger.error(
68
+ 'Reachability:index#gatherReachability --> Error in accessing LocalStorage.'
69
+ );
70
+
71
+ return {};
72
+ }
73
+
74
+ // Fetch clusters and measure latency
75
+ try {
76
+ const clusters = await this.reachabilityRequest.getClusters();
77
+
78
+ // Perform Reachability Check
79
+ const results = await this.performReachabilityCheck(clusters);
80
+
81
+ window.localStorage.setItem(REACHABILITY.localStorage, JSON.stringify(results));
82
+
83
+ LoggerProxy.logger.log(
84
+ 'Reachability:index#gatherReachability --> Reachability checks completed'
85
+ );
86
+
87
+ return results;
88
+ } catch (getClusterError) {
89
+ LoggerProxy.logger.error(
90
+ `Reachability:index#gatherReachability --> Error in calling getClusters(): ${getClusterError}`
91
+ );
92
+
93
+ return {};
94
+ }
95
+ }
96
+
97
+ /**
98
+ * fetches reachability data and checks for cluster reachability
99
+ * @returns {boolean}
100
+ * @public
101
+ * @memberof Reachability
102
+ */
103
+ isAnyClusterReachable() {
104
+ let reachable = false;
105
+ const reachabilityData = window.localStorage.getItem(REACHABILITY.localStorage);
106
+
107
+ if (reachabilityData) {
108
+ try {
109
+ const reachabilityResults = JSON.parse(reachabilityData);
110
+
111
+ reachable = Object.values(reachabilityResults).some(
112
+ (result: any) => result.udp?.reachable === 'true' || result.tcp?.reachable === 'true'
113
+ );
114
+ } catch (e) {
115
+ LoggerProxy.logger.error(
116
+ `Roap:request#attachReachabilityData --> Error in parsing reachability data: ${e}`
117
+ );
118
+ }
119
+ }
120
+
121
+ return reachable;
122
+ }
123
+
124
+ /**
125
+ * Generate peerConnection config settings
126
+ * @param {object} cluster
127
+ * @returns {object} peerConnectionConfig
128
+ * @private
129
+ * @memberof Reachability
130
+ */
131
+ private buildPeerConnectionConfig(cluster: any) {
132
+ const iceServers = _.uniq([...cluster.udp, ...cluster.tcp]).map((url) => ({
133
+ username: '',
134
+ credential: '',
135
+ urls: [url],
136
+ }));
137
+
138
+ return {
139
+ iceServers: [...iceServers],
140
+ iceCandidatePoolSize: '0',
141
+ iceTransportPolicy: 'all',
142
+ };
143
+ }
144
+
145
+ /**
146
+ * Creates an RTCPeerConnection
147
+ * @param {object} cluster
148
+ * @returns {RTCPeerConnection} peerConnection
149
+ * @private
150
+ * @memberof Reachability
151
+ */
152
+ private createPeerConnection(cluster: any) {
153
+ const {key, config} = cluster;
154
+
155
+ try {
156
+ const peerConnection = new window.RTCPeerConnection(config);
157
+
158
+ // @ts-ignore
159
+ peerConnection.key = key;
160
+
161
+ return peerConnection;
162
+ } catch (peerConnectionError) {
163
+ LoggerProxy.logger.log(
164
+ `Reachability:index#createPeerConnection --> Error creating peerConnection: ${peerConnectionError}`
165
+ );
166
+
167
+ return null;
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Gets total elapsed time
173
+ * @param {RTCPeerConnection} peerConnection
174
+ * @returns {Number} Milliseconds
175
+ * @private
176
+ * @memberof Reachability
177
+ */
178
+ private getElapsedTime(peerConnection: any) {
179
+ const startTime = peerConnection.begin;
180
+
181
+ delete peerConnection.begin;
182
+
183
+ return Date.now() - startTime;
184
+ }
185
+
186
+ /**
187
+ * creates offer and generates localSDP
188
+ * @param {object} clusterList cluster List
189
+ * @returns {Promise} Reachability latency results
190
+ * @private
191
+ * @memberof Reachability
192
+ */
193
+ private getLocalSDPForClusters(clusterList: object) {
194
+ let clusters: any[] = [...Object.keys(clusterList)];
195
+
196
+ clusters = clusters.map(async (key) => {
197
+ const cluster = clusterList[key];
198
+ const config = this.buildPeerConnectionConfig(cluster);
199
+ const peerConnection = this.createPeerConnection({key, config});
200
+ const description = await peerConnection.createOffer({offerToReceiveAudio: true});
201
+
202
+ // @ts-ignore
203
+ peerConnection.begin = Date.now();
204
+ peerConnection.setLocalDescription(description);
205
+
206
+ return this.iceGatheringState(
207
+ peerConnection,
208
+ cluster.isVideoMesh ? VIDEO_MESH_TIMEOUT : DEFAULT_TIMEOUT
209
+ ).catch((iceGatheringStateError) => {
210
+ LoggerProxy.logger.log(
211
+ `Reachability:index#getLocalSDPForClusters --> Error in getLocalSDP : ${iceGatheringStateError}`
212
+ );
213
+ });
214
+ });
215
+
216
+ return Promise.all(clusters)
217
+ .then(this.parseIceResultsToReachabilityResults)
218
+ .then((reachabilityLatencyResults) => {
219
+ this.logUnreachableClusters();
220
+
221
+ // return results
222
+ return reachabilityLatencyResults;
223
+ });
224
+ }
225
+
226
+ /**
227
+ * Get list of all unreachable clusters
228
+ * @returns {array} Unreachable clusters
229
+ * @private
230
+ * @memberof Reachability
231
+ */
232
+ private getUnreachablClusters() {
233
+ const unreachableList = [];
234
+ const clusters = this.clusterLatencyResults;
235
+
236
+ Object.keys(clusters).forEach((key) => {
237
+ const cluster = clusters[key];
238
+
239
+ if (cluster.unreachable && !cluster.reachable) {
240
+ unreachableList.push(key);
241
+ }
242
+ });
243
+
244
+ return unreachableList;
245
+ }
246
+
247
+ /**
248
+ * Attach an event handler for the icegatheringstatechange
249
+ * event and measure latency.
250
+ * @param {RTCPeerConnection} peerConnection
251
+ * @returns {undefined}
252
+ * @private
253
+ * @memberof Reachability
254
+ */
255
+ private handleIceGatheringStateChange(peerConnection: RTCPeerConnection) {
256
+ peerConnection.onicegatheringstatechange = () => {
257
+ const {COMPLETE} = ICE_GATHERING_STATE;
258
+
259
+ if (peerConnection.iceConnectionState === COMPLETE) {
260
+ const elapsed = this.getElapsedTime(peerConnection);
261
+
262
+ // @ts-ignore
263
+ LoggerProxy.logger.log(
264
+ // @ts-ignore
265
+ `Reachability:index#onIceGatheringStateChange --> Successfully pinged ${peerConnection.key}:`,
266
+ elapsed
267
+ );
268
+ this.setLatencyAndClose(peerConnection, elapsed);
269
+ }
270
+ };
271
+ }
272
+
273
+ /**
274
+ * Attach an event handler for the icecandidate
275
+ * event and measure latency.
276
+ * @param {RTCPeerConnection} peerConnection
277
+ * @returns {undefined}
278
+ * @private
279
+ * @memberof Reachability
280
+ */
281
+ private handleOnIceCandidate(peerConnection: RTCPeerConnection) {
282
+ peerConnection.onicecandidate = (e) => {
283
+ const SERVER_REFLEXIVE = 'srflx';
284
+
285
+ if (e.candidate && String(e.candidate.type).toLowerCase() === SERVER_REFLEXIVE) {
286
+ const elapsed = this.getElapsedTime(peerConnection);
287
+
288
+ LoggerProxy.logger.log(
289
+ // @ts-ignore
290
+ `Reachability:index#onIceCandidate --> Successfully pinged ${peerConnection.key}:`,
291
+ elapsed
292
+ );
293
+ this.setLatencyAndClose(peerConnection, elapsed);
294
+ }
295
+ };
296
+ }
297
+
298
+ /**
299
+ * An event handler on an RTCPeerConnection when the state of the ICE
300
+ * candidate gathering process changes. Used to measure connection
301
+ * speed.
302
+ * @private
303
+ * @param {RTCPeerConnection} peerConnection
304
+ * @param {number} timeout
305
+ * @returns {Promise}
306
+ */
307
+ private iceGatheringState(peerConnection: RTCPeerConnection, timeout: number) {
308
+ const ELAPSED = 'elapsed';
309
+
310
+ return new Promise((resolve) => {
311
+ const peerConnectionProxy = new window.Proxy(peerConnection, {
312
+ get(target, property) {
313
+ const targetMember = target[property];
314
+
315
+ if (typeof targetMember === 'function') {
316
+ return targetMember.bind(target);
317
+ }
318
+
319
+ return targetMember;
320
+ },
321
+ set: (target, property, value) => {
322
+ // only intercept elapsed property
323
+ if (property === ELAPSED) {
324
+ // @ts-ignore
325
+ resolve({clusterId: peerConnection.key, elapsed: value});
326
+
327
+ return true;
328
+ }
329
+
330
+ // pass thru
331
+ return window.Reflect.set(target, property, value);
332
+ },
333
+ });
334
+
335
+ // Using peerConnection proxy so handle functions below
336
+ // won't be coupled to our promise implementation
337
+ this.handleIceGatheringStateChange(peerConnectionProxy);
338
+ this.handleOnIceCandidate(peerConnectionProxy);
339
+
340
+ // Set maximum timeout
341
+ window.setTimeout(() => {
342
+ const {CLOSED} = CONNECTION_STATE;
343
+
344
+ // Close any open peerConnections
345
+ if (peerConnectionProxy.connectionState !== CLOSED) {
346
+ this.setLatencyAndClose(peerConnectionProxy, null);
347
+ }
348
+ }, timeout);
349
+ });
350
+ }
351
+
352
+ /**
353
+ * Make a log of unreachable clusters.
354
+ * @returns {undefined}
355
+ * @private
356
+ * @memberof Reachability
357
+ */
358
+ private logUnreachableClusters() {
359
+ const list = this.getUnreachablClusters();
360
+
361
+ list.forEach((cluster) => {
362
+ LoggerProxy.logger.log(
363
+ `Reachability:index#logUnreachableClusters --> No ice candidate for ${cluster}.`
364
+ );
365
+ });
366
+ }
367
+
368
+ /**
369
+ * Calculates time to establish connection
370
+ * @param {array} iceResults iceResults
371
+ * @returns {object} reachabilityMap
372
+ * @private
373
+ * @memberof Reachability
374
+ */
375
+ private parseIceResultsToReachabilityResults(iceResults: Array<any>) {
376
+ const reachabilityMap = {};
377
+
378
+ iceResults.forEach(({clusterId, elapsed}) => {
379
+ let latencyResult;
380
+
381
+ if (elapsed === null) {
382
+ latencyResult = {reachable: 'false'};
383
+ } else {
384
+ latencyResult = {
385
+ reachable: 'true',
386
+ latencyInMilliseconds: elapsed.toString(),
387
+ };
388
+ }
389
+
390
+ reachabilityMap[clusterId] = {
391
+ udp: latencyResult,
392
+ tcp: latencyResult,
393
+ };
394
+ });
395
+
396
+ return reachabilityMap;
397
+ }
398
+
399
+ /**
400
+ * fetches reachability data
401
+ * @param {object} clusterList
402
+ * @returns {Promise<localSDPData>} reachability check results
403
+ * @private
404
+ * @memberof Reachability
405
+ */
406
+ private performReachabilityCheck(clusterList: object) {
407
+ if (!clusterList || !Object.keys(clusterList).length) {
408
+ return Promise.resolve({});
409
+ }
410
+
411
+ return new Promise((resolve) => {
412
+ this.getLocalSDPForClusters(clusterList)
413
+ .then((localSDPData) => {
414
+ if (!localSDPData || !Object.keys(localSDPData).length) {
415
+ // TODO: handle the error condition properly and try retry
416
+ LoggerProxy.logger.log(
417
+ 'Reachability:index#performReachabilityCheck --> Local SDP is empty or has missing elements..returning'
418
+ );
419
+ resolve({});
420
+ } else {
421
+ resolve(localSDPData);
422
+ }
423
+ })
424
+ .catch((error) => {
425
+ LoggerProxy.logger.error(
426
+ `Reachability:index#performReachabilityCheck --> Error in getLocalSDPForClusters: ${error}`
427
+ );
428
+ resolve({});
429
+ });
430
+ });
431
+ }
432
+
433
+ /**
434
+ * Records latency and closes the peerConnection
435
+ * @param {RTCPeerConnection} peerConnection
436
+ * @param {number} elapsed Latency in milliseconds
437
+ * @returns {undefined}
438
+ * @private
439
+ * @memberof Reachability
440
+ */
441
+ private setLatencyAndClose(peerConnection: RTCPeerConnection, elapsed: number) {
442
+ const REACHABLE = 'reachable';
443
+ const UNREACHABLE = 'unreachable';
444
+ const {CLOSED} = CONNECTION_STATE;
445
+ // @ts-ignore
446
+ const {key} = peerConnection;
447
+ const resultKey = elapsed === null ? UNREACHABLE : REACHABLE;
448
+ const intialState = {[REACHABLE]: 0, [UNREACHABLE]: 0};
449
+
450
+ if (peerConnection.connectionState === CLOSED) {
451
+ LoggerProxy.logger.log(
452
+ `Reachability:index#setLatencyAndClose --> Attempting to set latency of ${elapsed} on closed peerConnection.`
453
+ );
454
+
455
+ return;
456
+ }
457
+
458
+ this.clusterLatencyResults[key] = this.clusterLatencyResults[key] || intialState;
459
+ this.clusterLatencyResults[key][resultKey] += 1;
460
+
461
+ // Set to null in case this fired from
462
+ // an event other than onIceCandidate
463
+ peerConnection.onicecandidate = null;
464
+ peerConnection.close();
465
+ // @ts-ignore
466
+ peerConnection.elapsed = elapsed;
467
+ }
468
+
469
+ /**
470
+ * utility function
471
+ * @returns {undefined}
472
+ * @private
473
+ * @memberof Reachability
474
+ */
475
+ private setup() {
476
+ this.clusterLatencyResults = {};
477
+ }
478
+ }