twilio-video 2.34.0 → 2.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (410) hide show
  1. package/.release.json +1 -2
  2. package/CHANGELOG.md +11 -0
  3. package/README.md +9 -10
  4. package/dist/twilio-video.js +29836 -32994
  5. package/dist/twilio-video.min.js +2 -23
  6. package/es5/cancelableroompromise.js +4 -4
  7. package/es5/cancelableroompromise.js.map +1 -1
  8. package/es5/connect.js +86 -90
  9. package/es5/connect.js.map +1 -1
  10. package/es5/createlocaltrack.js +7 -7
  11. package/es5/createlocaltrack.js.map +1 -1
  12. package/es5/createlocaltracks.js +111 -195
  13. package/es5/createlocaltracks.js.map +1 -1
  14. package/es5/data/receiver.js +16 -34
  15. package/es5/data/receiver.js.map +1 -1
  16. package/es5/data/sender.js +28 -47
  17. package/es5/data/sender.js.map +1 -1
  18. package/es5/data/transceiver.js +6 -24
  19. package/es5/data/transceiver.js.map +1 -1
  20. package/es5/data/transport.js +18 -37
  21. package/es5/data/transport.js.map +1 -1
  22. package/es5/encodingparameters.js +14 -33
  23. package/es5/encodingparameters.js.map +1 -1
  24. package/es5/eventemitter.js +2 -2
  25. package/es5/eventemitter.js.map +1 -1
  26. package/es5/eventtarget.js +12 -40
  27. package/es5/eventtarget.js.map +1 -1
  28. package/es5/index.js +21 -32
  29. package/es5/index.js.map +1 -1
  30. package/es5/insights/applicationmonitor.js +16 -18
  31. package/es5/insights/applicationmonitor.js.map +1 -1
  32. package/es5/insights/computepressuremonitor.js +33 -79
  33. package/es5/insights/computepressuremonitor.js.map +1 -1
  34. package/es5/insights/events/application.js +9 -10
  35. package/es5/insights/events/application.js.map +1 -1
  36. package/es5/insights/events/getusermedia.js +9 -10
  37. package/es5/insights/events/getusermedia.js.map +1 -1
  38. package/es5/insights/events/network.js +14 -16
  39. package/es5/insights/events/network.js.map +1 -1
  40. package/es5/insights/events/peerconnection.js +31 -44
  41. package/es5/insights/events/peerconnection.js.map +1 -1
  42. package/es5/insights/events/quality.js +13 -14
  43. package/es5/insights/events/quality.js.map +1 -1
  44. package/es5/insights/events/room.js +12 -13
  45. package/es5/insights/events/room.js.map +1 -1
  46. package/es5/insights/events/system.js +6 -7
  47. package/es5/insights/events/system.js.map +1 -1
  48. package/es5/insights/events/track.js +15 -18
  49. package/es5/insights/events/track.js.map +1 -1
  50. package/es5/insights/monitorregistry.js +10 -12
  51. package/es5/insights/monitorregistry.js.map +1 -1
  52. package/es5/insights/networkmonitor.js +17 -18
  53. package/es5/insights/networkmonitor.js.map +1 -1
  54. package/es5/insights/resourcemonitor.js +15 -17
  55. package/es5/insights/resourcemonitor.js.map +1 -1
  56. package/es5/insights/statsmonitor.js +100 -172
  57. package/es5/insights/statsmonitor.js.map +1 -1
  58. package/es5/insights/telemetry.js +40 -47
  59. package/es5/insights/telemetry.js.map +1 -1
  60. package/es5/localparticipant.js +122 -148
  61. package/es5/localparticipant.js.map +1 -1
  62. package/es5/media/track/audiotrack.js +11 -28
  63. package/es5/media/track/audiotrack.js.map +1 -1
  64. package/es5/media/track/capturevideoframes.js +21 -37
  65. package/es5/media/track/capturevideoframes.js.map +1 -1
  66. package/es5/media/track/es5/localaudiotrack.js +3 -3
  67. package/es5/media/track/es5/localaudiotrack.js.map +1 -1
  68. package/es5/media/track/es5/localdatatrack.js +3 -3
  69. package/es5/media/track/es5/localdatatrack.js.map +1 -1
  70. package/es5/media/track/es5/localvideotrack.js +3 -3
  71. package/es5/media/track/es5/localvideotrack.js.map +1 -1
  72. package/es5/media/track/index.js +17 -36
  73. package/es5/media/track/index.js.map +1 -1
  74. package/es5/media/track/localaudiotrack.js +80 -105
  75. package/es5/media/track/localaudiotrack.js.map +1 -1
  76. package/es5/media/track/localaudiotrackpublication.js +8 -25
  77. package/es5/media/track/localaudiotrackpublication.js.map +1 -1
  78. package/es5/media/track/localdatatrack.js +11 -30
  79. package/es5/media/track/localdatatrack.js.map +1 -1
  80. package/es5/media/track/localdatatrackpublication.js +8 -25
  81. package/es5/media/track/localdatatrackpublication.js.map +1 -1
  82. package/es5/media/track/localmediatrack.js +104 -129
  83. package/es5/media/track/localmediatrack.js.map +1 -1
  84. package/es5/media/track/localtrackpublication.js +24 -82
  85. package/es5/media/track/localtrackpublication.js.map +1 -1
  86. package/es5/media/track/localvideotrack.js +87 -112
  87. package/es5/media/track/localvideotrack.js.map +1 -1
  88. package/es5/media/track/localvideotrackpublication.js +8 -25
  89. package/es5/media/track/localvideotrackpublication.js.map +1 -1
  90. package/es5/media/track/mediatrack.js +71 -95
  91. package/es5/media/track/mediatrack.js.map +1 -1
  92. package/es5/media/track/noisecancellationimpl.js +63 -129
  93. package/es5/media/track/noisecancellationimpl.js.map +1 -1
  94. package/es5/media/track/receiver.js +5 -22
  95. package/es5/media/track/receiver.js.map +1 -1
  96. package/es5/media/track/remoteaudiotrack.js +16 -33
  97. package/es5/media/track/remoteaudiotrack.js.map +1 -1
  98. package/es5/media/track/remoteaudiotrackpublication.js +8 -25
  99. package/es5/media/track/remoteaudiotrackpublication.js.map +1 -1
  100. package/es5/media/track/remotedatatrack.js +18 -61
  101. package/es5/media/track/remotedatatrack.js.map +1 -1
  102. package/es5/media/track/remotedatatrackpublication.js +8 -25
  103. package/es5/media/track/remotedatatrackpublication.js.map +1 -1
  104. package/es5/media/track/remotemediatrack.js +36 -80
  105. package/es5/media/track/remotemediatrack.js.map +1 -1
  106. package/es5/media/track/remotetrackpublication.js +30 -48
  107. package/es5/media/track/remotetrackpublication.js.map +1 -1
  108. package/es5/media/track/remotevideotrack.js +94 -133
  109. package/es5/media/track/remotevideotrack.js.map +1 -1
  110. package/es5/media/track/remotevideotrackpublication.js +8 -25
  111. package/es5/media/track/remotevideotrackpublication.js.map +1 -1
  112. package/es5/media/track/sender.js +46 -83
  113. package/es5/media/track/sender.js.map +1 -1
  114. package/es5/media/track/trackpublication.js +17 -35
  115. package/es5/media/track/trackpublication.js.map +1 -1
  116. package/es5/media/track/transceiver.js +12 -30
  117. package/es5/media/track/transceiver.js.map +1 -1
  118. package/es5/media/track/videoprocessoreventobserver.js +47 -65
  119. package/es5/media/track/videoprocessoreventobserver.js.map +1 -1
  120. package/es5/media/track/videotrack.js +103 -124
  121. package/es5/media/track/videotrack.js.map +1 -1
  122. package/es5/networkqualityconfiguration.js +12 -48
  123. package/es5/networkqualityconfiguration.js.map +1 -1
  124. package/es5/noisecancellationadapter.js +72 -120
  125. package/es5/noisecancellationadapter.js.map +1 -1
  126. package/es5/participant.js +126 -179
  127. package/es5/participant.js.map +1 -1
  128. package/es5/preflight/getCombinedConnectionStats.js +44 -95
  129. package/es5/preflight/getCombinedConnectionStats.js.map +1 -1
  130. package/es5/preflight/getturncredentials.js +13 -13
  131. package/es5/preflight/getturncredentials.js.map +1 -1
  132. package/es5/preflight/makestat.js +4 -29
  133. package/es5/preflight/makestat.js.map +1 -1
  134. package/es5/preflight/mos.js +5 -5
  135. package/es5/preflight/mos.js.map +1 -1
  136. package/es5/preflight/preflighttest.js +240 -381
  137. package/es5/preflight/preflighttest.js.map +1 -1
  138. package/es5/preflight/syntheticaudio.js +8 -8
  139. package/es5/preflight/syntheticaudio.js.map +1 -1
  140. package/es5/preflight/syntheticvideo.js +13 -14
  141. package/es5/preflight/syntheticvideo.js.map +1 -1
  142. package/es5/preflight/timer.js +9 -10
  143. package/es5/preflight/timer.js.map +1 -1
  144. package/es5/queueingeventemitter.js +16 -60
  145. package/es5/queueingeventemitter.js.map +1 -1
  146. package/es5/remoteparticipant.js +33 -76
  147. package/es5/remoteparticipant.js.map +1 -1
  148. package/es5/room.js +89 -169
  149. package/es5/room.js.map +1 -1
  150. package/es5/signaling/index.js +36 -55
  151. package/es5/signaling/index.js.map +1 -1
  152. package/es5/signaling/localparticipant.js +18 -37
  153. package/es5/signaling/localparticipant.js.map +1 -1
  154. package/es5/signaling/localtrackpublication.js +28 -51
  155. package/es5/signaling/localtrackpublication.js.map +1 -1
  156. package/es5/signaling/participant.js +37 -63
  157. package/es5/signaling/participant.js.map +1 -1
  158. package/es5/signaling/recording.js +11 -29
  159. package/es5/signaling/recording.js.map +1 -1
  160. package/es5/signaling/remoteparticipant.js +6 -24
  161. package/es5/signaling/remoteparticipant.js.map +1 -1
  162. package/es5/signaling/remotetrackpublication.js +27 -53
  163. package/es5/signaling/remotetrackpublication.js.map +1 -1
  164. package/es5/signaling/room.js +40 -59
  165. package/es5/signaling/room.js.map +1 -1
  166. package/es5/signaling/track.js +52 -90
  167. package/es5/signaling/track.js.map +1 -1
  168. package/es5/signaling/v2/cancelableroomsignalingpromise.js +46 -46
  169. package/es5/signaling/v2/cancelableroomsignalingpromise.js.map +1 -1
  170. package/es5/signaling/v2/dominantspeakersignaling.js +18 -40
  171. package/es5/signaling/v2/dominantspeakersignaling.js.map +1 -1
  172. package/es5/signaling/v2/icebox.js +12 -13
  173. package/es5/signaling/v2/icebox.js.map +1 -1
  174. package/es5/signaling/v2/iceconnectionmonitor.js +28 -32
  175. package/es5/signaling/v2/iceconnectionmonitor.js.map +1 -1
  176. package/es5/signaling/v2/index.js +12 -31
  177. package/es5/signaling/v2/index.js.map +1 -1
  178. package/es5/signaling/v2/localparticipant.js +65 -85
  179. package/es5/signaling/v2/localparticipant.js.map +1 -1
  180. package/es5/signaling/v2/localtrackpublication.js +21 -39
  181. package/es5/signaling/v2/localtrackpublication.js.map +1 -1
  182. package/es5/signaling/v2/mediasignaling.js +25 -48
  183. package/es5/signaling/v2/mediasignaling.js.map +1 -1
  184. package/es5/signaling/v2/networkqualitymonitor.js +50 -97
  185. package/es5/signaling/v2/networkqualitymonitor.js.map +1 -1
  186. package/es5/signaling/v2/networkqualitysignaling.js +56 -88
  187. package/es5/signaling/v2/networkqualitysignaling.js.map +1 -1
  188. package/es5/signaling/v2/peerconnection.js +523 -648
  189. package/es5/signaling/v2/peerconnection.js.map +1 -1
  190. package/es5/signaling/v2/peerconnectionmanager.js +111 -167
  191. package/es5/signaling/v2/peerconnectionmanager.js.map +1 -1
  192. package/es5/signaling/v2/publisherhintsignaling.js +22 -42
  193. package/es5/signaling/v2/publisherhintsignaling.js.map +1 -1
  194. package/es5/signaling/v2/recording.js +8 -26
  195. package/es5/signaling/v2/recording.js.map +1 -1
  196. package/es5/signaling/v2/remoteparticipant.js +25 -43
  197. package/es5/signaling/v2/remoteparticipant.js.map +1 -1
  198. package/es5/signaling/v2/remotetrackpublication.js +7 -24
  199. package/es5/signaling/v2/remotetrackpublication.js.map +1 -1
  200. package/es5/signaling/v2/renderhintssignaling.js +40 -61
  201. package/es5/signaling/v2/renderhintssignaling.js.map +1 -1
  202. package/es5/signaling/v2/room.js +216 -280
  203. package/es5/signaling/v2/room.js.map +1 -1
  204. package/es5/signaling/v2/trackprioritysignaling.js +11 -29
  205. package/es5/signaling/v2/trackprioritysignaling.js.map +1 -1
  206. package/es5/signaling/v2/trackswitchoffsignaling.js +10 -28
  207. package/es5/signaling/v2/trackswitchoffsignaling.js.map +1 -1
  208. package/es5/signaling/v2/transcriptionsignaling.js +8 -26
  209. package/es5/signaling/v2/transcriptionsignaling.js.map +1 -1
  210. package/es5/signaling/v2/twilioconnectiontransport.js +62 -82
  211. package/es5/signaling/v2/twilioconnectiontransport.js.map +1 -1
  212. package/es5/statemachine.js +75 -121
  213. package/es5/statemachine.js.map +1 -1
  214. package/es5/stats/average.js +2 -2
  215. package/es5/stats/average.js.map +1 -1
  216. package/es5/stats/icereport.js +11 -12
  217. package/es5/stats/icereport.js.map +1 -1
  218. package/es5/stats/icereportfactory.js +8 -9
  219. package/es5/stats/icereportfactory.js.map +1 -1
  220. package/es5/stats/localaudiotrackstats.js +6 -24
  221. package/es5/stats/localaudiotrackstats.js.map +1 -1
  222. package/es5/stats/localtrackstats.js +6 -24
  223. package/es5/stats/localtrackstats.js.map +1 -1
  224. package/es5/stats/localvideotrackstats.js +9 -27
  225. package/es5/stats/localvideotrackstats.js.map +1 -1
  226. package/es5/stats/networkqualityaudiostats.js +5 -22
  227. package/es5/stats/networkqualityaudiostats.js.map +1 -1
  228. package/es5/stats/networkqualitybandwidthstats.js +3 -5
  229. package/es5/stats/networkqualitybandwidthstats.js.map +1 -1
  230. package/es5/stats/networkqualityfractionloststats.js +3 -5
  231. package/es5/stats/networkqualityfractionloststats.js.map +1 -1
  232. package/es5/stats/networkqualitylatencystats.js +3 -5
  233. package/es5/stats/networkqualitylatencystats.js.map +1 -1
  234. package/es5/stats/networkqualitymediastats.js +5 -7
  235. package/es5/stats/networkqualitymediastats.js.map +1 -1
  236. package/es5/stats/networkqualityrecvstats.js +5 -22
  237. package/es5/stats/networkqualityrecvstats.js.map +1 -1
  238. package/es5/stats/networkqualitysendorrecvstats.js +6 -8
  239. package/es5/stats/networkqualitysendorrecvstats.js.map +1 -1
  240. package/es5/stats/networkqualitysendstats.js +5 -22
  241. package/es5/stats/networkqualitysendstats.js.map +1 -1
  242. package/es5/stats/networkqualitystats.js +5 -7
  243. package/es5/stats/networkqualitystats.js.map +1 -1
  244. package/es5/stats/networkqualityvideostats.js +5 -22
  245. package/es5/stats/networkqualityvideostats.js.map +1 -1
  246. package/es5/stats/peerconnectionreport.js +13 -14
  247. package/es5/stats/peerconnectionreport.js.map +1 -1
  248. package/es5/stats/peerconnectionreportfactory.js +89 -185
  249. package/es5/stats/peerconnectionreportfactory.js.map +1 -1
  250. package/es5/stats/receiverreport.js +28 -46
  251. package/es5/stats/receiverreport.js.map +1 -1
  252. package/es5/stats/receiverreportfactory.js +11 -29
  253. package/es5/stats/receiverreportfactory.js.map +1 -1
  254. package/es5/stats/remoteaudiotrackstats.js +6 -24
  255. package/es5/stats/remoteaudiotrackstats.js.map +1 -1
  256. package/es5/stats/remotetrackstats.js +6 -24
  257. package/es5/stats/remotetrackstats.js.map +1 -1
  258. package/es5/stats/remotevideotrackstats.js +7 -25
  259. package/es5/stats/remotevideotrackstats.js.map +1 -1
  260. package/es5/stats/senderorreceiverreport.js +3 -4
  261. package/es5/stats/senderorreceiverreport.js.map +1 -1
  262. package/es5/stats/senderorreceiverreportfactory.js +3 -4
  263. package/es5/stats/senderorreceiverreportfactory.js.map +1 -1
  264. package/es5/stats/senderreport.js +20 -38
  265. package/es5/stats/senderreport.js.map +1 -1
  266. package/es5/stats/senderreportfactory.js +11 -29
  267. package/es5/stats/senderreportfactory.js.map +1 -1
  268. package/es5/stats/statsreport.js +11 -12
  269. package/es5/stats/statsreport.js.map +1 -1
  270. package/es5/stats/sum.js +1 -1
  271. package/es5/stats/sum.js.map +1 -1
  272. package/es5/stats/trackstats.js +3 -4
  273. package/es5/stats/trackstats.js.map +1 -1
  274. package/es5/transceiver.js +8 -26
  275. package/es5/transceiver.js.map +1 -1
  276. package/es5/twilioconnection.js +166 -223
  277. package/es5/twilioconnection.js.map +1 -1
  278. package/es5/util/asyncvar.js +12 -14
  279. package/es5/util/asyncvar.js.map +1 -1
  280. package/es5/util/backoff.js +14 -16
  281. package/es5/util/backoff.js.map +1 -1
  282. package/es5/util/browserdetection.js +19 -35
  283. package/es5/util/browserdetection.js.map +1 -1
  284. package/es5/util/cancelablepromise.js +30 -57
  285. package/es5/util/cancelablepromise.js.map +1 -1
  286. package/es5/util/constants.js +13 -13
  287. package/es5/util/constants.js.map +1 -1
  288. package/es5/util/detectsilentaudio.js +10 -10
  289. package/es5/util/detectsilentaudio.js.map +1 -1
  290. package/es5/util/detectsilentvideo.js +12 -12
  291. package/es5/util/detectsilentvideo.js.map +1 -1
  292. package/es5/util/documentvisibilitymonitor.js +34 -41
  293. package/es5/util/documentvisibilitymonitor.js.map +1 -1
  294. package/es5/util/dynamicimport.js +4 -4
  295. package/es5/util/dynamicimport.js.map +1 -1
  296. package/es5/util/eventobserver.js +19 -39
  297. package/es5/util/eventobserver.js.map +1 -1
  298. package/es5/util/filter.js +11 -12
  299. package/es5/util/filter.js.map +1 -1
  300. package/es5/util/index.js +96 -165
  301. package/es5/util/index.js.map +1 -1
  302. package/es5/util/insightspublisher/index.js +48 -78
  303. package/es5/util/insightspublisher/index.js.map +1 -1
  304. package/es5/util/insightspublisher/null.js +9 -10
  305. package/es5/util/insightspublisher/null.js.map +1 -1
  306. package/es5/util/localmediarestartdeferreds.js +10 -11
  307. package/es5/util/localmediarestartdeferreds.js.map +1 -1
  308. package/es5/util/log.js +44 -70
  309. package/es5/util/log.js.map +1 -1
  310. package/es5/util/movingaveragedelta.js +12 -13
  311. package/es5/util/movingaveragedelta.js.map +1 -1
  312. package/es5/util/networkmonitor.js +26 -30
  313. package/es5/util/networkmonitor.js.map +1 -1
  314. package/es5/util/nullobserver.js +22 -48
  315. package/es5/util/nullobserver.js.map +1 -1
  316. package/es5/util/sdp/index.js +109 -134
  317. package/es5/util/sdp/index.js.map +1 -1
  318. package/es5/util/sdp/issue8329.js +56 -57
  319. package/es5/util/sdp/issue8329.js.map +1 -1
  320. package/es5/util/sdp/simulcast.js +55 -73
  321. package/es5/util/sdp/simulcast.js.map +1 -1
  322. package/es5/util/sdp/trackmatcher.js +14 -15
  323. package/es5/util/sdp/trackmatcher.js.map +1 -1
  324. package/es5/util/sid.js +5 -5
  325. package/es5/util/sid.js.map +1 -1
  326. package/es5/util/support.js +13 -16
  327. package/es5/util/support.js.map +1 -1
  328. package/es5/util/timeout.js +28 -39
  329. package/es5/util/timeout.js.map +1 -1
  330. package/es5/util/timeoutpromise.js +38 -84
  331. package/es5/util/timeoutpromise.js.map +1 -1
  332. package/es5/util/twilio-video-errors.js +277 -457
  333. package/es5/util/twilio-video-errors.js.map +1 -1
  334. package/es5/util/twilioerror.js +13 -57
  335. package/es5/util/twilioerror.js.map +1 -1
  336. package/es5/util/twiliowarning.js +1 -1
  337. package/es5/util/twiliowarning.js.map +1 -1
  338. package/es5/util/validate.js +13 -15
  339. package/es5/util/validate.js.map +1 -1
  340. package/es5/vendor/inherits.js +3 -5
  341. package/es5/vendor/inherits.js.map +1 -1
  342. package/es5/webaudio/audiocontext.js +8 -9
  343. package/es5/webaudio/audiocontext.js.map +1 -1
  344. package/es5/webaudio/detectsilence.js +9 -9
  345. package/es5/webaudio/detectsilence.js.map +1 -1
  346. package/es5/webaudio/workaround180748.js +15 -13
  347. package/es5/webaudio/workaround180748.js.map +1 -1
  348. package/es5/webrtc/getstats.js +242 -448
  349. package/es5/webrtc/getstats.js.map +1 -1
  350. package/es5/webrtc/getusermedia.js +1 -2
  351. package/es5/webrtc/getusermedia.js.map +1 -1
  352. package/es5/webrtc/index.js +1 -17
  353. package/es5/webrtc/index.js.map +1 -1
  354. package/es5/webrtc/rtcpeerconnection/chrome.js +102 -295
  355. package/es5/webrtc/rtcpeerconnection/chrome.js.map +1 -1
  356. package/es5/webrtc/rtcpeerconnection/firefox.js +69 -146
  357. package/es5/webrtc/rtcpeerconnection/firefox.js.map +1 -1
  358. package/es5/webrtc/rtcpeerconnection/index.js +1 -1
  359. package/es5/webrtc/rtcpeerconnection/index.js.map +1 -1
  360. package/es5/webrtc/rtcpeerconnection/safari.js +110 -192
  361. package/es5/webrtc/rtcpeerconnection/safari.js.map +1 -1
  362. package/es5/webrtc/rtcrtpsender.js +3 -4
  363. package/es5/webrtc/rtcrtpsender.js.map +1 -1
  364. package/es5/webrtc/util/index.js +28 -63
  365. package/es5/webrtc/util/index.js.map +1 -1
  366. package/es5/webrtc/util/latch.js +21 -28
  367. package/es5/webrtc/util/latch.js.map +1 -1
  368. package/es5/webrtc/util/sdp.js +41 -211
  369. package/es5/webrtc/util/sdp.js.map +1 -1
  370. package/lib/connect.js +0 -1
  371. package/lib/createlocaltracks.ts +2 -2
  372. package/lib/localparticipant.js +0 -1
  373. package/lib/media/track/mediatrack.js +0 -2
  374. package/lib/media/track/noisecancellationimpl.ts +2 -2
  375. package/lib/noisecancellationadapter.ts +2 -2
  376. package/lib/preflight/getCombinedConnectionStats.ts +1 -1
  377. package/lib/preflight/getturncredentials.ts +2 -2
  378. package/lib/preflight/preflighttest.ts +3 -3
  379. package/lib/signaling/v2/peerconnection.js +2 -4
  380. package/lib/util/sdp/index.js +1 -2
  381. package/lib/util/sdp/issue8329.js +0 -2
  382. package/lib/util/support.js +4 -7
  383. package/lib/webrtc/getstats.js +6 -21
  384. package/lib/webrtc/index.js +0 -16
  385. package/lib/webrtc/rtcpeerconnection/chrome.js +13 -123
  386. package/lib/webrtc/rtcpeerconnection/firefox.js +5 -6
  387. package/lib/webrtc/rtcpeerconnection/safari.js +9 -19
  388. package/lib/webrtc/util/sdp.js +13 -194
  389. package/package.json +16 -11
  390. package/rollup.config.mjs +85 -0
  391. package/tsconfig.json +5 -5
  392. package/es5/webrtc/mediastream.js +0 -11
  393. package/es5/webrtc/mediastream.js.map +0 -1
  394. package/es5/webrtc/mediastreamtrack.js +0 -11
  395. package/es5/webrtc/mediastreamtrack.js.map +0 -1
  396. package/es5/webrtc/rtcicecandidate.js +0 -11
  397. package/es5/webrtc/rtcicecandidate.js.map +0 -1
  398. package/es5/webrtc/rtcsessiondescription/chrome.js +0 -43
  399. package/es5/webrtc/rtcsessiondescription/chrome.js.map +0 -1
  400. package/es5/webrtc/rtcsessiondescription/firefox.js +0 -4
  401. package/es5/webrtc/rtcsessiondescription/firefox.js.map +0 -1
  402. package/es5/webrtc/rtcsessiondescription/index.js +0 -22
  403. package/es5/webrtc/rtcsessiondescription/index.js.map +0 -1
  404. package/lib/webrtc/mediastream.js +0 -10
  405. package/lib/webrtc/mediastreamtrack.js +0 -10
  406. package/lib/webrtc/rtcicecandidate.js +0 -10
  407. package/lib/webrtc/rtcsessiondescription/chrome.js +0 -39
  408. package/lib/webrtc/rtcsessiondescription/firefox.js +0 -4
  409. package/lib/webrtc/rtcsessiondescription/index.js +0 -21
  410. package/src/twilio-video.js +0 -16
