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.
- package/.release.json +1 -2
- package/CHANGELOG.md +11 -0
- package/README.md +9 -10
- package/dist/twilio-video.js +29836 -32994
- package/dist/twilio-video.min.js +2 -23
- package/es5/cancelableroompromise.js +4 -4
- package/es5/cancelableroompromise.js.map +1 -1
- package/es5/connect.js +86 -90
- package/es5/connect.js.map +1 -1
- package/es5/createlocaltrack.js +7 -7
- package/es5/createlocaltrack.js.map +1 -1
- package/es5/createlocaltracks.js +111 -195
- package/es5/createlocaltracks.js.map +1 -1
- package/es5/data/receiver.js +16 -34
- package/es5/data/receiver.js.map +1 -1
- package/es5/data/sender.js +28 -47
- package/es5/data/sender.js.map +1 -1
- package/es5/data/transceiver.js +6 -24
- package/es5/data/transceiver.js.map +1 -1
- package/es5/data/transport.js +18 -37
- package/es5/data/transport.js.map +1 -1
- package/es5/encodingparameters.js +14 -33
- package/es5/encodingparameters.js.map +1 -1
- package/es5/eventemitter.js +2 -2
- package/es5/eventemitter.js.map +1 -1
- package/es5/eventtarget.js +12 -40
- package/es5/eventtarget.js.map +1 -1
- package/es5/index.js +21 -32
- package/es5/index.js.map +1 -1
- package/es5/insights/applicationmonitor.js +16 -18
- package/es5/insights/applicationmonitor.js.map +1 -1
- package/es5/insights/computepressuremonitor.js +33 -79
- package/es5/insights/computepressuremonitor.js.map +1 -1
- package/es5/insights/events/application.js +9 -10
- package/es5/insights/events/application.js.map +1 -1
- package/es5/insights/events/getusermedia.js +9 -10
- package/es5/insights/events/getusermedia.js.map +1 -1
- package/es5/insights/events/network.js +14 -16
- package/es5/insights/events/network.js.map +1 -1
- package/es5/insights/events/peerconnection.js +31 -44
- package/es5/insights/events/peerconnection.js.map +1 -1
- package/es5/insights/events/quality.js +13 -14
- package/es5/insights/events/quality.js.map +1 -1
- package/es5/insights/events/room.js +12 -13
- package/es5/insights/events/room.js.map +1 -1
- package/es5/insights/events/system.js +6 -7
- package/es5/insights/events/system.js.map +1 -1
- package/es5/insights/events/track.js +15 -18
- package/es5/insights/events/track.js.map +1 -1
- package/es5/insights/monitorregistry.js +10 -12
- package/es5/insights/monitorregistry.js.map +1 -1
- package/es5/insights/networkmonitor.js +17 -18
- package/es5/insights/networkmonitor.js.map +1 -1
- package/es5/insights/resourcemonitor.js +15 -17
- package/es5/insights/resourcemonitor.js.map +1 -1
- package/es5/insights/statsmonitor.js +100 -172
- package/es5/insights/statsmonitor.js.map +1 -1
- package/es5/insights/telemetry.js +40 -47
- package/es5/insights/telemetry.js.map +1 -1
- package/es5/localparticipant.js +122 -148
- package/es5/localparticipant.js.map +1 -1
- package/es5/media/track/audiotrack.js +11 -28
- package/es5/media/track/audiotrack.js.map +1 -1
- package/es5/media/track/capturevideoframes.js +21 -37
- package/es5/media/track/capturevideoframes.js.map +1 -1
- package/es5/media/track/es5/localaudiotrack.js +3 -3
- package/es5/media/track/es5/localaudiotrack.js.map +1 -1
- package/es5/media/track/es5/localdatatrack.js +3 -3
- package/es5/media/track/es5/localdatatrack.js.map +1 -1
- package/es5/media/track/es5/localvideotrack.js +3 -3
- package/es5/media/track/es5/localvideotrack.js.map +1 -1
- package/es5/media/track/index.js +17 -36
- package/es5/media/track/index.js.map +1 -1
- package/es5/media/track/localaudiotrack.js +80 -105
- package/es5/media/track/localaudiotrack.js.map +1 -1
- package/es5/media/track/localaudiotrackpublication.js +8 -25
- package/es5/media/track/localaudiotrackpublication.js.map +1 -1
- package/es5/media/track/localdatatrack.js +11 -30
- package/es5/media/track/localdatatrack.js.map +1 -1
- package/es5/media/track/localdatatrackpublication.js +8 -25
- package/es5/media/track/localdatatrackpublication.js.map +1 -1
- package/es5/media/track/localmediatrack.js +104 -129
- package/es5/media/track/localmediatrack.js.map +1 -1
- package/es5/media/track/localtrackpublication.js +24 -82
- package/es5/media/track/localtrackpublication.js.map +1 -1
- package/es5/media/track/localvideotrack.js +87 -112
- package/es5/media/track/localvideotrack.js.map +1 -1
- package/es5/media/track/localvideotrackpublication.js +8 -25
- package/es5/media/track/localvideotrackpublication.js.map +1 -1
- package/es5/media/track/mediatrack.js +71 -95
- package/es5/media/track/mediatrack.js.map +1 -1
- package/es5/media/track/noisecancellationimpl.js +63 -129
- package/es5/media/track/noisecancellationimpl.js.map +1 -1
- package/es5/media/track/receiver.js +5 -22
- package/es5/media/track/receiver.js.map +1 -1
- package/es5/media/track/remoteaudiotrack.js +16 -33
- package/es5/media/track/remoteaudiotrack.js.map +1 -1
- package/es5/media/track/remoteaudiotrackpublication.js +8 -25
- package/es5/media/track/remoteaudiotrackpublication.js.map +1 -1
- package/es5/media/track/remotedatatrack.js +18 -61
- package/es5/media/track/remotedatatrack.js.map +1 -1
- package/es5/media/track/remotedatatrackpublication.js +8 -25
- package/es5/media/track/remotedatatrackpublication.js.map +1 -1
- package/es5/media/track/remotemediatrack.js +36 -80
- package/es5/media/track/remotemediatrack.js.map +1 -1
- package/es5/media/track/remotetrackpublication.js +30 -48
- package/es5/media/track/remotetrackpublication.js.map +1 -1
- package/es5/media/track/remotevideotrack.js +94 -133
- package/es5/media/track/remotevideotrack.js.map +1 -1
- package/es5/media/track/remotevideotrackpublication.js +8 -25
- package/es5/media/track/remotevideotrackpublication.js.map +1 -1
- package/es5/media/track/sender.js +46 -83
- package/es5/media/track/sender.js.map +1 -1
- package/es5/media/track/trackpublication.js +17 -35
- package/es5/media/track/trackpublication.js.map +1 -1
- package/es5/media/track/transceiver.js +12 -30
- package/es5/media/track/transceiver.js.map +1 -1
- package/es5/media/track/videoprocessoreventobserver.js +47 -65
- package/es5/media/track/videoprocessoreventobserver.js.map +1 -1
- package/es5/media/track/videotrack.js +103 -124
- package/es5/media/track/videotrack.js.map +1 -1
- package/es5/networkqualityconfiguration.js +12 -48
- package/es5/networkqualityconfiguration.js.map +1 -1
- package/es5/noisecancellationadapter.js +72 -120
- package/es5/noisecancellationadapter.js.map +1 -1
- package/es5/participant.js +126 -179
- package/es5/participant.js.map +1 -1
- package/es5/preflight/getCombinedConnectionStats.js +44 -95
- package/es5/preflight/getCombinedConnectionStats.js.map +1 -1
- package/es5/preflight/getturncredentials.js +13 -13
- package/es5/preflight/getturncredentials.js.map +1 -1
- package/es5/preflight/makestat.js +4 -29
- package/es5/preflight/makestat.js.map +1 -1
- package/es5/preflight/mos.js +5 -5
- package/es5/preflight/mos.js.map +1 -1
- package/es5/preflight/preflighttest.js +240 -381
- package/es5/preflight/preflighttest.js.map +1 -1
- package/es5/preflight/syntheticaudio.js +8 -8
- package/es5/preflight/syntheticaudio.js.map +1 -1
- package/es5/preflight/syntheticvideo.js +13 -14
- package/es5/preflight/syntheticvideo.js.map +1 -1
- package/es5/preflight/timer.js +9 -10
- package/es5/preflight/timer.js.map +1 -1
- package/es5/queueingeventemitter.js +16 -60
- package/es5/queueingeventemitter.js.map +1 -1
- package/es5/remoteparticipant.js +33 -76
- package/es5/remoteparticipant.js.map +1 -1
- package/es5/room.js +89 -169
- package/es5/room.js.map +1 -1
- package/es5/signaling/index.js +36 -55
- package/es5/signaling/index.js.map +1 -1
- package/es5/signaling/localparticipant.js +18 -37
- package/es5/signaling/localparticipant.js.map +1 -1
- package/es5/signaling/localtrackpublication.js +28 -51
- package/es5/signaling/localtrackpublication.js.map +1 -1
- package/es5/signaling/participant.js +37 -63
- package/es5/signaling/participant.js.map +1 -1
- package/es5/signaling/recording.js +11 -29
- package/es5/signaling/recording.js.map +1 -1
- package/es5/signaling/remoteparticipant.js +6 -24
- package/es5/signaling/remoteparticipant.js.map +1 -1
- package/es5/signaling/remotetrackpublication.js +27 -53
- package/es5/signaling/remotetrackpublication.js.map +1 -1
- package/es5/signaling/room.js +40 -59
- package/es5/signaling/room.js.map +1 -1
- package/es5/signaling/track.js +52 -90
- package/es5/signaling/track.js.map +1 -1
- package/es5/signaling/v2/cancelableroomsignalingpromise.js +46 -46
- package/es5/signaling/v2/cancelableroomsignalingpromise.js.map +1 -1
- package/es5/signaling/v2/dominantspeakersignaling.js +18 -40
- package/es5/signaling/v2/dominantspeakersignaling.js.map +1 -1
- package/es5/signaling/v2/icebox.js +12 -13
- package/es5/signaling/v2/icebox.js.map +1 -1
- package/es5/signaling/v2/iceconnectionmonitor.js +28 -32
- package/es5/signaling/v2/iceconnectionmonitor.js.map +1 -1
- package/es5/signaling/v2/index.js +12 -31
- package/es5/signaling/v2/index.js.map +1 -1
- package/es5/signaling/v2/localparticipant.js +65 -85
- package/es5/signaling/v2/localparticipant.js.map +1 -1
- package/es5/signaling/v2/localtrackpublication.js +21 -39
- package/es5/signaling/v2/localtrackpublication.js.map +1 -1
- package/es5/signaling/v2/mediasignaling.js +25 -48
- package/es5/signaling/v2/mediasignaling.js.map +1 -1
- package/es5/signaling/v2/networkqualitymonitor.js +50 -97
- package/es5/signaling/v2/networkqualitymonitor.js.map +1 -1
- package/es5/signaling/v2/networkqualitysignaling.js +56 -88
- package/es5/signaling/v2/networkqualitysignaling.js.map +1 -1
- package/es5/signaling/v2/peerconnection.js +523 -648
- package/es5/signaling/v2/peerconnection.js.map +1 -1
- package/es5/signaling/v2/peerconnectionmanager.js +111 -167
- package/es5/signaling/v2/peerconnectionmanager.js.map +1 -1
- package/es5/signaling/v2/publisherhintsignaling.js +22 -42
- package/es5/signaling/v2/publisherhintsignaling.js.map +1 -1
- package/es5/signaling/v2/recording.js +8 -26
- package/es5/signaling/v2/recording.js.map +1 -1
- package/es5/signaling/v2/remoteparticipant.js +25 -43
- package/es5/signaling/v2/remoteparticipant.js.map +1 -1
- package/es5/signaling/v2/remotetrackpublication.js +7 -24
- package/es5/signaling/v2/remotetrackpublication.js.map +1 -1
- package/es5/signaling/v2/renderhintssignaling.js +40 -61
- package/es5/signaling/v2/renderhintssignaling.js.map +1 -1
- package/es5/signaling/v2/room.js +216 -280
- package/es5/signaling/v2/room.js.map +1 -1
- package/es5/signaling/v2/trackprioritysignaling.js +11 -29
- package/es5/signaling/v2/trackprioritysignaling.js.map +1 -1
- package/es5/signaling/v2/trackswitchoffsignaling.js +10 -28
- package/es5/signaling/v2/trackswitchoffsignaling.js.map +1 -1
- package/es5/signaling/v2/transcriptionsignaling.js +8 -26
- package/es5/signaling/v2/transcriptionsignaling.js.map +1 -1
- package/es5/signaling/v2/twilioconnectiontransport.js +62 -82
- package/es5/signaling/v2/twilioconnectiontransport.js.map +1 -1
- package/es5/statemachine.js +75 -121
- package/es5/statemachine.js.map +1 -1
- package/es5/stats/average.js +2 -2
- package/es5/stats/average.js.map +1 -1
- package/es5/stats/icereport.js +11 -12
- package/es5/stats/icereport.js.map +1 -1
- package/es5/stats/icereportfactory.js +8 -9
- package/es5/stats/icereportfactory.js.map +1 -1
- package/es5/stats/localaudiotrackstats.js +6 -24
- package/es5/stats/localaudiotrackstats.js.map +1 -1
- package/es5/stats/localtrackstats.js +6 -24
- package/es5/stats/localtrackstats.js.map +1 -1
- package/es5/stats/localvideotrackstats.js +9 -27
- package/es5/stats/localvideotrackstats.js.map +1 -1
- package/es5/stats/networkqualityaudiostats.js +5 -22
- package/es5/stats/networkqualityaudiostats.js.map +1 -1
- package/es5/stats/networkqualitybandwidthstats.js +3 -5
- package/es5/stats/networkqualitybandwidthstats.js.map +1 -1
- package/es5/stats/networkqualityfractionloststats.js +3 -5
- package/es5/stats/networkqualityfractionloststats.js.map +1 -1
- package/es5/stats/networkqualitylatencystats.js +3 -5
- package/es5/stats/networkqualitylatencystats.js.map +1 -1
- package/es5/stats/networkqualitymediastats.js +5 -7
- package/es5/stats/networkqualitymediastats.js.map +1 -1
- package/es5/stats/networkqualityrecvstats.js +5 -22
- package/es5/stats/networkqualityrecvstats.js.map +1 -1
- package/es5/stats/networkqualitysendorrecvstats.js +6 -8
- package/es5/stats/networkqualitysendorrecvstats.js.map +1 -1
- package/es5/stats/networkqualitysendstats.js +5 -22
- package/es5/stats/networkqualitysendstats.js.map +1 -1
- package/es5/stats/networkqualitystats.js +5 -7
- package/es5/stats/networkqualitystats.js.map +1 -1
- package/es5/stats/networkqualityvideostats.js +5 -22
- package/es5/stats/networkqualityvideostats.js.map +1 -1
- package/es5/stats/peerconnectionreport.js +13 -14
- package/es5/stats/peerconnectionreport.js.map +1 -1
- package/es5/stats/peerconnectionreportfactory.js +89 -185
- package/es5/stats/peerconnectionreportfactory.js.map +1 -1
- package/es5/stats/receiverreport.js +28 -46
- package/es5/stats/receiverreport.js.map +1 -1
- package/es5/stats/receiverreportfactory.js +11 -29
- package/es5/stats/receiverreportfactory.js.map +1 -1
- package/es5/stats/remoteaudiotrackstats.js +6 -24
- package/es5/stats/remoteaudiotrackstats.js.map +1 -1
- package/es5/stats/remotetrackstats.js +6 -24
- package/es5/stats/remotetrackstats.js.map +1 -1
- package/es5/stats/remotevideotrackstats.js +7 -25
- package/es5/stats/remotevideotrackstats.js.map +1 -1
- package/es5/stats/senderorreceiverreport.js +3 -4
- package/es5/stats/senderorreceiverreport.js.map +1 -1
- package/es5/stats/senderorreceiverreportfactory.js +3 -4
- package/es5/stats/senderorreceiverreportfactory.js.map +1 -1
- package/es5/stats/senderreport.js +20 -38
- package/es5/stats/senderreport.js.map +1 -1
- package/es5/stats/senderreportfactory.js +11 -29
- package/es5/stats/senderreportfactory.js.map +1 -1
- package/es5/stats/statsreport.js +11 -12
- package/es5/stats/statsreport.js.map +1 -1
- package/es5/stats/sum.js +1 -1
- package/es5/stats/sum.js.map +1 -1
- package/es5/stats/trackstats.js +3 -4
- package/es5/stats/trackstats.js.map +1 -1
- package/es5/transceiver.js +8 -26
- package/es5/transceiver.js.map +1 -1
- package/es5/twilioconnection.js +166 -223
- package/es5/twilioconnection.js.map +1 -1
- package/es5/util/asyncvar.js +12 -14
- package/es5/util/asyncvar.js.map +1 -1
- package/es5/util/backoff.js +14 -16
- package/es5/util/backoff.js.map +1 -1
- package/es5/util/browserdetection.js +19 -35
- package/es5/util/browserdetection.js.map +1 -1
- package/es5/util/cancelablepromise.js +30 -57
- package/es5/util/cancelablepromise.js.map +1 -1
- package/es5/util/constants.js +13 -13
- package/es5/util/constants.js.map +1 -1
- package/es5/util/detectsilentaudio.js +10 -10
- package/es5/util/detectsilentaudio.js.map +1 -1
- package/es5/util/detectsilentvideo.js +12 -12
- package/es5/util/detectsilentvideo.js.map +1 -1
- package/es5/util/documentvisibilitymonitor.js +34 -41
- package/es5/util/documentvisibilitymonitor.js.map +1 -1
- package/es5/util/dynamicimport.js +4 -4
- package/es5/util/dynamicimport.js.map +1 -1
- package/es5/util/eventobserver.js +19 -39
- package/es5/util/eventobserver.js.map +1 -1
- package/es5/util/filter.js +11 -12
- package/es5/util/filter.js.map +1 -1
- package/es5/util/index.js +96 -165
- package/es5/util/index.js.map +1 -1
- package/es5/util/insightspublisher/index.js +48 -78
- package/es5/util/insightspublisher/index.js.map +1 -1
- package/es5/util/insightspublisher/null.js +9 -10
- package/es5/util/insightspublisher/null.js.map +1 -1
- package/es5/util/localmediarestartdeferreds.js +10 -11
- package/es5/util/localmediarestartdeferreds.js.map +1 -1
- package/es5/util/log.js +44 -70
- package/es5/util/log.js.map +1 -1
- package/es5/util/movingaveragedelta.js +12 -13
- package/es5/util/movingaveragedelta.js.map +1 -1
- package/es5/util/networkmonitor.js +26 -30
- package/es5/util/networkmonitor.js.map +1 -1
- package/es5/util/nullobserver.js +22 -48
- package/es5/util/nullobserver.js.map +1 -1
- package/es5/util/sdp/index.js +109 -134
- package/es5/util/sdp/index.js.map +1 -1
- package/es5/util/sdp/issue8329.js +56 -57
- package/es5/util/sdp/issue8329.js.map +1 -1
- package/es5/util/sdp/simulcast.js +55 -73
- package/es5/util/sdp/simulcast.js.map +1 -1
- package/es5/util/sdp/trackmatcher.js +14 -15
- package/es5/util/sdp/trackmatcher.js.map +1 -1
- package/es5/util/sid.js +5 -5
- package/es5/util/sid.js.map +1 -1
- package/es5/util/support.js +13 -16
- package/es5/util/support.js.map +1 -1
- package/es5/util/timeout.js +28 -39
- package/es5/util/timeout.js.map +1 -1
- package/es5/util/timeoutpromise.js +38 -84
- package/es5/util/timeoutpromise.js.map +1 -1
- package/es5/util/twilio-video-errors.js +277 -457
- package/es5/util/twilio-video-errors.js.map +1 -1
- package/es5/util/twilioerror.js +13 -57
- package/es5/util/twilioerror.js.map +1 -1
- package/es5/util/twiliowarning.js +1 -1
- package/es5/util/twiliowarning.js.map +1 -1
- package/es5/util/validate.js +13 -15
- package/es5/util/validate.js.map +1 -1
- package/es5/vendor/inherits.js +3 -5
- package/es5/vendor/inherits.js.map +1 -1
- package/es5/webaudio/audiocontext.js +8 -9
- package/es5/webaudio/audiocontext.js.map +1 -1
- package/es5/webaudio/detectsilence.js +9 -9
- package/es5/webaudio/detectsilence.js.map +1 -1
- package/es5/webaudio/workaround180748.js +15 -13
- package/es5/webaudio/workaround180748.js.map +1 -1
- package/es5/webrtc/getstats.js +242 -448
- package/es5/webrtc/getstats.js.map +1 -1
- package/es5/webrtc/getusermedia.js +1 -2
- package/es5/webrtc/getusermedia.js.map +1 -1
- package/es5/webrtc/index.js +1 -17
- package/es5/webrtc/index.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/chrome.js +102 -295
- package/es5/webrtc/rtcpeerconnection/chrome.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/firefox.js +69 -146
- package/es5/webrtc/rtcpeerconnection/firefox.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/index.js +1 -1
- package/es5/webrtc/rtcpeerconnection/index.js.map +1 -1
- package/es5/webrtc/rtcpeerconnection/safari.js +110 -192
- package/es5/webrtc/rtcpeerconnection/safari.js.map +1 -1
- package/es5/webrtc/rtcrtpsender.js +3 -4
- package/es5/webrtc/rtcrtpsender.js.map +1 -1
- package/es5/webrtc/util/index.js +28 -63
- package/es5/webrtc/util/index.js.map +1 -1
- package/es5/webrtc/util/latch.js +21 -28
- package/es5/webrtc/util/latch.js.map +1 -1
- package/es5/webrtc/util/sdp.js +41 -211
- package/es5/webrtc/util/sdp.js.map +1 -1
- package/lib/connect.js +0 -1
- package/lib/createlocaltracks.ts +2 -2
- package/lib/localparticipant.js +0 -1
- package/lib/media/track/mediatrack.js +0 -2
- package/lib/media/track/noisecancellationimpl.ts +2 -2
- package/lib/noisecancellationadapter.ts +2 -2
- package/lib/preflight/getCombinedConnectionStats.ts +1 -1
- package/lib/preflight/getturncredentials.ts +2 -2
- package/lib/preflight/preflighttest.ts +3 -3
- package/lib/signaling/v2/peerconnection.js +2 -4
- package/lib/util/sdp/index.js +1 -2
- package/lib/util/sdp/issue8329.js +0 -2
- package/lib/util/support.js +4 -7
- package/lib/webrtc/getstats.js +6 -21
- package/lib/webrtc/index.js +0 -16
- package/lib/webrtc/rtcpeerconnection/chrome.js +13 -123
- package/lib/webrtc/rtcpeerconnection/firefox.js +5 -6
- package/lib/webrtc/rtcpeerconnection/safari.js +9 -19
- package/lib/webrtc/util/sdp.js +13 -194
- package/package.json +16 -11
- package/rollup.config.mjs +85 -0
- package/tsconfig.json +5 -5
- package/es5/webrtc/mediastream.js +0 -11
- package/es5/webrtc/mediastream.js.map +0 -1
- package/es5/webrtc/mediastreamtrack.js +0 -11
- package/es5/webrtc/mediastreamtrack.js.map +0 -1
- package/es5/webrtc/rtcicecandidate.js +0 -11
- package/es5/webrtc/rtcicecandidate.js.map +0 -1
- package/es5/webrtc/rtcsessiondescription/chrome.js +0 -43
- package/es5/webrtc/rtcsessiondescription/chrome.js.map +0 -1
- package/es5/webrtc/rtcsessiondescription/firefox.js +0 -4
- package/es5/webrtc/rtcsessiondescription/firefox.js.map +0 -1
- package/es5/webrtc/rtcsessiondescription/index.js +0 -22
- package/es5/webrtc/rtcsessiondescription/index.js.map +0 -1
- package/lib/webrtc/mediastream.js +0 -10
- package/lib/webrtc/mediastreamtrack.js +0 -10
- package/lib/webrtc/rtcicecandidate.js +0 -10
- package/lib/webrtc/rtcsessiondescription/chrome.js +0 -39
- package/lib/webrtc/rtcsessiondescription/firefox.js +0 -4
- package/lib/webrtc/rtcsessiondescription/index.js +0 -21
- package/src/twilio-video.js +0 -16
package/es5/twilioconnection.js
CHANGED
|
@@ -1,50 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
34
|
+
const events = {
|
|
75
35
|
closed: 'close',
|
|
76
36
|
open: 'open',
|
|
77
37
|
waiting: 'waiting'
|
|
78
38
|
};
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
133
|
-
|
|
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
|
|
142
|
-
WebSocket
|
|
100
|
+
Log,
|
|
101
|
+
WebSocket
|
|
143
102
|
}, options);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
109
|
+
this._close({ code: WS_CLOSE_NETWORK_CHANGED, reason });
|
|
151
110
|
}) : null;
|
|
152
|
-
Object.defineProperties(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
179
|
+
this.emit(events[state], ...args);
|
|
225
180
|
}
|
|
226
|
-
|
|
181
|
+
const event = { name: state, group: 'signaling', level: eventsToLevels[this.state] };
|
|
227
182
|
if (state === 'closed') {
|
|
228
|
-
|
|
229
|
-
event.payload = { reason
|
|
183
|
+
const [reason] = args;
|
|
184
|
+
event.payload = { reason };
|
|
230
185
|
event.level = reason === CloseReason.LOCAL ? 'info' : 'error';
|
|
231
186
|
}
|
|
232
|
-
|
|
187
|
+
this._eventObserver.emit('event', event);
|
|
233
188
|
});
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
284
|
-
|
|
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
|
-
|
|
294
|
-
|
|
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(
|
|
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
|
-
|
|
257
|
+
const ws = this._ws;
|
|
306
258
|
log.debug('Created a new WebSocket:', ws);
|
|
307
|
-
ws.addEventListener('close',
|
|
308
|
-
|
|
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(
|
|
311
|
-
|
|
312
|
-
|
|
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',
|
|
266
|
+
ws.addEventListener('open', () => {
|
|
315
267
|
log.debug('WebSocket opened:', ws);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (
|
|
319
|
-
|
|
268
|
+
this._openTimeout.clear();
|
|
269
|
+
this._startHandshake();
|
|
270
|
+
if (this._networkMonitor) {
|
|
271
|
+
this._networkMonitor.start();
|
|
320
272
|
}
|
|
321
273
|
});
|
|
322
|
-
ws.addEventListener('message',
|
|
323
|
-
log.debug(
|
|
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
|
-
|
|
280
|
+
this.emit('error', error);
|
|
329
281
|
return;
|
|
330
282
|
}
|
|
331
283
|
switch (message.type) {
|
|
332
284
|
case 'bad':
|
|
333
|
-
|
|
285
|
+
this._handleBad(message);
|
|
334
286
|
break;
|
|
335
287
|
case 'busy':
|
|
336
|
-
|
|
288
|
+
this._handleBusy(message);
|
|
337
289
|
break;
|
|
338
290
|
case 'bye':
|
|
339
291
|
// Do nothing.
|
|
340
292
|
break;
|
|
341
293
|
case 'msg':
|
|
342
|
-
|
|
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
|
-
|
|
299
|
+
this._handleHeartbeat();
|
|
348
300
|
break;
|
|
349
301
|
case 'welcome':
|
|
350
|
-
|
|
302
|
+
this._handleWelcome(message);
|
|
351
303
|
break;
|
|
352
304
|
default:
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
365
|
-
|
|
366
|
-
var log = this._log;
|
|
316
|
+
_handleBad({ reason }) {
|
|
317
|
+
const log = this._log;
|
|
367
318
|
if (!['connecting', 'open'].includes(this.state)) {
|
|
368
|
-
log.warn(
|
|
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(
|
|
374
|
-
this._close({ code: WS_CLOSE_HELLO_FAILED, 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(
|
|
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
|
-
|
|
386
|
-
|
|
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(
|
|
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
|
-
|
|
349
|
+
const reason = retryAfter < 0
|
|
401
350
|
? 'Received terminal "busy" message'
|
|
402
|
-
:
|
|
351
|
+
: `Received "busy" message, retrying after ${retryAfter} ms`;
|
|
403
352
|
if (retryAfter < 0) {
|
|
404
|
-
log.warn(
|
|
405
|
-
this._close({ code: WS_CLOSE_SERVER_BUSY, 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
|
-
|
|
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(
|
|
362
|
+
this._busyWaitTimeout = new Timeout(() => this._startHandshake(), retryAfter);
|
|
414
363
|
}
|
|
415
364
|
else {
|
|
416
|
-
log.warn(
|
|
417
|
-
this._close({ code: WS_CLOSE_BUSY_WAIT, reason
|
|
418
|
-
this._busyWaitTimeout = new Timeout(
|
|
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
|
-
|
|
375
|
+
_handleHeartbeat() {
|
|
427
376
|
if (this.state !== 'open') {
|
|
428
|
-
this._log.warn(
|
|
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
|
-
|
|
387
|
+
_handleHeartbeatTimeout() {
|
|
439
388
|
if (this.state !== 'open') {
|
|
440
389
|
return;
|
|
441
390
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
log.debug(
|
|
445
|
-
|
|
446
|
-
log.warn(
|
|
447
|
-
this._close({ code: WS_CLOSE_HEARTBEATS_MISSED, 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
|
-
|
|
455
|
-
var body = _a.body;
|
|
403
|
+
_handleMessage({ body }) {
|
|
456
404
|
if (this.state !== 'open') {
|
|
457
|
-
this._log.warn(
|
|
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
|
-
|
|
469
|
-
|
|
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(
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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(
|
|
486
|
-
this._messageQueue.splice(0).forEach(
|
|
487
|
-
this._sendHeartbeatTimeout = new Timeout(
|
|
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
|
-
|
|
440
|
+
_handleWelcomeTimeout() {
|
|
495
441
|
if (this.state !== 'connecting') {
|
|
496
442
|
return;
|
|
497
443
|
}
|
|
498
|
-
|
|
444
|
+
const log = this._log;
|
|
499
445
|
if (this._hellosLeft <= 0) {
|
|
500
|
-
|
|
501
|
-
log.warn(
|
|
502
|
-
this._close({ code: WS_CLOSE_WELCOME_TIMEOUT, 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
|
-
|
|
506
|
-
log.warn(
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
460
|
+
_send(message) {
|
|
461
|
+
const { readyState } = this._ws;
|
|
462
|
+
const { WebSocket } = this._options;
|
|
517
463
|
if (readyState === WebSocket.OPEN) {
|
|
518
|
-
|
|
519
|
-
this._log.debug(
|
|
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
|
-
|
|
529
|
-
this._log.warn(
|
|
530
|
-
this._close({ code: WS_CLOSE_SEND_FAILED, 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
|
-
|
|
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
|
-
|
|
549
|
-
|
|
550
|
-
|
|
494
|
+
_sendHello() {
|
|
495
|
+
const { helloBody, requestedHeartbeatTimeout: timeout } = this._options;
|
|
496
|
+
const hello = {
|
|
551
497
|
id: makeUUID(),
|
|
552
|
-
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
|
-
|
|
570
|
-
var _this = this;
|
|
515
|
+
_sendOrEnqueue(message) {
|
|
571
516
|
if (this.state === 'closed') {
|
|
572
517
|
return;
|
|
573
518
|
}
|
|
574
|
-
|
|
575
|
-
?
|
|
576
|
-
:
|
|
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
|
-
|
|
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
|
-
|
|
594
|
-
this._welcomeTimeout = new Timeout(
|
|
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
|
-
|
|
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
|
-
|
|
613
|
-
this._sendOrEnqueue({ body
|
|
614
|
-
}
|
|
615
|
-
|
|
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}
|