@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,847 +1,847 @@
1
- // We need to figure out how to pass a webex logger instance to these util files
2
-
3
- /* globals RTCSessionDescription */
4
-
5
- import window from 'global/window';
6
- import sdpTransform from 'sdp-transform'; // https://github.com/clux/sdp-transform
7
-
8
- import Metrics from '../metrics';
9
- import LoggerProxy from '../common/logs/logger-proxy';
10
- import StaticConfig from '../common/config';
11
- import {
12
- COMPLETE,
13
- GATHERING,
14
- AUDIO,
15
- SDP,
16
- ICE_STATE,
17
- CONNECTION_STATE,
18
- NETWORK_STATUS,
19
- PEER_CONNECTION_STATE,
20
- OFFER,
21
- QUALITY_LEVELS,
22
- REMOTE_VIDEO_CONSTRAINTS,
23
- } from '../constants';
24
- import BEHAVIORAL_METRICS from '../metrics/constants';
25
- import {error, eventType} from '../metrics/config';
26
- import MediaError from '../common/errors/media';
27
- import ParameterError from '../common/errors/parameter';
28
- import {InvalidSdpError} from '../common/errors/webex-errors';
29
- import BrowserDetection from '../common/browser-detection';
30
-
31
- import PeerConnectionUtils from './util';
32
-
33
- const {isBrowser} = BrowserDetection();
34
-
35
- /**
36
- * @export
37
- * @public
38
- */
39
- const pc: any = {};
40
-
41
- /**
42
- * munges the bandwidth limit into the sdp
43
- * @param {String} sdpLines
44
- * @param {Number} index
45
- * @returns {String}
46
- */
47
- const insertBandwidthLimit = (sdpLines: any, index: number) => {
48
- // eslint-disable-next-line no-warning-comments
49
- // TODO convert to sdp parser
50
- let limit;
51
- let periodicKeyFrame = '';
52
-
53
- if (sdpLines[index].search(AUDIO) !== -1) {
54
- limit = StaticConfig.meetings.bandwidth.audio;
55
- } else {
56
- limit = StaticConfig.meetings.bandwidth.video;
57
- periodicKeyFrame = SDP.PERIODIC_KEYFRAME;
58
- sdpLines.splice(index + 2, 0, periodicKeyFrame);
59
- }
60
- sdpLines.splice(index + 1, 0, `${SDP.B_LINE}:${limit}`);
61
-
62
- return sdpLines;
63
- };
64
-
65
- /**
66
- * needed for calliope max-fs
67
- * @param {String} sdp
68
- * @param {String} [level=QUALITY_LEVELS.HIGH] quality level for max-fs
69
- * @returns {String}
70
- */
71
- const setRemoteVideoConstraints = (sdp: string, level: string = QUALITY_LEVELS.HIGH) => {
72
- const maxFs = REMOTE_VIDEO_CONSTRAINTS.MAX_FS[level];
73
-
74
- if (!maxFs) {
75
- throw new ParameterError(
76
- `setRemoteVideoConstraints: unable to set max framesize, value for level "${level}" is not defined`
77
- );
78
- }
79
-
80
- const modifiedSdp = PeerConnectionUtils.adjustH264Profile(sdp, maxFs);
81
-
82
- return modifiedSdp;
83
- };
84
-
85
- const setStartBitrateOnRemoteSdp = (sdp) => {
86
- if (StaticConfig.meetings.bandwidth.startBitrate) {
87
- sdp = sdp.replace(
88
- /(\na=fmtp:(\d+).*profile-level-id=.*)/gi,
89
- `$1;x-google-start-bitrate=${StaticConfig.meetings.bandwidth.startBitrate}`
90
- );
91
- }
92
-
93
- return sdp;
94
- };
95
-
96
- /**
97
- * checks that sdp has h264 codec in it
98
- * @param {String} sdp
99
- * @returns {boolean}
100
- */
101
- const checkH264Support = (sdp: string) => {
102
- // eslint-disable-next-line no-warning-comments
103
- // TODO convert to sdp parser to read rtp.codec
104
- const videoPresent = sdp.match(/\nm=video.*/g);
105
- const h264Present = sdp.match(/\na=rtpmap:\d+\sH264.*/g);
106
-
107
- if (videoPresent) {
108
- return !!h264Present;
109
- }
110
-
111
- return true;
112
- };
113
-
114
- /**
115
- * validates the sdp, checks port, candidates, and ice info
116
- * @param {String} sdp
117
- * @returns {String}
118
- */
119
- const isSdpInvalid = (sdp: string) => {
120
- const parsedSdp = sdpTransform.parse(sdp);
121
-
122
- for (const mediaLine of parsedSdp.media) {
123
- if (!mediaLine.candidates || mediaLine.candidates?.length === 0) {
124
- LoggerProxy.logger.error(
125
- 'PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Ice candidate never completed'
126
- );
127
-
128
- return 'iceCandidate: Ice gathering never completed';
129
- }
130
-
131
- if (SDP.BAD_MEDIA_PORTS.includes(mediaLine.port)) {
132
- LoggerProxy.logger.error(
133
- 'PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Found invalid port number for the ice candidate'
134
- );
135
-
136
- return 'iceCandidate: Found invalid port number for the ice candidate';
137
- }
138
- if (!mediaLine.icePwd || !mediaLine.iceUfrag) {
139
- LoggerProxy.logger.error(
140
- 'PeerConnectionManager:index#isSdpInvalid --> iceCandidate: ice ufrag and password not found'
141
- );
142
-
143
- return 'iceCandidate: ice ufrag and password not found';
144
- }
145
- }
146
-
147
- return '';
148
- };
149
-
150
- /**
151
- * munges the bandwidth into the sdp
152
- * @param {String} sdp
153
- * @returns {String}
154
- */
155
- const limitBandwidth = (sdp: string) => {
156
- // TODO convert to sdp parser
157
- let offerSdp = sdp;
158
- let sdpLines = offerSdp.split(SDP.CARRIAGE_RETURN);
159
-
160
- for (let i = 0; i < sdpLines.length; i += 1) {
161
- if (sdpLines[i].search(SDP.M_LINE) !== -1) {
162
- sdpLines = insertBandwidthLimit(sdpLines, i);
163
- }
164
- }
165
- offerSdp = sdpLines.join(SDP.CARRIAGE_RETURN);
166
-
167
- return offerSdp;
168
- };
169
-
170
- /**
171
- * makes sure the screen pc sdp has content:slides for server
172
- * @param {RTCPeerConnection} screenPc
173
- * @returns {RTCPeerConnection}
174
- */
175
- pc.setContentSlides = (screenPc: any) => {
176
- if (screenPc && screenPc.sdp) {
177
- screenPc.sdp += `${SDP.A_CONTENT_SLIDES}${SDP.CARRIAGE_RETURN}`;
178
- }
179
-
180
- return screenPc;
181
- };
182
-
183
- /**
184
- * handles ice trickling and establishes ICE connection onto peer connection object
185
- * @param {Object} peerConnection
186
- * @param {Object} options
187
- * @param {String} options.remoteQualityLevel
188
- * @returns {Promise.RTCPeerConnection}
189
- */
190
- pc.iceCandidate = (
191
- peerConnection: any,
192
- {
193
- remoteQualityLevel,
194
- }: {
195
- remoteQualityLevel: string;
196
- }
197
- ) =>
198
- new Promise<void>((resolve, reject) => {
199
- const now = Date.now();
200
- const doneGatheringIceCandidate = () => {
201
- // @ts-ignore
202
- const miliseconds = parseInt(Math.abs(Date.now() - now), 4);
203
-
204
- peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
205
- peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
206
- peerConnection.sdp = setRemoteVideoConstraints(peerConnection.sdp, remoteQualityLevel);
207
-
208
- const invalidSdpPresent = isSdpInvalid(peerConnection.sdp);
209
-
210
- if (invalidSdpPresent) {
211
- LoggerProxy.logger.error(
212
- 'PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.'
213
- );
214
- reject(new InvalidSdpError(invalidSdpPresent));
215
- }
216
- LoggerProxy.logger.log(
217
- `PeerConnectionManager:index#iceCandidate --> Time to gather ice candidate ${miliseconds} miliseconds`
218
- );
219
-
220
- resolve();
221
- };
222
-
223
- // If ice has already been gathered
224
- if (peerConnection.iceGatheringState === COMPLETE) {
225
- doneGatheringIceCandidate();
226
- }
227
-
228
- peerConnection.onIceGatheringStateChange = () => {
229
- if (peerConnection.iceGatheringState === COMPLETE) {
230
- // @ts-ignore
231
- doneGatheringIceCandidate(peerConnection);
232
- }
233
- if (peerConnection.iceGatheringState === GATHERING) {
234
- LoggerProxy.logger.log(
235
- 'PeerConnectionManager:index#onIceGatheringStateChange --> Ice state changed to gathering'
236
- );
237
- }
238
- };
239
-
240
- peerConnection.onicecandidate = (evt) => {
241
- if (evt.candidate === null) {
242
- // @ts-ignore
243
- doneGatheringIceCandidate(peerConnection);
244
- } else {
245
- LoggerProxy.logger.log(
246
- `PeerConnectionManager:index#onicecandidate --> Candidate ${evt.candidate?.type} ${evt.candidate?.protocol} ${evt.candidate?.address}:${evt.candidate?.port}`
247
- );
248
- }
249
- };
250
-
251
- peerConnection.onicecandidateerror = (event) => {
252
- // we can often get ICE candidate errors (for example when failing to communicate with a TURN server)
253
- // they don't mean that the whole ICE connection will fail, so it's OK to ignore them
254
- LoggerProxy.logger.error(
255
- 'PeerConnectionManager:index#onicecandidateerror --> ignoring ice error:',
256
- event
257
- );
258
- };
259
- });
260
-
261
- /**
262
- * swapping tracks
263
- * @param {Object} peerConnection
264
- * @param {Object} track
265
- * @returns {undefined}
266
- */
267
- pc.replaceTrack = (peerConnection: any, track: any) => {
268
- try {
269
- const senders = peerConnection.getSenders();
270
-
271
- if (senders.length > 0) {
272
- senders.forEach((sender) => {
273
- if (sender.track && sender.track.kind === track.kind) {
274
- sender.replaceTrack(track);
275
- }
276
- });
277
- }
278
- } catch (err) {
279
- LoggerProxy.logger.error(
280
- `PeerConnectionManager:index#replaceTrack --> Error replacing track, ${err}`
281
- );
282
- }
283
- };
284
-
285
- /**
286
- * adding streams to peerConnection
287
- * @param {Object} peerConnection
288
- * @param {Object} stream
289
- * @returns {undefined}
290
- */
291
- pc.addStream = (peerConnection: any, stream: any) => {
292
- try {
293
- if (stream && !isBrowser('edge')) {
294
- const tracksPresent =
295
- peerConnection.getSenders &&
296
- peerConnection.getSenders().find((sender) => sender.track != null);
297
-
298
- if (tracksPresent) {
299
- stream.getTracks().forEach((track) => {
300
- pc.replaceTrack(peerConnection, track);
301
- });
302
-
303
- return;
304
- }
305
- stream.getTracks().forEach((track) => {
306
- peerConnection.addTrack(track, stream);
307
- });
308
- // // TODO : may come back disable addTracks for chrome they are moving back to addStream
309
- // // https://bugs.chromium.org/p/chromium/issues/detail?id=764414
310
- // // https://bugs.chromium.org/p/chromium/issues/detail?id=738918#c7
311
- // peerConnection.addStream(stream);
312
- } else if (isBrowser('edge')) {
313
- peerConnection.addStream(stream);
314
- }
315
- } catch (err) {
316
- LoggerProxy.logger.error(
317
- `PeerConnectionManager:index#addStream --> Error adding stream, error: ${error}`
318
- );
319
- }
320
- };
321
-
322
- /**
323
- * setting the remote description
324
- * @param {Object} peerConnection
325
- * @param {String} typeStr
326
- * @param {String} remoteSdp
327
- * @param {String} meetingId
328
- * @returns {undefined}
329
- */
330
- pc.setRemoteSessionDetails = (
331
- peerConnection: any,
332
- typeStr: string,
333
- remoteSdp: string,
334
- meetingId: string
335
- ) => {
336
- LoggerProxy.logger.log(
337
- `PeerConnectionManager:index#setRemoteSessionDetails --> Setting the remote description type: ${typeStr}State: ${peerConnection.signalingState}`
338
- );
339
- let sdp = remoteSdp;
340
-
341
- // making sure that the remoteDescription is only set when there is a answer for offer
342
- // or there is a offer from the server
343
-
344
- if (!sdp) {
345
- Metrics.postEvent({
346
- event: eventType.REMOTE_SDP_RECEIVED,
347
- meetingId,
348
- data: {
349
- canProceed: false,
350
- errors: [
351
- Metrics.generateErrorPayload(2001, true, error.name.MEDIA_ENGINE, 'missing remoteSdp'),
352
- ],
353
- },
354
- });
355
- }
356
- if (
357
- peerConnection.signalingState === SDP.HAVE_LOCAL_OFFER ||
358
- (peerConnection.signalingState === SDP.STABLE && typeStr === SDP.OFFER)
359
- ) {
360
- sdp = setStartBitrateOnRemoteSdp(sdp);
361
-
362
- if (!peerConnection.enableExtmap) {
363
- sdp = sdp.replace(/\na=extmap.*/g, '');
364
- }
365
-
366
- // remove any xtls candidates
367
- sdp = sdp.replace(/^a=candidate:.*xTLS.*\r\n/gim, '');
368
-
369
- return (
370
- peerConnection
371
- .setRemoteDescription(
372
- new window.RTCSessionDescription({
373
- type: typeStr,
374
- sdp,
375
- })
376
- )
377
- .then(() => {
378
- if (peerConnection.signalingState === SDP.STABLE) {
379
- Metrics.postEvent({
380
- event: eventType.REMOTE_SDP_RECEIVED,
381
- meetingId,
382
- });
383
- }
384
- })
385
- // eslint-disable-next-line @typescript-eslint/no-shadow
386
- .catch((error) => {
387
- LoggerProxy.logger.error(
388
- `Peer-connection-manager:index#setRemoteDescription --> ${error} missing remotesdp`
389
- );
390
-
391
- const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
392
- const data = {
393
- correlation_id: meetingId,
394
- reason: error.message,
395
- stack: error.stack,
396
- };
397
- const metadata = {
398
- type: error.name,
399
- };
400
-
401
- Metrics.sendBehavioralMetric(metricName, data, metadata);
402
-
403
- return Metrics.postEvent({
404
- event: eventType.REMOTE_SDP_RECEIVED,
405
- meetingId,
406
- data: {
407
- canProceed: false,
408
- errors: [
409
- Metrics.generateErrorPayload(
410
- 2001,
411
- true,
412
- error.name.MEDIA_ENGINE,
413
- 'missing remoteSdp'
414
- ),
415
- ],
416
- },
417
- });
418
- })
419
- );
420
- }
421
-
422
- return Promise.reject(new MediaError('PeerConnection in wrong state'));
423
- };
424
-
425
- /**
426
- * Create offer with a valid parameter
427
- * @param {Object} peerConnection
428
- * @param {Object} meetingProperties
429
- * @param {string} meetingProperties.meetingId
430
- * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
431
- * @param {string} meetingProperties.enableRtx
432
- * @param {string} meetingProperties.enableExtmap
433
- * @returns {RTCPeerConnection}
434
- */
435
- pc.createOffer = (
436
- peerConnection: any,
437
- {
438
- meetingId,
439
- remoteQualityLevel,
440
- enableRtx,
441
- enableExtmap,
442
- }: {
443
- meetingId: string;
444
- remoteQualityLevel: string;
445
- enableRtx: string;
446
- enableExtmap: string;
447
- }
448
- ) => {
449
- LoggerProxy.logger.log('PeerConnectionManager:index#createOffer --> creating a new offer');
450
-
451
- // saving the extMap State to use in setRemoteDescription
452
-
453
- peerConnection.enableExtmap = enableExtmap;
454
-
455
- return (
456
- peerConnection
457
- .createOffer()
458
- .then((description) => {
459
- // bug https://bugs.chromium.org/p/chromium/issues/detail?id=1020642
460
- // chrome currently generates RTX line irrespective of whether the server side supports it
461
- // we are removing apt as well because its associated with rtx line
462
-
463
- if (!enableRtx) {
464
- description.sdp = description.sdp.replace(/\r\na=rtpmap:\d+ rtx\/\d+/g, '');
465
- description.sdp = description.sdp.replace(/\r\na=fmtp:\d+ apt=\d+/g, '');
466
- }
467
-
468
- return peerConnection.setLocalDescription(description);
469
- })
470
- .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))
471
- .then(() => {
472
- if (!checkH264Support(peerConnection.sdp)) {
473
- throw new MediaError(
474
- 'openH264 is downloading please Wait. Upload logs if not working on second try'
475
- );
476
- }
477
-
478
- if (!enableExtmap) {
479
- peerConnection.sdp = peerConnection.sdp.replace(/\na=extmap.*/g, '');
480
- }
481
-
482
- pc.setContentSlides(peerConnection);
483
-
484
- Metrics.postEvent({
485
- event: eventType.LOCAL_SDP_GENERATED,
486
- meetingId,
487
- });
488
-
489
- return peerConnection;
490
- })
491
- // eslint-disable-next-line @typescript-eslint/no-shadow
492
- .catch((error) => {
493
- LoggerProxy.logger.error(`Peer-connection-manager:index#createOffer --> ${error}`);
494
- if (error instanceof InvalidSdpError) {
495
- Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.INVALID_ICE_CANDIDATE, {
496
- correlation_id: meetingId,
497
- code: error.code,
498
- reason: error.message,
499
- });
500
- } else {
501
- const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
502
- const data = {
503
- correlation_id: meetingId,
504
- reason: error.message,
505
- stack: error.stack,
506
- };
507
- const metadata = {
508
- type: error.name,
509
- };
510
-
511
- Metrics.sendBehavioralMetric(metricName, data, metadata);
512
- }
513
-
514
- Metrics.postEvent({
515
- event: eventType.LOCAL_SDP_GENERATED,
516
- meetingId,
517
- data: {
518
- canProceed: false,
519
- errors: [
520
- // @ts-ignore
521
- Metrics.generateErrorPayload(2001, true, error.name.MEDIA_ENGINE),
522
- ],
523
- },
524
- });
525
- pc.close(peerConnection);
526
- throw error;
527
- })
528
- );
529
- };
530
-
531
- /**
532
- * rollBack local description in peerconnection
533
- * @param {Object} peerConnection
534
- * @returns {Promise.RTCPeerConnection}
535
- */
536
- pc.rollBackLocalDescription = (peerConnection: any) =>
537
- peerConnection
538
- // @ts-ignore
539
- .setLocalDescription(new RTCSessionDescription({type: SDP.ROLLBACK}))
540
- .then(() => peerConnection)
541
- .catch((err) => {
542
- LoggerProxy.logger.error(`Peer-connection-manager:index#setLocalDescription --> ${err} `);
543
-
544
- // @ts-ignore
545
- return Promise.error(err);
546
- });
547
-
548
- /**
549
- * @param {Object} params {
550
- * @param {Boolean} params.offerToReceiveAudio
551
- * @param {Boolean} params.offerToReceiveVideo
552
- * @param {string} params.offerSdp
553
- * @param {MediaStream} params.stream
554
- * @param {Object} meetingProperties
555
- * @param {string} meetingProperties.meetingId
556
- * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
557
- * @returns {Promise.<Array>} [MediaSDP, ScreenSDP]
558
- */
559
- pc.updatePeerConnection = (
560
- params: {
561
- offerToReceiveAudio: boolean;
562
- offerToReceiveVideo: boolean;
563
- offerSdp: string;
564
- stream: MediaStream;
565
- peerConnection: any;
566
- },
567
- {
568
- meetingId,
569
- remoteQualityLevel,
570
- }: {
571
- meetingId: string;
572
- remoteQualityLevel: string;
573
- }
574
- ) => {
575
- LoggerProxy.logger.log(
576
- `PeerConnectionManager:index#updatePeerConnection --> updating the peerConnection with params: ${params}`
577
- );
578
-
579
- const {peerConnection, offerSdp} = params;
580
-
581
- return pc
582
- .createAnswer(
583
- {
584
- peerConnection,
585
- offerSdp: offerSdp[0],
586
- },
587
- {meetingId, remoteQualityLevel}
588
- )
589
- .then((peerconnection) => {
590
- // The content slides should also be set when we are sending inactive
591
- pc.setContentSlides(peerconnection);
592
-
593
- return Promise.resolve([peerconnection.sdp]);
594
- });
595
- };
596
-
597
- /**
598
- * @param {Object} params
599
- * @param {Object} params.peerConnection
600
- * @param {Object} params.sdpConstraints
601
- * @param {Object} meetingProperties
602
- * @param {string} meetingProperties.meetingId
603
- * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
604
- * @returns {RTCPeerConnection} peerConnection
605
- */
606
- pc.createAnswer = (
607
- params: {
608
- peerConnection: any;
609
- sdpConstraints: object;
610
- offerSdp: any;
611
- },
612
- {
613
- meetingId,
614
- remoteQualityLevel,
615
- }: {
616
- meetingId: string;
617
- remoteQualityLevel: string;
618
- }
619
- ) => {
620
- const {peerConnection} = params;
621
-
622
- // TODO: Some times to many mercury event comes at the same time
623
- // Need to maintain state of peerconnection
624
- if (peerConnection.signalingState === SDP.HAVE_REMOTE_OFFER) {
625
- return Promise.resolve(peerConnection);
626
- }
627
-
628
- return (
629
- pc
630
- .setRemoteSessionDetails(peerConnection, OFFER, params.offerSdp, meetingId)
631
- .then(() => peerConnection.createAnswer(params.sdpConstraints))
632
- .then((answer) => peerConnection.setLocalDescription(answer))
633
- .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))
634
- .then(() => {
635
- peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
636
- peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
637
- peerConnection.sdp = setRemoteVideoConstraints(peerConnection.sdp, remoteQualityLevel);
638
-
639
- if (!checkH264Support(peerConnection.sdp)) {
640
- throw new MediaError(
641
- 'openH264 is downloading please Wait. Upload logs if not working on second try'
642
- );
643
- }
644
-
645
- return peerConnection;
646
- })
647
- // eslint-disable-next-line @typescript-eslint/no-shadow
648
- .catch((error) => {
649
- if (error instanceof InvalidSdpError) {
650
- Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.INVALID_ICE_CANDIDATE, {
651
- correlation_id: meetingId,
652
- });
653
- } else {
654
- const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
655
- const data = {
656
- correlation_id: meetingId,
657
- reason: error.message,
658
- stack: error.stack,
659
- };
660
- const metadata = {
661
- type: error.name,
662
- };
663
-
664
- Metrics.sendBehavioralMetric(metricName, data, metadata);
665
- }
666
-
667
- LoggerProxy.logger.error(
668
- `PeerConnectionManager:index#setRemoteSessionDetails --> Error creating remote session, error: ${error}`
669
- );
670
- })
671
- );
672
- };
673
-
674
- /**
675
- * shut down the peer connection
676
- * @param {Object} peerConnection
677
- * @returns {undefined}
678
- */
679
- pc.close = (peerConnection: any) => {
680
- // peerConnection.close() fails on firefox on network changes and gives a Dom exception
681
- // To avoid this we have added a try catch block.
682
- // Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=1274407 for more information
683
- LoggerProxy.logger.log(
684
- 'PeerConnectionManager:index#close --> pc: close() -> attempting to close the peer connection'
685
- );
686
-
687
- if (peerConnection && peerConnection.connectionState === PEER_CONNECTION_STATE.CLOSED) {
688
- LoggerProxy.logger.log(
689
- 'PeerConnectionManager:index#close --> pc: close() -> connection already closed'
690
- );
691
-
692
- return Promise.resolve();
693
- }
694
- LoggerProxy.logger.log(
695
- 'PeerConnectionManager:index#close --> pc: close() -> closing the mediaPeerConnection'
696
- );
697
-
698
- return Promise.resolve().then(() => {
699
- if (peerConnection && peerConnection.close) {
700
- peerConnection.close();
701
- }
702
- });
703
- };
704
-
705
- pc.setPeerConnectionEvents = (meeting) => {
706
- // In case ICE fail
707
- const {peerConnection} = meeting.mediaProperties;
708
-
709
- const connectionFailed = () => {
710
- if (meeting.reconnectionManager.iceState.resolve) {
711
- // DISCONNECTED state triggers first then it goes to FAILED STATE
712
- // sometimes the failed state can happen before 10 seconds (Which is the timer for the reconnect for ice disconnect)
713
- meeting.reconnectionManager.iceState.resolve();
714
- }
715
-
716
- meeting.reconnect({networkDisconnect: true});
717
- Metrics.postEvent({
718
- event: eventType.ICE_END,
719
- meeting,
720
- data: {
721
- canProceed: false,
722
- errors: [
723
- // @ts-ignore
724
- Metrics.generateErrorPayload(2004, false, error.name.MEDIA_ENGINE),
725
- ],
726
- },
727
- });
728
-
729
- meeting.uploadLogs({
730
- file: 'peer-connection-manager/index',
731
- function: 'connectionFailed',
732
- });
733
-
734
- Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.CONNECTION_FAILURE, {
735
- correlation_id: meeting.correlationId,
736
- locus_id: meeting.locusId,
737
- });
738
- };
739
-
740
- peerConnection.oniceconnectionstatechange = () => {
741
- LoggerProxy.logger.info(
742
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHANGE.'
743
- );
744
- switch (peerConnection.iceConnectionState) {
745
- case ICE_STATE.CHECKING:
746
- LoggerProxy.logger.info(
747
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHECKING.'
748
- );
749
- Metrics.postEvent({event: eventType.ICE_START, meeting});
750
- break;
751
- case ICE_STATE.COMPLETED:
752
- LoggerProxy.logger.info(
753
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE COMPLETED.'
754
- );
755
- break;
756
- case ICE_STATE.CONNECTED:
757
- // Ice connection state goes to connected when both client and server sends STUN packets and
758
- // Established connected between them. Firefox does not trigger COMPLETED and only trigger CONNECTED
759
- Metrics.postEvent({event: eventType.ICE_END, meeting});
760
- Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.CONNECTION_SUCCESS, {
761
- correlation_id: meeting.correlationId,
762
- locus_id: meeting.locusId,
763
- });
764
- meeting.setNetworkStatus(NETWORK_STATUS.CONNECTED);
765
- meeting.reconnectionManager.iceReconnected();
766
- LoggerProxy.logger.info(
767
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CONNECTED.'
768
- );
769
- break;
770
- case ICE_STATE.CLOSED:
771
- LoggerProxy.logger.info(
772
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CLOSED.'
773
- );
774
- break;
775
- case ICE_STATE.DISCONNECTED:
776
- meeting.setNetworkStatus(NETWORK_STATUS.DISCONNECTED);
777
- meeting.reconnectionManager.waitForIceReconnect().catch(() => {
778
- LoggerProxy.logger.info(
779
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED. Automatic Reconnection Timed Out.'
780
- );
781
-
782
- connectionFailed();
783
- });
784
- LoggerProxy.logger.info(
785
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED.'
786
- );
787
- break;
788
- case ICE_STATE.FAILED:
789
- LoggerProxy.logger.info(
790
- 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE FAILED.'
791
- );
792
- // notify of ice failure
793
- // Ice failure is the only indicator currently for identifying the actual connection drop
794
- // Firefox takes sometime 10-15 seconds to go to failed state
795
- connectionFailed();
796
- break;
797
- default:
798
- break;
799
- }
800
- };
801
-
802
- peerConnection.onconnectionstatechange = () => {
803
- LoggerProxy.logger.info(
804
- 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CHANGE.'
805
- );
806
- switch (peerConnection.connectionState) {
807
- case CONNECTION_STATE.NEW:
808
- LoggerProxy.logger.info(
809
- 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE NEW.'
810
- );
811
- break;
812
- case CONNECTION_STATE.CONNECTING:
813
- LoggerProxy.logger.info(
814
- 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTING.'
815
- );
816
- break;
817
- case CONNECTION_STATE.CONNECTED:
818
- LoggerProxy.logger.info(
819
- 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTED.'
820
- );
821
- break;
822
- case CONNECTION_STATE.CLOSED:
823
- LoggerProxy.logger.info(
824
- 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CLOSED.'
825
- );
826
- break;
827
- case CONNECTION_STATE.DISCONNECTED:
828
- LoggerProxy.logger.info(
829
- 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE DISCONNECTED.'
830
- );
831
- break;
832
- case CONNECTION_STATE.FAILED:
833
- LoggerProxy.logger.info(
834
- 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE FAILED.'
835
- );
836
- // Special case happens only on chrome where there is no ICE FAILED event
837
- // only CONNECTION FAILED event gets triggered
838
-
839
- connectionFailed();
840
- break;
841
- default:
842
- break;
843
- }
844
- };
845
- };
846
-
847
- export default pc;
1
+ // We need to figure out how to pass a webex logger instance to these util files
2
+
3
+ /* globals RTCSessionDescription */
4
+
5
+ import window from 'global/window';
6
+ import sdpTransform from 'sdp-transform'; // https://github.com/clux/sdp-transform
7
+
8
+ import Metrics from '../metrics';
9
+ import LoggerProxy from '../common/logs/logger-proxy';
10
+ import StaticConfig from '../common/config';
11
+ import {
12
+ COMPLETE,
13
+ GATHERING,
14
+ AUDIO,
15
+ SDP,
16
+ ICE_STATE,
17
+ CONNECTION_STATE,
18
+ NETWORK_STATUS,
19
+ PEER_CONNECTION_STATE,
20
+ OFFER,
21
+ QUALITY_LEVELS,
22
+ REMOTE_VIDEO_CONSTRAINTS,
23
+ } from '../constants';
24
+ import BEHAVIORAL_METRICS from '../metrics/constants';
25
+ import {error, eventType} from '../metrics/config';
26
+ import MediaError from '../common/errors/media';
27
+ import ParameterError from '../common/errors/parameter';
28
+ import {InvalidSdpError} from '../common/errors/webex-errors';
29
+ import BrowserDetection from '../common/browser-detection';
30
+
31
+ import PeerConnectionUtils from './util';
32
+
33
+ const {isBrowser} = BrowserDetection();
34
+
35
+ /**
36
+ * @export
37
+ * @public
38
+ */
39
+ const pc: any = {};
40
+
41
+ /**
42
+ * munges the bandwidth limit into the sdp
43
+ * @param {String} sdpLines
44
+ * @param {Number} index
45
+ * @returns {String}
46
+ */
47
+ const insertBandwidthLimit = (sdpLines: any, index: number) => {
48
+ // eslint-disable-next-line no-warning-comments
49
+ // TODO convert to sdp parser
50
+ let limit;
51
+ let periodicKeyFrame = '';
52
+
53
+ if (sdpLines[index].search(AUDIO) !== -1) {
54
+ limit = StaticConfig.meetings.bandwidth.audio;
55
+ } else {
56
+ limit = StaticConfig.meetings.bandwidth.video;
57
+ periodicKeyFrame = SDP.PERIODIC_KEYFRAME;
58
+ sdpLines.splice(index + 2, 0, periodicKeyFrame);
59
+ }
60
+ sdpLines.splice(index + 1, 0, `${SDP.B_LINE}:${limit}`);
61
+
62
+ return sdpLines;
63
+ };
64
+
65
+ /**
66
+ * needed for calliope max-fs
67
+ * @param {String} sdp
68
+ * @param {String} [level=QUALITY_LEVELS.HIGH] quality level for max-fs
69
+ * @returns {String}
70
+ */
71
+ const setRemoteVideoConstraints = (sdp: string, level: string = QUALITY_LEVELS.HIGH) => {
72
+ const maxFs = REMOTE_VIDEO_CONSTRAINTS.MAX_FS[level];
73
+
74
+ if (!maxFs) {
75
+ throw new ParameterError(
76
+ `setRemoteVideoConstraints: unable to set max framesize, value for level "${level}" is not defined`
77
+ );
78
+ }
79
+
80
+ const modifiedSdp = PeerConnectionUtils.adjustH264Profile(sdp, maxFs);
81
+
82
+ return modifiedSdp;
83
+ };
84
+
85
+ const setStartBitrateOnRemoteSdp = (sdp) => {
86
+ if (StaticConfig.meetings.bandwidth.startBitrate) {
87
+ sdp = sdp.replace(
88
+ /(\na=fmtp:(\d+).*profile-level-id=.*)/gi,
89
+ `$1;x-google-start-bitrate=${StaticConfig.meetings.bandwidth.startBitrate}`
90
+ );
91
+ }
92
+
93
+ return sdp;
94
+ };
95
+
96
+ /**
97
+ * checks that sdp has h264 codec in it
98
+ * @param {String} sdp
99
+ * @returns {boolean}
100
+ */
101
+ const checkH264Support = (sdp: string) => {
102
+ // eslint-disable-next-line no-warning-comments
103
+ // TODO convert to sdp parser to read rtp.codec
104
+ const videoPresent = sdp.match(/\nm=video.*/g);
105
+ const h264Present = sdp.match(/\na=rtpmap:\d+\sH264.*/g);
106
+
107
+ if (videoPresent) {
108
+ return !!h264Present;
109
+ }
110
+
111
+ return true;
112
+ };
113
+
114
+ /**
115
+ * validates the sdp, checks port, candidates, and ice info
116
+ * @param {String} sdp
117
+ * @returns {String}
118
+ */
119
+ const isSdpInvalid = (sdp: string) => {
120
+ const parsedSdp = sdpTransform.parse(sdp);
121
+
122
+ for (const mediaLine of parsedSdp.media) {
123
+ if (!mediaLine.candidates || mediaLine.candidates?.length === 0) {
124
+ LoggerProxy.logger.error(
125
+ 'PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Ice candidate never completed'
126
+ );
127
+
128
+ return 'iceCandidate: Ice gathering never completed';
129
+ }
130
+
131
+ if (SDP.BAD_MEDIA_PORTS.includes(mediaLine.port)) {
132
+ LoggerProxy.logger.error(
133
+ 'PeerConnectionManager:index#isSdpInvalid --> iceCandidate: Found invalid port number for the ice candidate'
134
+ );
135
+
136
+ return 'iceCandidate: Found invalid port number for the ice candidate';
137
+ }
138
+ if (!mediaLine.icePwd || !mediaLine.iceUfrag) {
139
+ LoggerProxy.logger.error(
140
+ 'PeerConnectionManager:index#isSdpInvalid --> iceCandidate: ice ufrag and password not found'
141
+ );
142
+
143
+ return 'iceCandidate: ice ufrag and password not found';
144
+ }
145
+ }
146
+
147
+ return '';
148
+ };
149
+
150
+ /**
151
+ * munges the bandwidth into the sdp
152
+ * @param {String} sdp
153
+ * @returns {String}
154
+ */
155
+ const limitBandwidth = (sdp: string) => {
156
+ // TODO convert to sdp parser
157
+ let offerSdp = sdp;
158
+ let sdpLines = offerSdp.split(SDP.CARRIAGE_RETURN);
159
+
160
+ for (let i = 0; i < sdpLines.length; i += 1) {
161
+ if (sdpLines[i].search(SDP.M_LINE) !== -1) {
162
+ sdpLines = insertBandwidthLimit(sdpLines, i);
163
+ }
164
+ }
165
+ offerSdp = sdpLines.join(SDP.CARRIAGE_RETURN);
166
+
167
+ return offerSdp;
168
+ };
169
+
170
+ /**
171
+ * makes sure the screen pc sdp has content:slides for server
172
+ * @param {RTCPeerConnection} screenPc
173
+ * @returns {RTCPeerConnection}
174
+ */
175
+ pc.setContentSlides = (screenPc: any) => {
176
+ if (screenPc && screenPc.sdp) {
177
+ screenPc.sdp += `${SDP.A_CONTENT_SLIDES}${SDP.CARRIAGE_RETURN}`;
178
+ }
179
+
180
+ return screenPc;
181
+ };
182
+
183
+ /**
184
+ * handles ice trickling and establishes ICE connection onto peer connection object
185
+ * @param {Object} peerConnection
186
+ * @param {Object} options
187
+ * @param {String} options.remoteQualityLevel
188
+ * @returns {Promise.RTCPeerConnection}
189
+ */
190
+ pc.iceCandidate = (
191
+ peerConnection: any,
192
+ {
193
+ remoteQualityLevel,
194
+ }: {
195
+ remoteQualityLevel: string;
196
+ }
197
+ ) =>
198
+ new Promise<void>((resolve, reject) => {
199
+ const now = Date.now();
200
+ const doneGatheringIceCandidate = () => {
201
+ // @ts-ignore
202
+ const miliseconds = parseInt(Math.abs(Date.now() - now), 4);
203
+
204
+ peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
205
+ peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
206
+ peerConnection.sdp = setRemoteVideoConstraints(peerConnection.sdp, remoteQualityLevel);
207
+
208
+ const invalidSdpPresent = isSdpInvalid(peerConnection.sdp);
209
+
210
+ if (invalidSdpPresent) {
211
+ LoggerProxy.logger.error(
212
+ 'PeerConnectionManager:index#iceCandidate --> SDP not valid after waiting.'
213
+ );
214
+ reject(new InvalidSdpError(invalidSdpPresent));
215
+ }
216
+ LoggerProxy.logger.log(
217
+ `PeerConnectionManager:index#iceCandidate --> Time to gather ice candidate ${miliseconds} miliseconds`
218
+ );
219
+
220
+ resolve();
221
+ };
222
+
223
+ // If ice has already been gathered
224
+ if (peerConnection.iceGatheringState === COMPLETE) {
225
+ doneGatheringIceCandidate();
226
+ }
227
+
228
+ peerConnection.onIceGatheringStateChange = () => {
229
+ if (peerConnection.iceGatheringState === COMPLETE) {
230
+ // @ts-ignore
231
+ doneGatheringIceCandidate(peerConnection);
232
+ }
233
+ if (peerConnection.iceGatheringState === GATHERING) {
234
+ LoggerProxy.logger.log(
235
+ 'PeerConnectionManager:index#onIceGatheringStateChange --> Ice state changed to gathering'
236
+ );
237
+ }
238
+ };
239
+
240
+ peerConnection.onicecandidate = (evt) => {
241
+ if (evt.candidate === null) {
242
+ // @ts-ignore
243
+ doneGatheringIceCandidate(peerConnection);
244
+ } else {
245
+ LoggerProxy.logger.log(
246
+ `PeerConnectionManager:index#onicecandidate --> Candidate ${evt.candidate?.type} ${evt.candidate?.protocol} ${evt.candidate?.address}:${evt.candidate?.port}`
247
+ );
248
+ }
249
+ };
250
+
251
+ peerConnection.onicecandidateerror = (event) => {
252
+ // we can often get ICE candidate errors (for example when failing to communicate with a TURN server)
253
+ // they don't mean that the whole ICE connection will fail, so it's OK to ignore them
254
+ LoggerProxy.logger.error(
255
+ 'PeerConnectionManager:index#onicecandidateerror --> ignoring ice error:',
256
+ event
257
+ );
258
+ };
259
+ });
260
+
261
+ /**
262
+ * swapping tracks
263
+ * @param {Object} peerConnection
264
+ * @param {Object} track
265
+ * @returns {undefined}
266
+ */
267
+ pc.replaceTrack = (peerConnection: any, track: any) => {
268
+ try {
269
+ const senders = peerConnection.getSenders();
270
+
271
+ if (senders.length > 0) {
272
+ senders.forEach((sender) => {
273
+ if (sender.track && sender.track.kind === track.kind) {
274
+ sender.replaceTrack(track);
275
+ }
276
+ });
277
+ }
278
+ } catch (err) {
279
+ LoggerProxy.logger.error(
280
+ `PeerConnectionManager:index#replaceTrack --> Error replacing track, ${err}`
281
+ );
282
+ }
283
+ };
284
+
285
+ /**
286
+ * adding streams to peerConnection
287
+ * @param {Object} peerConnection
288
+ * @param {Object} stream
289
+ * @returns {undefined}
290
+ */
291
+ pc.addStream = (peerConnection: any, stream: any) => {
292
+ try {
293
+ if (stream && !isBrowser('edge')) {
294
+ const tracksPresent =
295
+ peerConnection.getSenders &&
296
+ peerConnection.getSenders().find((sender) => sender.track != null);
297
+
298
+ if (tracksPresent) {
299
+ stream.getTracks().forEach((track) => {
300
+ pc.replaceTrack(peerConnection, track);
301
+ });
302
+
303
+ return;
304
+ }
305
+ stream.getTracks().forEach((track) => {
306
+ peerConnection.addTrack(track, stream);
307
+ });
308
+ // // TODO : may come back disable addTracks for chrome they are moving back to addStream
309
+ // // https://bugs.chromium.org/p/chromium/issues/detail?id=764414
310
+ // // https://bugs.chromium.org/p/chromium/issues/detail?id=738918#c7
311
+ // peerConnection.addStream(stream);
312
+ } else if (isBrowser('edge')) {
313
+ peerConnection.addStream(stream);
314
+ }
315
+ } catch (err) {
316
+ LoggerProxy.logger.error(
317
+ `PeerConnectionManager:index#addStream --> Error adding stream, error: ${error}`
318
+ );
319
+ }
320
+ };
321
+
322
+ /**
323
+ * setting the remote description
324
+ * @param {Object} peerConnection
325
+ * @param {String} typeStr
326
+ * @param {String} remoteSdp
327
+ * @param {String} meetingId
328
+ * @returns {undefined}
329
+ */
330
+ pc.setRemoteSessionDetails = (
331
+ peerConnection: any,
332
+ typeStr: string,
333
+ remoteSdp: string,
334
+ meetingId: string
335
+ ) => {
336
+ LoggerProxy.logger.log(
337
+ `PeerConnectionManager:index#setRemoteSessionDetails --> Setting the remote description type: ${typeStr}State: ${peerConnection.signalingState}`
338
+ );
339
+ let sdp = remoteSdp;
340
+
341
+ // making sure that the remoteDescription is only set when there is a answer for offer
342
+ // or there is a offer from the server
343
+
344
+ if (!sdp) {
345
+ Metrics.postEvent({
346
+ event: eventType.REMOTE_SDP_RECEIVED,
347
+ meetingId,
348
+ data: {
349
+ canProceed: false,
350
+ errors: [
351
+ Metrics.generateErrorPayload(2001, true, error.name.MEDIA_ENGINE, 'missing remoteSdp'),
352
+ ],
353
+ },
354
+ });
355
+ }
356
+ if (
357
+ peerConnection.signalingState === SDP.HAVE_LOCAL_OFFER ||
358
+ (peerConnection.signalingState === SDP.STABLE && typeStr === SDP.OFFER)
359
+ ) {
360
+ sdp = setStartBitrateOnRemoteSdp(sdp);
361
+
362
+ if (!peerConnection.enableExtmap) {
363
+ sdp = sdp.replace(/\na=extmap.*/g, '');
364
+ }
365
+
366
+ // remove any xtls candidates
367
+ sdp = sdp.replace(/^a=candidate:.*xTLS.*\r\n/gim, '');
368
+
369
+ return (
370
+ peerConnection
371
+ .setRemoteDescription(
372
+ new window.RTCSessionDescription({
373
+ type: typeStr,
374
+ sdp,
375
+ })
376
+ )
377
+ .then(() => {
378
+ if (peerConnection.signalingState === SDP.STABLE) {
379
+ Metrics.postEvent({
380
+ event: eventType.REMOTE_SDP_RECEIVED,
381
+ meetingId,
382
+ });
383
+ }
384
+ })
385
+ // eslint-disable-next-line @typescript-eslint/no-shadow
386
+ .catch((error) => {
387
+ LoggerProxy.logger.error(
388
+ `Peer-connection-manager:index#setRemoteDescription --> ${error} missing remotesdp`
389
+ );
390
+
391
+ const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
392
+ const data = {
393
+ correlation_id: meetingId,
394
+ reason: error.message,
395
+ stack: error.stack,
396
+ };
397
+ const metadata = {
398
+ type: error.name,
399
+ };
400
+
401
+ Metrics.sendBehavioralMetric(metricName, data, metadata);
402
+
403
+ return Metrics.postEvent({
404
+ event: eventType.REMOTE_SDP_RECEIVED,
405
+ meetingId,
406
+ data: {
407
+ canProceed: false,
408
+ errors: [
409
+ Metrics.generateErrorPayload(
410
+ 2001,
411
+ true,
412
+ error.name.MEDIA_ENGINE,
413
+ 'missing remoteSdp'
414
+ ),
415
+ ],
416
+ },
417
+ });
418
+ })
419
+ );
420
+ }
421
+
422
+ return Promise.reject(new MediaError('PeerConnection in wrong state'));
423
+ };
424
+
425
+ /**
426
+ * Create offer with a valid parameter
427
+ * @param {Object} peerConnection
428
+ * @param {Object} meetingProperties
429
+ * @param {string} meetingProperties.meetingId
430
+ * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
431
+ * @param {string} meetingProperties.enableRtx
432
+ * @param {string} meetingProperties.enableExtmap
433
+ * @returns {RTCPeerConnection}
434
+ */
435
+ pc.createOffer = (
436
+ peerConnection: any,
437
+ {
438
+ meetingId,
439
+ remoteQualityLevel,
440
+ enableRtx,
441
+ enableExtmap,
442
+ }: {
443
+ meetingId: string;
444
+ remoteQualityLevel: string;
445
+ enableRtx: string;
446
+ enableExtmap: string;
447
+ }
448
+ ) => {
449
+ LoggerProxy.logger.log('PeerConnectionManager:index#createOffer --> creating a new offer');
450
+
451
+ // saving the extMap State to use in setRemoteDescription
452
+
453
+ peerConnection.enableExtmap = enableExtmap;
454
+
455
+ return (
456
+ peerConnection
457
+ .createOffer()
458
+ .then((description) => {
459
+ // bug https://bugs.chromium.org/p/chromium/issues/detail?id=1020642
460
+ // chrome currently generates RTX line irrespective of whether the server side supports it
461
+ // we are removing apt as well because its associated with rtx line
462
+
463
+ if (!enableRtx) {
464
+ description.sdp = description.sdp.replace(/\r\na=rtpmap:\d+ rtx\/\d+/g, '');
465
+ description.sdp = description.sdp.replace(/\r\na=fmtp:\d+ apt=\d+/g, '');
466
+ }
467
+
468
+ return peerConnection.setLocalDescription(description);
469
+ })
470
+ .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))
471
+ .then(() => {
472
+ if (!checkH264Support(peerConnection.sdp)) {
473
+ throw new MediaError(
474
+ 'openH264 is downloading please Wait. Upload logs if not working on second try'
475
+ );
476
+ }
477
+
478
+ if (!enableExtmap) {
479
+ peerConnection.sdp = peerConnection.sdp.replace(/\na=extmap.*/g, '');
480
+ }
481
+
482
+ pc.setContentSlides(peerConnection);
483
+
484
+ Metrics.postEvent({
485
+ event: eventType.LOCAL_SDP_GENERATED,
486
+ meetingId,
487
+ });
488
+
489
+ return peerConnection;
490
+ })
491
+ // eslint-disable-next-line @typescript-eslint/no-shadow
492
+ .catch((error) => {
493
+ LoggerProxy.logger.error(`Peer-connection-manager:index#createOffer --> ${error}`);
494
+ if (error instanceof InvalidSdpError) {
495
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.INVALID_ICE_CANDIDATE, {
496
+ correlation_id: meetingId,
497
+ code: error.code,
498
+ reason: error.message,
499
+ });
500
+ } else {
501
+ const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
502
+ const data = {
503
+ correlation_id: meetingId,
504
+ reason: error.message,
505
+ stack: error.stack,
506
+ };
507
+ const metadata = {
508
+ type: error.name,
509
+ };
510
+
511
+ Metrics.sendBehavioralMetric(metricName, data, metadata);
512
+ }
513
+
514
+ Metrics.postEvent({
515
+ event: eventType.LOCAL_SDP_GENERATED,
516
+ meetingId,
517
+ data: {
518
+ canProceed: false,
519
+ errors: [
520
+ // @ts-ignore
521
+ Metrics.generateErrorPayload(2001, true, error.name.MEDIA_ENGINE),
522
+ ],
523
+ },
524
+ });
525
+ pc.close(peerConnection);
526
+ throw error;
527
+ })
528
+ );
529
+ };
530
+
531
+ /**
532
+ * rollBack local description in peerconnection
533
+ * @param {Object} peerConnection
534
+ * @returns {Promise.RTCPeerConnection}
535
+ */
536
+ pc.rollBackLocalDescription = (peerConnection: any) =>
537
+ peerConnection
538
+ // @ts-ignore
539
+ .setLocalDescription(new RTCSessionDescription({type: SDP.ROLLBACK}))
540
+ .then(() => peerConnection)
541
+ .catch((err) => {
542
+ LoggerProxy.logger.error(`Peer-connection-manager:index#setLocalDescription --> ${err} `);
543
+
544
+ // @ts-ignore
545
+ return Promise.error(err);
546
+ });
547
+
548
+ /**
549
+ * @param {Object} params {
550
+ * @param {Boolean} params.offerToReceiveAudio
551
+ * @param {Boolean} params.offerToReceiveVideo
552
+ * @param {string} params.offerSdp
553
+ * @param {MediaStream} params.stream
554
+ * @param {Object} meetingProperties
555
+ * @param {string} meetingProperties.meetingId
556
+ * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
557
+ * @returns {Promise.<Array>} [MediaSDP, ScreenSDP]
558
+ */
559
+ pc.updatePeerConnection = (
560
+ params: {
561
+ offerToReceiveAudio: boolean;
562
+ offerToReceiveVideo: boolean;
563
+ offerSdp: string;
564
+ stream: MediaStream;
565
+ peerConnection: any;
566
+ },
567
+ {
568
+ meetingId,
569
+ remoteQualityLevel,
570
+ }: {
571
+ meetingId: string;
572
+ remoteQualityLevel: string;
573
+ }
574
+ ) => {
575
+ LoggerProxy.logger.log(
576
+ `PeerConnectionManager:index#updatePeerConnection --> updating the peerConnection with params: ${params}`
577
+ );
578
+
579
+ const {peerConnection, offerSdp} = params;
580
+
581
+ return pc
582
+ .createAnswer(
583
+ {
584
+ peerConnection,
585
+ offerSdp: offerSdp[0],
586
+ },
587
+ {meetingId, remoteQualityLevel}
588
+ )
589
+ .then((peerconnection) => {
590
+ // The content slides should also be set when we are sending inactive
591
+ pc.setContentSlides(peerconnection);
592
+
593
+ return Promise.resolve([peerconnection.sdp]);
594
+ });
595
+ };
596
+
597
+ /**
598
+ * @param {Object} params
599
+ * @param {Object} params.peerConnection
600
+ * @param {Object} params.sdpConstraints
601
+ * @param {Object} meetingProperties
602
+ * @param {string} meetingProperties.meetingId
603
+ * @param {string} meetingProperties.remoteQualityLevel LOW|MEDIUM|HIGH
604
+ * @returns {RTCPeerConnection} peerConnection
605
+ */
606
+ pc.createAnswer = (
607
+ params: {
608
+ peerConnection: any;
609
+ sdpConstraints: object;
610
+ offerSdp: any;
611
+ },
612
+ {
613
+ meetingId,
614
+ remoteQualityLevel,
615
+ }: {
616
+ meetingId: string;
617
+ remoteQualityLevel: string;
618
+ }
619
+ ) => {
620
+ const {peerConnection} = params;
621
+
622
+ // TODO: Some times to many mercury event comes at the same time
623
+ // Need to maintain state of peerconnection
624
+ if (peerConnection.signalingState === SDP.HAVE_REMOTE_OFFER) {
625
+ return Promise.resolve(peerConnection);
626
+ }
627
+
628
+ return (
629
+ pc
630
+ .setRemoteSessionDetails(peerConnection, OFFER, params.offerSdp, meetingId)
631
+ .then(() => peerConnection.createAnswer(params.sdpConstraints))
632
+ .then((answer) => peerConnection.setLocalDescription(answer))
633
+ .then(() => pc.iceCandidate(peerConnection, {remoteQualityLevel}))
634
+ .then(() => {
635
+ peerConnection.sdp = limitBandwidth(peerConnection.localDescription.sdp);
636
+ peerConnection.sdp = PeerConnectionUtils.convertCLineToIpv4(peerConnection.sdp);
637
+ peerConnection.sdp = setRemoteVideoConstraints(peerConnection.sdp, remoteQualityLevel);
638
+
639
+ if (!checkH264Support(peerConnection.sdp)) {
640
+ throw new MediaError(
641
+ 'openH264 is downloading please Wait. Upload logs if not working on second try'
642
+ );
643
+ }
644
+
645
+ return peerConnection;
646
+ })
647
+ // eslint-disable-next-line @typescript-eslint/no-shadow
648
+ .catch((error) => {
649
+ if (error instanceof InvalidSdpError) {
650
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.INVALID_ICE_CANDIDATE, {
651
+ correlation_id: meetingId,
652
+ });
653
+ } else {
654
+ const metricName = BEHAVIORAL_METRICS.PEERCONNECTION_FAILURE;
655
+ const data = {
656
+ correlation_id: meetingId,
657
+ reason: error.message,
658
+ stack: error.stack,
659
+ };
660
+ const metadata = {
661
+ type: error.name,
662
+ };
663
+
664
+ Metrics.sendBehavioralMetric(metricName, data, metadata);
665
+ }
666
+
667
+ LoggerProxy.logger.error(
668
+ `PeerConnectionManager:index#setRemoteSessionDetails --> Error creating remote session, error: ${error}`
669
+ );
670
+ })
671
+ );
672
+ };
673
+
674
+ /**
675
+ * shut down the peer connection
676
+ * @param {Object} peerConnection
677
+ * @returns {undefined}
678
+ */
679
+ pc.close = (peerConnection: any) => {
680
+ // peerConnection.close() fails on firefox on network changes and gives a Dom exception
681
+ // To avoid this we have added a try catch block.
682
+ // Please refer to https://bugzilla.mozilla.org/show_bug.cgi?id=1274407 for more information
683
+ LoggerProxy.logger.log(
684
+ 'PeerConnectionManager:index#close --> pc: close() -> attempting to close the peer connection'
685
+ );
686
+
687
+ if (peerConnection && peerConnection.connectionState === PEER_CONNECTION_STATE.CLOSED) {
688
+ LoggerProxy.logger.log(
689
+ 'PeerConnectionManager:index#close --> pc: close() -> connection already closed'
690
+ );
691
+
692
+ return Promise.resolve();
693
+ }
694
+ LoggerProxy.logger.log(
695
+ 'PeerConnectionManager:index#close --> pc: close() -> closing the mediaPeerConnection'
696
+ );
697
+
698
+ return Promise.resolve().then(() => {
699
+ if (peerConnection && peerConnection.close) {
700
+ peerConnection.close();
701
+ }
702
+ });
703
+ };
704
+
705
+ pc.setPeerConnectionEvents = (meeting) => {
706
+ // In case ICE fail
707
+ const {peerConnection} = meeting.mediaProperties;
708
+
709
+ const connectionFailed = () => {
710
+ if (meeting.reconnectionManager.iceState.resolve) {
711
+ // DISCONNECTED state triggers first then it goes to FAILED STATE
712
+ // sometimes the failed state can happen before 10 seconds (Which is the timer for the reconnect for ice disconnect)
713
+ meeting.reconnectionManager.iceState.resolve();
714
+ }
715
+
716
+ meeting.reconnect({networkDisconnect: true});
717
+ Metrics.postEvent({
718
+ event: eventType.ICE_END,
719
+ meeting,
720
+ data: {
721
+ canProceed: false,
722
+ errors: [
723
+ // @ts-ignore
724
+ Metrics.generateErrorPayload(2004, false, error.name.MEDIA_ENGINE),
725
+ ],
726
+ },
727
+ });
728
+
729
+ meeting.uploadLogs({
730
+ file: 'peer-connection-manager/index',
731
+ function: 'connectionFailed',
732
+ });
733
+
734
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.CONNECTION_FAILURE, {
735
+ correlation_id: meeting.correlationId,
736
+ locus_id: meeting.locusId,
737
+ });
738
+ };
739
+
740
+ peerConnection.oniceconnectionstatechange = () => {
741
+ LoggerProxy.logger.info(
742
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHANGE.'
743
+ );
744
+ switch (peerConnection.iceConnectionState) {
745
+ case ICE_STATE.CHECKING:
746
+ LoggerProxy.logger.info(
747
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CHECKING.'
748
+ );
749
+ Metrics.postEvent({event: eventType.ICE_START, meeting});
750
+ break;
751
+ case ICE_STATE.COMPLETED:
752
+ LoggerProxy.logger.info(
753
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE COMPLETED.'
754
+ );
755
+ break;
756
+ case ICE_STATE.CONNECTED:
757
+ // Ice connection state goes to connected when both client and server sends STUN packets and
758
+ // Established connected between them. Firefox does not trigger COMPLETED and only trigger CONNECTED
759
+ Metrics.postEvent({event: eventType.ICE_END, meeting});
760
+ Metrics.sendBehavioralMetric(BEHAVIORAL_METRICS.CONNECTION_SUCCESS, {
761
+ correlation_id: meeting.correlationId,
762
+ locus_id: meeting.locusId,
763
+ });
764
+ meeting.setNetworkStatus(NETWORK_STATUS.CONNECTED);
765
+ meeting.reconnectionManager.iceReconnected();
766
+ LoggerProxy.logger.info(
767
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CONNECTED.'
768
+ );
769
+ break;
770
+ case ICE_STATE.CLOSED:
771
+ LoggerProxy.logger.info(
772
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE CLOSED.'
773
+ );
774
+ break;
775
+ case ICE_STATE.DISCONNECTED:
776
+ meeting.setNetworkStatus(NETWORK_STATUS.DISCONNECTED);
777
+ meeting.reconnectionManager.waitForIceReconnect().catch(() => {
778
+ LoggerProxy.logger.info(
779
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED. Automatic Reconnection Timed Out.'
780
+ );
781
+
782
+ connectionFailed();
783
+ });
784
+ LoggerProxy.logger.info(
785
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE DISCONNECTED.'
786
+ );
787
+ break;
788
+ case ICE_STATE.FAILED:
789
+ LoggerProxy.logger.info(
790
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> ICE STATE FAILED.'
791
+ );
792
+ // notify of ice failure
793
+ // Ice failure is the only indicator currently for identifying the actual connection drop
794
+ // Firefox takes sometime 10-15 seconds to go to failed state
795
+ connectionFailed();
796
+ break;
797
+ default:
798
+ break;
799
+ }
800
+ };
801
+
802
+ peerConnection.onconnectionstatechange = () => {
803
+ LoggerProxy.logger.info(
804
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CHANGE.'
805
+ );
806
+ switch (peerConnection.connectionState) {
807
+ case CONNECTION_STATE.NEW:
808
+ LoggerProxy.logger.info(
809
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE NEW.'
810
+ );
811
+ break;
812
+ case CONNECTION_STATE.CONNECTING:
813
+ LoggerProxy.logger.info(
814
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTING.'
815
+ );
816
+ break;
817
+ case CONNECTION_STATE.CONNECTED:
818
+ LoggerProxy.logger.info(
819
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CONNECTED.'
820
+ );
821
+ break;
822
+ case CONNECTION_STATE.CLOSED:
823
+ LoggerProxy.logger.info(
824
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE CLOSED.'
825
+ );
826
+ break;
827
+ case CONNECTION_STATE.DISCONNECTED:
828
+ LoggerProxy.logger.info(
829
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE DISCONNECTED.'
830
+ );
831
+ break;
832
+ case CONNECTION_STATE.FAILED:
833
+ LoggerProxy.logger.info(
834
+ 'PeerConnectionManager:index#setPeerConnectionEvents --> CONNECTION STATE FAILED.'
835
+ );
836
+ // Special case happens only on chrome where there is no ICE FAILED event
837
+ // only CONNECTION FAILED event gets triggered
838
+
839
+ connectionFailed();
840
+ break;
841
+ default:
842
+ break;
843
+ }
844
+ };
845
+ };
846
+
847
+ export default pc;