@@ -1,50 +1,10 @@
1
1
  'use strict';
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
19
- if (!m) return o;
20
- var i = m.call(o), r, ar = [], e;
21
- try {
22
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
- }
24
- catch (error) { e = { error: error }; }
25
- finally {
26
- try {
27
- if (r && !r.done && (m = i["return"])) m.call(i);
28
- }
29
- finally { if (e) throw e.error; }
30
- }
31
- return ar;
32
- };
33
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
35
- if (ar || !(i in from)) {
36
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
37
- ar[i] = from[i];
38
- }
39
- }
40
- return to.concat(ar || Array.prototype.slice.call(from));
41
- };
42
- var StateMachine = require('./statemachine');
43
- var _a = require('./util'), buildLogLevels = _a.buildLogLevels, makeUUID = _a.makeUUID;
44
- var Log = require('./util/log');
45
- var NetworkMonitor = require('./util/networkmonitor');
46
- var Timeout = require('./util/timeout');
47
- var nInstances = 0;
2
+ const StateMachine = require('./statemachine');
3
+ const { buildLogLevels, makeUUID } = require('./util');
4
+ const Log = require('./util/log');
5
+ const NetworkMonitor = require('./util/networkmonitor');
6
+ const Timeout = require('./util/timeout');
7
+ let nInstances = 0;
48
8
  /*
49
9
  TwilioConnection states
50
10
  -----------------------
@@ -64,47 +24,47 @@ var nInstances = 0;
64
24
  | waiting | --------> | open | ---------------
65
25
  +----------+ +--------+
66
26
  */
67
- var states = {
27
+ const states = {
68
28
  closed: [],
69
29
  connecting: ['closed', 'open', 'waiting'],
70
30
  early: ['closed', 'connecting'],
71
31
  open: ['closed'],
72
32
  waiting: ['closed', 'connecting', 'early', 'open']
73
33
  };
74
- var events = {
34
+ const events = {
75
35
  closed: 'close',
76
36
  open: 'open',
77
37
  waiting: 'waiting'
78
38
  };
79
- var TCMP_VERSION = 2;
80
- var DEFAULT_MAX_CONSECUTIVE_MISSED_HEARTBEATS = 3;
81
- var DEFAULT_MAX_CONSECUTIVE_FAILED_HELLOS = 3;
82
- var DEFAULT_MAX_REQUESTED_HEARTBEAT_TIMEOUT = 5000;
83
- var DEFAULT_OPEN_TIMEOUT = 15000;
84
- var DEFAULT_WELCOME_TIMEOUT = 5000;
85
- var OUTGOING_HEARTBEAT_OFFSET = 200;
86
- var WS_CLOSE_NORMAL = 1000;
87
- var WS_CLOSE_WELCOME_TIMEOUT = 3000;
88
- var WS_CLOSE_HEARTBEATS_MISSED = 3001;
89
- var WS_CLOSE_HELLO_FAILED = 3002;
90
- var WS_CLOSE_SEND_FAILED = 3003;
91
- var WS_CLOSE_NETWORK_CHANGED = 3004;
92
- var WS_CLOSE_BUSY_WAIT = 3005;
93
- var WS_CLOSE_SERVER_BUSY = 3006;
94
- var WS_CLOSE_OPEN_TIMEOUT = 3007;
39
+ const TCMP_VERSION = 2;
40
+ const DEFAULT_MAX_CONSECUTIVE_MISSED_HEARTBEATS = 3;
41
+ const DEFAULT_MAX_CONSECUTIVE_FAILED_HELLOS = 3;
42
+ const DEFAULT_MAX_REQUESTED_HEARTBEAT_TIMEOUT = 5000;
43
+ const DEFAULT_OPEN_TIMEOUT = 15000;
44
+ const DEFAULT_WELCOME_TIMEOUT = 5000;
45
+ const OUTGOING_HEARTBEAT_OFFSET = 200;
46
+ const WS_CLOSE_NORMAL = 1000;
47
+ const WS_CLOSE_WELCOME_TIMEOUT = 3000;
48
+ const WS_CLOSE_HEARTBEATS_MISSED = 3001;
49
+ const WS_CLOSE_HELLO_FAILED = 3002;
50
+ const WS_CLOSE_SEND_FAILED = 3003;
51
+ const WS_CLOSE_NETWORK_CHANGED = 3004;
52
+ const WS_CLOSE_BUSY_WAIT = 3005;
53
+ const WS_CLOSE_SERVER_BUSY = 3006;
54
+ const WS_CLOSE_OPEN_TIMEOUT = 3007;
95
55
  // NOTE(joma): If you want to use close code 3008, please increment
96
56
  // the close code in test/integration/spec/docker/reconnection.js
97
57
  // line number 492.
98
- var toplevel = globalThis;
99
- var WebSocket = toplevel.WebSocket ? toplevel.WebSocket : require('ws');
100
- var CloseReason = {
58
+ const toplevel = globalThis;
59
+ const WebSocket = toplevel.WebSocket ? toplevel.WebSocket : require('ws');
60
+ const CloseReason = {
101
61
  BUSY: 'busy',
102
62
  FAILED: 'failed',
103
63
  LOCAL: 'local',
104
64
  REMOTE: 'remote',
105
65
  TIMEOUT: 'timeout'
106
66
  };
107
- var wsCloseCodesToCloseReasons = new Map([
67
+ const wsCloseCodesToCloseReasons = new Map([
108
68
  [WS_CLOSE_WELCOME_TIMEOUT, CloseReason.TIMEOUT],
109
69
  [WS_CLOSE_HEARTBEATS_MISSED, CloseReason.TIMEOUT],
110
70
  [WS_CLOSE_HELLO_FAILED, CloseReason.FAILED],
@@ -122,15 +82,14 @@ var wsCloseCodesToCloseReasons = new Map([
122
82
  * @fires TwilioConnection#open
123
83
  * @fires TwilioConnection#waiting
124
84
  */
125
- var TwilioConnection = /** @class */ (function (_super) {
126
- __extends(TwilioConnection, _super);
85
+ class TwilioConnection extends StateMachine {
127
86
  /**
128
87
  * Construct a {@link TwilioConnection}.
129
88
  * @param {string} serverUrl - TCMP server url
130
89
  * @param {TwilioConnectionOptions} options - {@link TwilioConnection} options
131
90
  */
132
- function TwilioConnection(serverUrl, options) {
133
- var _this = _super.call(this, 'early', states) || this;
91
+ constructor(serverUrl, options) {
92
+ super('early', states);
134
93
  options = Object.assign({
135
94
  helloBody: null,
136
95
  maxConsecutiveFailedHellos: DEFAULT_MAX_CONSECUTIVE_FAILED_HELLOS,
@@ -138,18 +97,18 @@ var TwilioConnection = /** @class */ (function (_super) {
138
97
  requestedHeartbeatTimeout: DEFAULT_MAX_REQUESTED_HEARTBEAT_TIMEOUT,
139
98
  openTimeout: DEFAULT_OPEN_TIMEOUT,
140
99
  welcomeTimeout: DEFAULT_WELCOME_TIMEOUT,
141
- Log: Log,
142
- WebSocket: WebSocket
100
+ Log,
101
+ WebSocket
143
102
  }, options);
144
- var logLevels = buildLogLevels(options.logLevel);
145
- var log = new options.Log('default', _this, logLevels, options.loggerName);
146
- var networkMonitor = options.networkMonitor ? new NetworkMonitor(function () {
147
- var type = networkMonitor.type;
148
- var reason = "Network changed".concat(type ? " to ".concat(type) : '');
103
+ const logLevels = buildLogLevels(options.logLevel);
104
+ const log = new options.Log('default', this, logLevels, options.loggerName);
105
+ const networkMonitor = options.networkMonitor ? new NetworkMonitor(() => {
106
+ const { type } = networkMonitor;
107
+ const reason = `Network changed${type ? ` to ${type}` : ''}`;
149
108
  log.debug(reason);
150
- _this._close({ code: WS_CLOSE_NETWORK_CHANGED, reason: reason });
109
+ this._close({ code: WS_CLOSE_NETWORK_CHANGED, reason });
151
110
  }) : null;
152
- Object.defineProperties(_this, {
111
+ Object.defineProperties(this, {
153
112
  _busyWaitTimeout: {
154
113
  value: null,
155
114
  writable: true
@@ -208,43 +167,37 @@ var TwilioConnection = /** @class */ (function (_super) {
208
167
  writable: true
209
168
  }
210
169
  });
211
- var eventsToLevels = {
170
+ const eventsToLevels = {
212
171
  connecting: 'info',
213
172
  early: 'info',
214
173
  open: 'info',
215
174
  waiting: 'warning',
216
175
  closed: 'info'
217
176
  };
218
- _this.on('stateChanged', function (state) {
219
- var args = [];
220
- for (var _i = 1; _i < arguments.length; _i++) {
221
- args[_i - 1] = arguments[_i];
222
- }
177
+ this.on('stateChanged', (state, ...args) => {
223
178
  if (state in events) {
224
- _this.emit.apply(_this, __spreadArray([events[state]], __read(args), false));
179
+ this.emit(events[state], ...args);
225
180
  }
226
- var event = { name: state, group: 'signaling', level: eventsToLevels[_this.state] };
181
+ const event = { name: state, group: 'signaling', level: eventsToLevels[this.state] };
227
182
  if (state === 'closed') {
228
- var _a = __read(args, 1), reason = _a[0];
229
- event.payload = { reason: reason };
183
+ const [reason] = args;
184
+ event.payload = { reason };
230
185
  event.level = reason === CloseReason.LOCAL ? 'info' : 'error';
231
186
  }
232
- _this._eventObserver.emit('event', event);
187
+ this._eventObserver.emit('event', event);
233
188
  });
234
- _this._eventObserver.emit('event', { name: _this.state, group: 'signaling', level: eventsToLevels[_this.state] });
235
- _this._connect();
236
- return _this;
189
+ this._eventObserver.emit('event', { name: this.state, group: 'signaling', level: eventsToLevels[this.state] });
190
+ this._connect();
191
+ }
192
+ toString() {
193
+ return `[TwilioConnection #${this._instanceId}: ${this._ws.url}]`;
237
194
  }
238
- TwilioConnection.prototype.toString = function () {
239
- return "[TwilioConnection #".concat(this._instanceId, ": ").concat(this._ws.url, "]");
240
- };
241
195
  /**
242
196
  * Close the {@link TwilioConnection}.
243
197
  * @param {{code: number, reason: string}} event
244
198
  * @private
245
199
  */
246
- TwilioConnection.prototype._close = function (_a) {
247
- var code = _a.code, reason = _a.reason;
200
+ _close({ code, reason }) {
248
201
  if (this.state === 'closed') {
249
202
  return;
250
203
  }
@@ -267,127 +220,123 @@ var TwilioConnection = /** @class */ (function (_super) {
267
220
  this._busyWaitTimeout.clear();
268
221
  }
269
222
  this._messageQueue.splice(0);
270
- var log = this._log;
223
+ const log = this._log;
271
224
  if (code === WS_CLOSE_NORMAL) {
272
225
  log.debug('Closed');
273
226
  this.transition('closed', null, [CloseReason.LOCAL]);
274
227
  }
275
228
  else {
276
- log.warn("Closed: ".concat(code, " - ").concat(reason));
229
+ log.warn(`Closed: ${code} - ${reason}`);
277
230
  if (code !== WS_CLOSE_BUSY_WAIT) {
278
231
  this.transition('closed', null, [
279
232
  wsCloseCodesToCloseReasons.get(code) || CloseReason.REMOTE
280
233
  ]);
281
234
  }
282
235
  }
283
- var readyState = this._ws.readyState;
284
- var WebSocket = this._options.WebSocket;
236
+ const { readyState } = this._ws;
237
+ const { WebSocket } = this._options;
285
238
  if (readyState !== WebSocket.CLOSING && readyState !== WebSocket.CLOSED) {
286
239
  this._ws.close(code, reason);
287
240
  }
288
- };
241
+ }
289
242
  /**
290
243
  * Connect to the TCMP server.
291
244
  * @private
292
245
  */
293
- TwilioConnection.prototype._connect = function () {
294
- var _this = this;
295
- var log = this._log;
246
+ _connect() {
247
+ const log = this._log;
296
248
  if (this.state === 'waiting') {
297
249
  this.transition('early');
298
250
  }
299
251
  else if (this.state !== 'early') {
300
- log.warn("Unexpected state \"".concat(this.state, "\" for connecting to the")
252
+ log.warn(`Unexpected state "${this.state}" for connecting to the`
301
253
  + ' TCMP server.');
302
254
  return;
303
255
  }
304
256
  this._ws = new this._options.WebSocket(this._serverUrl);
305
- var ws = this._ws;
257
+ const ws = this._ws;
306
258
  log.debug('Created a new WebSocket:', ws);
307
- ws.addEventListener('close', function (event) { return _this._close(event); });
308
- var openTimeout = this._options.openTimeout;
259
+ ws.addEventListener('close', event => this._close(event));
260
+ const { openTimeout } = this._options;
309
261
  // Add a timeout for getting the onopen event on the WebSocket (15 sec). After that, attempt to reconnect only if this is not the first attempt.
310
- this._openTimeout = new Timeout(function () {
311
- var reason = "Failed to open in ".concat(openTimeout, " ms");
312
- _this._close({ code: WS_CLOSE_OPEN_TIMEOUT, reason: reason });
262
+ this._openTimeout = new Timeout(() => {
263
+ const reason = `Failed to open in ${openTimeout} ms`;
264
+ this._close({ code: WS_CLOSE_OPEN_TIMEOUT, reason });
313
265
  }, openTimeout);
314
- ws.addEventListener('open', function () {
266
+ ws.addEventListener('open', () => {
315
267
  log.debug('WebSocket opened:', ws);
316
- _this._openTimeout.clear();
317
- _this._startHandshake();
318
- if (_this._networkMonitor) {
319
- _this._networkMonitor.start();
268
+ this._openTimeout.clear();
269
+ this._startHandshake();
270
+ if (this._networkMonitor) {
271
+ this._networkMonitor.start();
320
272
  }
321
273
  });
322
- ws.addEventListener('message', function (message) {
323
- log.debug("Incoming: ".concat(message.data));
274
+ ws.addEventListener('message', message => {
275
+ log.debug(`Incoming: ${message.data}`);
324
276
  try {
325
277
  message = JSON.parse(message.data);
326
278
  }
327
279
  catch (error) {
328
- _this.emit('error', error);
280
+ this.emit('error', error);
329
281
  return;
330
282
  }
331
283
  switch (message.type) {
332
284
  case 'bad':
333
- _this._handleBad(message);
285
+ this._handleBad(message);
334
286
  break;
335
287
  case 'busy':
336
- _this._handleBusy(message);
288
+ this._handleBusy(message);
337
289
  break;
338
290
  case 'bye':
339
291
  // Do nothing.
340
292
  break;
341
293
  case 'msg':
342
- _this._handleMessage(message);
294
+ this._handleMessage(message);
343
295
  // NOTE(mpatwardhan): Each incoming message should be treated as an incoming
344
296
  // heartbeat intentionally falling through to 'heartbeat' case.
345
297
  // eslint-disable-next-line no-fallthrough
346
298
  case 'heartbeat':
347
- _this._handleHeartbeat();
299
+ this._handleHeartbeat();
348
300
  break;
349
301
  case 'welcome':
350
- _this._handleWelcome(message);
302
+ this._handleWelcome(message);
351
303
  break;
352
304
  default:
353
- _this._log.debug("Unknown message type: ".concat(message.type));
354
- _this.emit('error', new Error("Unknown message type: ".concat(message.type)));
305
+ this._log.debug(`Unknown message type: ${message.type}`);
306
+ this.emit('error', new Error(`Unknown message type: ${message.type}`));
355
307
  break;
356
308
  }
357
309
  });
358
- };
310
+ }
359
311
  /**
360
312
  * Handle an incoming "bad" message.
361
313
  * @param {{reason: string}} message
362
314
  * @private
363
315
  */
364
- TwilioConnection.prototype._handleBad = function (_a) {
365
- var reason = _a.reason;
366
- var log = this._log;
316
+ _handleBad({ reason }) {
317
+ const log = this._log;
367
318
  if (!['connecting', 'open'].includes(this.state)) {
368
- log.warn("Unexpected state \"".concat(this.state, "\" for handling a \"bad\" message")
319
+ log.warn(`Unexpected state "${this.state}" for handling a "bad" message`
369
320
  + ' from the TCMP server.');
370
321
  return;
371
322
  }
372
323
  if (this.state === 'connecting') {
373
- log.warn("Closing: ".concat(WS_CLOSE_HELLO_FAILED, " - ").concat(reason));
374
- this._close({ code: WS_CLOSE_HELLO_FAILED, reason: reason });
324
+ log.warn(`Closing: ${WS_CLOSE_HELLO_FAILED} - ${reason}`);
325
+ this._close({ code: WS_CLOSE_HELLO_FAILED, reason });
375
326
  return;
376
327
  }
377
- log.debug("Error: ".concat(reason));
328
+ log.debug(`Error: ${reason}`);
378
329
  this.emit('error', new Error(reason));
379
- };
330
+ }
380
331
  /**
381
332
  * Handle an incoming "busy" message.
382
333
  * @param {{cookie: ?string, keepAlive: boolean, retryAfter: number}} message
383
334
  * @private
384
335
  */
385
- TwilioConnection.prototype._handleBusy = function (_a) {
386
- var _this = this;
387
- var cookie = _a.cookie, keepAlive = _a.keepAlive, retryAfter = _a.retryAfter;
388
- var log = this._log;
336
+ _handleBusy({ cookie, keepAlive, retryAfter }) {
337
+ const log = this._log;
389
338
  if (!['connecting', 'waiting'].includes(this.state)) {
390
- log.warn("Unexpected state \"".concat(this.state, "\" for handling a \"busy\" message")
339
+ log.warn(`Unexpected state "${this.state}" for handling a "busy" message`
391
340
  + ' from the TCMP server.');
392
341
  return;
393
342
  }
@@ -397,80 +346,77 @@ var TwilioConnection = /** @class */ (function (_super) {
397
346
  if (this._welcomeTimeout) {
398
347
  this._welcomeTimeout.clear();
399
348
  }
400
- var reason = retryAfter < 0
349
+ const reason = retryAfter < 0
401
350
  ? 'Received terminal "busy" message'
402
- : "Received \"busy\" message, retrying after ".concat(retryAfter, " ms");
351
+ : `Received "busy" message, retrying after ${retryAfter} ms`;
403
352
  if (retryAfter < 0) {
404
- log.warn("Closing: ".concat(WS_CLOSE_SERVER_BUSY, " - ").concat(reason));
405
- this._close({ code: WS_CLOSE_SERVER_BUSY, reason: reason });
353
+ log.warn(`Closing: ${WS_CLOSE_SERVER_BUSY} - ${reason}`);
354
+ this._close({ code: WS_CLOSE_SERVER_BUSY, reason });
406
355
  return;
407
356
  }
408
- var maxConsecutiveFailedHellos = this._options.maxConsecutiveFailedHellos;
357
+ const { maxConsecutiveFailedHellos } = this._options;
409
358
  this._hellosLeft = maxConsecutiveFailedHellos;
410
359
  this._cookie = cookie || null;
411
360
  if (keepAlive) {
412
361
  log.warn(reason);
413
- this._busyWaitTimeout = new Timeout(function () { return _this._startHandshake(); }, retryAfter);
362
+ this._busyWaitTimeout = new Timeout(() => this._startHandshake(), retryAfter);
414
363
  }
415
364
  else {
416
- log.warn("Closing: ".concat(WS_CLOSE_BUSY_WAIT, " - ").concat(reason));
417
- this._close({ code: WS_CLOSE_BUSY_WAIT, reason: reason });
418
- this._busyWaitTimeout = new Timeout(function () { return _this._connect(); }, retryAfter);
365
+ log.warn(`Closing: ${WS_CLOSE_BUSY_WAIT} - ${reason}`);
366
+ this._close({ code: WS_CLOSE_BUSY_WAIT, reason });
367
+ this._busyWaitTimeout = new Timeout(() => this._connect(), retryAfter);
419
368
  }
420
369
  this.transition('waiting', null, [keepAlive, retryAfter]);
421
- };
370
+ }
422
371
  /**
423
372
  * Handle an incoming "heartbeat" message.
424
373
  * @private
425
374
  */
426
- TwilioConnection.prototype._handleHeartbeat = function () {
375
+ _handleHeartbeat() {
427
376
  if (this.state !== 'open') {
428
- this._log.warn("Unexpected state \"".concat(this.state, "\" for handling a \"heartbeat\"")
377
+ this._log.warn(`Unexpected state "${this.state}" for handling a "heartbeat"`
429
378
  + ' message from the TCMP server.');
430
379
  return;
431
380
  }
432
381
  this._heartbeatTimeout.reset();
433
- };
382
+ }
434
383
  /**
435
384
  * Handle a missed "heartbeat" message.
436
385
  * @private
437
386
  */
438
- TwilioConnection.prototype._handleHeartbeatTimeout = function () {
387
+ _handleHeartbeatTimeout() {
439
388
  if (this.state !== 'open') {
440
389
  return;
441
390
  }
442
- var log = this._log;
443
- var maxConsecutiveMissedHeartbeats = this._options.maxConsecutiveMissedHeartbeats;
444
- log.debug("Consecutive heartbeats missed: ".concat(maxConsecutiveMissedHeartbeats));
445
- var reason = "Missed ".concat(maxConsecutiveMissedHeartbeats, " \"heartbeat\" messages");
446
- log.warn("Closing: ".concat(WS_CLOSE_HEARTBEATS_MISSED, " - ").concat(reason));
447
- this._close({ code: WS_CLOSE_HEARTBEATS_MISSED, reason: reason });
448
- };
391
+ const log = this._log;
392
+ const { maxConsecutiveMissedHeartbeats } = this._options;
393
+ log.debug(`Consecutive heartbeats missed: ${maxConsecutiveMissedHeartbeats}`);
394
+ const reason = `Missed ${maxConsecutiveMissedHeartbeats} "heartbeat" messages`;
395
+ log.warn(`Closing: ${WS_CLOSE_HEARTBEATS_MISSED} - ${reason}`);
396
+ this._close({ code: WS_CLOSE_HEARTBEATS_MISSED, reason });
397
+ }
449
398
  /**
450
399
  * Handle an incoming "msg" message.
451
400
  * @param {{body: object}} message
452
401
  * @private
453
402
  */
454
- TwilioConnection.prototype._handleMessage = function (_a) {
455
- var body = _a.body;
403
+ _handleMessage({ body }) {
456
404
  if (this.state !== 'open') {
457
- this._log.warn("Unexpected state \"".concat(this.state, "\" for handling a \"msg\" message")
405
+ this._log.warn(`Unexpected state "${this.state}" for handling a "msg" message`
458
406
  + ' from the TCMP server.');
459
407
  return;
460
408
  }
461
409
  this.emit('message', body);
462
- };
410
+ }
463
411
  /**
464
412
  * Handle an incoming "welcome" message.
465
413
  * @param {{ negotiatedTimeout: number }} message
466
414
  * @private
467
415
  */
468
- TwilioConnection.prototype._handleWelcome = function (_a) {
469
- var _this = this;
470
- var negotiatedTimeout = _a.negotiatedTimeout;
471
- var log = this._log;
416
+ _handleWelcome({ negotiatedTimeout }) {
417
+ const log = this._log;
472
418
  if (!['connecting', 'waiting'].includes(this.state)) {
473
- log.warn("Unexpected state \"".concat(this.state, "\" for handling a \"welcome\"")
419
+ log.warn(`Unexpected state "${this.state}" for handling a "welcome"`
474
420
  + ' message from the TCMP server.');
475
421
  return;
476
422
  }
@@ -478,45 +424,45 @@ var TwilioConnection = /** @class */ (function (_super) {
478
424
  log.debug('Received "welcome" message, no need to retry connection.');
479
425
  this._busyWaitTimeout.clear();
480
426
  }
481
- var maxConsecutiveMissedHeartbeats = this._options.maxConsecutiveMissedHeartbeats;
482
- var heartbeatTimeout = negotiatedTimeout * maxConsecutiveMissedHeartbeats;
483
- var outgoingHeartbeatTimeout = negotiatedTimeout - OUTGOING_HEARTBEAT_OFFSET;
427
+ const { maxConsecutiveMissedHeartbeats } = this._options;
428
+ const heartbeatTimeout = negotiatedTimeout * maxConsecutiveMissedHeartbeats;
429
+ const outgoingHeartbeatTimeout = negotiatedTimeout - OUTGOING_HEARTBEAT_OFFSET;
484
430
  this._welcomeTimeout.clear();
485
- this._heartbeatTimeout = new Timeout(function () { return _this._handleHeartbeatTimeout(); }, heartbeatTimeout);
486
- this._messageQueue.splice(0).forEach(function (message) { return _this._send(message); });
487
- this._sendHeartbeatTimeout = new Timeout(function () { return _this._sendHeartbeat(); }, outgoingHeartbeatTimeout);
431
+ this._heartbeatTimeout = new Timeout(() => this._handleHeartbeatTimeout(), heartbeatTimeout);
432
+ this._messageQueue.splice(0).forEach(message => this._send(message));
433
+ this._sendHeartbeatTimeout = new Timeout(() => this._sendHeartbeat(), outgoingHeartbeatTimeout);
488
434
  this.transition('open');
489
- };
435
+ }
490
436
  /**
491
437
  * Handle a missed "welcome" message.
492
438
  * @private
493
439
  */
494
- TwilioConnection.prototype._handleWelcomeTimeout = function () {
440
+ _handleWelcomeTimeout() {
495
441
  if (this.state !== 'connecting') {
496
442
  return;
497
443
  }
498
- var log = this._log;
444
+ const log = this._log;
499
445
  if (this._hellosLeft <= 0) {
500
- var reason = 'All handshake attempts failed';
501
- log.warn("Closing: ".concat(WS_CLOSE_WELCOME_TIMEOUT, " - ").concat(reason));
502
- this._close({ code: WS_CLOSE_WELCOME_TIMEOUT, reason: reason });
446
+ const reason = 'All handshake attempts failed';
447
+ log.warn(`Closing: ${WS_CLOSE_WELCOME_TIMEOUT} - ${reason}`);
448
+ this._close({ code: WS_CLOSE_WELCOME_TIMEOUT, reason });
503
449
  return;
504
450
  }
505
- var maxConsecutiveFailedHellos = this._options.maxConsecutiveFailedHellos;
506
- log.warn("Handshake attempt ".concat(maxConsecutiveFailedHellos - this._hellosLeft, " failed"));
451
+ const { maxConsecutiveFailedHellos } = this._options;
452
+ log.warn(`Handshake attempt ${maxConsecutiveFailedHellos - this._hellosLeft} failed`);
507
453
  this._startHandshake();
508
- };
454
+ }
509
455
  /**
510
456
  * Send a message to the TCMP server.
511
457
  * @param {*} message
512
458
  * @private
513
459
  */
514
- TwilioConnection.prototype._send = function (message) {
515
- var readyState = this._ws.readyState;
516
- var WebSocket = this._options.WebSocket;
460
+ _send(message) {
461
+ const { readyState } = this._ws;
462
+ const { WebSocket } = this._options;
517
463
  if (readyState === WebSocket.OPEN) {
518
- var data = JSON.stringify(message);
519
- this._log.debug("Outgoing: ".concat(data));
464
+ const data = JSON.stringify(message);
465
+ this._log.debug(`Outgoing: ${data}`);
520
466
  try {
521
467
  this._ws.send(data);
522
468
  if (this._sendHeartbeatTimeout) {
@@ -525,31 +471,31 @@ var TwilioConnection = /** @class */ (function (_super) {
525
471
  }
526
472
  }
527
473
  catch (error) {
528
- var reason = 'Failed to send message';
529
- this._log.warn("Closing: ".concat(WS_CLOSE_SEND_FAILED, " - ").concat(reason));
530
- this._close({ code: WS_CLOSE_SEND_FAILED, reason: reason });
474
+ const reason = 'Failed to send message';
475
+ this._log.warn(`Closing: ${WS_CLOSE_SEND_FAILED} - ${reason}`);
476
+ this._close({ code: WS_CLOSE_SEND_FAILED, reason });
531
477
  }
532
478
  }
533
- };
479
+ }
534
480
  /**
535
481
  * Send a "heartbeat" message.
536
482
  * @private
537
483
  */
538
- TwilioConnection.prototype._sendHeartbeat = function () {
484
+ _sendHeartbeat() {
539
485
  if (this.state === 'closed') {
540
486
  return;
541
487
  }
542
488
  this._send({ type: 'heartbeat' });
543
- };
489
+ }
544
490
  /**
545
491
  * Send a "hello" message.
546
492
  * @private
547
493
  */
548
- TwilioConnection.prototype._sendHello = function () {
549
- var _a = this._options, helloBody = _a.helloBody, timeout = _a.requestedHeartbeatTimeout;
550
- var hello = {
494
+ _sendHello() {
495
+ const { helloBody, requestedHeartbeatTimeout: timeout } = this._options;
496
+ const hello = {
551
497
  id: makeUUID(),
552
- timeout: timeout,
498
+ timeout,
553
499
  type: 'hello',
554
500
  version: TCMP_VERSION
555
501
  };
@@ -560,28 +506,26 @@ var TwilioConnection = /** @class */ (function (_super) {
560
506
  hello.body = helloBody;
561
507
  }
562
508
  this._send(hello);
563
- };
509
+ }
564
510
  /**
565
511
  * Send or enqueue a message.
566
512
  * @param {*} message
567
513
  * @private
568
514
  */
569
- TwilioConnection.prototype._sendOrEnqueue = function (message) {
570
- var _this = this;
515
+ _sendOrEnqueue(message) {
571
516
  if (this.state === 'closed') {
572
517
  return;
573
518
  }
574
- var sendOrEnqueue = this.state === 'open'
575
- ? function (message) { return _this._send(message); }
576
- : function (message) { return _this._messageQueue.push(message); };
519
+ const sendOrEnqueue = this.state === 'open'
520
+ ? message => this._send(message)
521
+ : message => this._messageQueue.push(message);
577
522
  sendOrEnqueue(message);
578
- };
523
+ }
579
524
  /**
580
525
  * Start the TCMP handshake.
581
526
  * @private
582
527
  */
583
- TwilioConnection.prototype._startHandshake = function () {
584
- var _this = this;
528
+ _startHandshake() {
585
529
  if (['early', 'waiting'].includes(this.state)) {
586
530
  this.transition('connecting');
587
531
  }
@@ -590,30 +534,29 @@ var TwilioConnection = /** @class */ (function (_super) {
590
534
  }
591
535
  this._hellosLeft--;
592
536
  this._sendHello();
593
- var welcomeTimeout = this._options.welcomeTimeout;
594
- this._welcomeTimeout = new Timeout(function () { return _this._handleWelcomeTimeout(); }, welcomeTimeout);
595
- };
537
+ const { welcomeTimeout } = this._options;
538
+ this._welcomeTimeout = new Timeout(() => this._handleWelcomeTimeout(), welcomeTimeout);
539
+ }
596
540
  /**
597
541
  * Close the {@link TwilioConnection}.
598
542
  * @returns {void}
599
543
  */
600
- TwilioConnection.prototype.close = function () {
544
+ close() {
601
545
  if (this.state === 'closed') {
602
546
  return;
603
547
  }
604
548
  this._sendOrEnqueue({ type: 'bye' });
605
549
  this._close({ code: WS_CLOSE_NORMAL, reason: 'Normal' });
606
- };
550
+ }
607
551
  /**
608
552
  * Send a "msg" message.
609
553
  * @param {*} body
610
554
  * @returns {void}
611
555
  */
612
- TwilioConnection.prototype.sendMessage = function (body) {
613
- this._sendOrEnqueue({ body: body, type: 'msg' });
614
- };
615
- return TwilioConnection;
616
- }(StateMachine));
556
+ sendMessage(body) {
557
+ this._sendOrEnqueue({ body, type: 'msg' });
558
+ }
559
+ }
617
560
  /**
618
561
  * A unique string depicting the reason for the {@link TwilioConnection} being closed.
619
562
  * @enum {string}