-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_BaseWebRTC.js.html
308 lines (245 loc) · 37.4 KB
/
utils_BaseWebRTC.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Adding favicon -->
<!-- Adding meta -->
<!-- Adding external script-->
<!-- Adding external style-->
<!-- Adding scripts-->
<!-- Adding style-->
<!-- Adding overlay script-->
<!-- Adding overlay style-->
<title>
utils/BaseWebRTC.js
</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/third-party/ionicons.min.css">
<link type="text/css" rel="stylesheet" href="styles/third-party/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/reset.css">
<link type="text/css" rel="stylesheet" href="styles/clean-jsdoc-theme-base.css">
<link type="text/css" rel="stylesheet" href="styles/clean-jsdoc-theme-light.css">
<svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
style="display:none">
<defs>
<symbol id="copy-icon" viewbox="0 0 488.3 488.3">
<g>
<path
d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z" />
<path
d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z" />
</g>
</symbol>
<symbol id='search-icon' viewBox="0 0 512 512">
<g>
<g>
<path
d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z" />
</g>
</g>
<g>
<g>
<path
d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z" />
</g>
</g>
</symbol>
<symbol id="down-icon" viewBox="0 0 16 16">
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"
>
</path>
</symbol>
</defs>
</svg>
</head>
<body>
<nav class="navbar" id="navbar">
<div class="navbar-heading" id="navbar-heading"><a href="index.html"><h2 class="navbar-heading-text">JavaScript SDK</h2></a></div><div class="search-box" id="search-box"><div class="search-box-input-container"><input class="search-box-input" type="text" placeholder="Search..." id="search-box-input" /><svg class="search-icon" alt="search-icon"><use xlink:href="#search-icon"></use></svg></div><div class="search-item-container" id="search-item-container"><ul class="search-item-ul" id="search-item-ul"></ul></div></div><div class="sidebar-main-content" id="sidebar-main-content"><div class="accordion collapsed" id="7557599" > <h3 class="accordion-heading">Modules<svg><use xlink:href="#down-icon"></use></svg></h3><ul class="accordion-content"><li class="accordion collapsed child" id=8443790><div class="accordion-heading child"><a href="module-Director.html">Director</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="module-Director.html#~getEndpoint">getEndpoint</a></li><li data-type='method'><a href="module-Director.html#~getLiveDomain">getLiveDomain</a></li><li data-type='method'><a href="module-Director.html#~getPublisher">getPublisher</a></li><li data-type='method'><a href="module-Director.html#~getSubscriber">getSubscriber</a></li><li data-type='method'><a href="module-Director.html#~setEndpoint">setEndpoint</a></li><li data-type='method'><a href="module-Director.html#~setLiveDomain">setLiveDomain</a></li></ul></li><li class="accordion collapsed child" id=5836212><div class="accordion-heading child"><a href="module-Logger.html">Logger</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="module-Logger.html#~get">get</a></li><li data-type='method'><a href="module-Logger.html#~getHistory">getHistory</a></li><li data-type='method'><a href="module-Logger.html#~getHistoryMaxSize">getHistoryMaxSize</a></li><li data-type='method'><a href="module-Logger.html#~getLevel">getLevel</a></li><li data-type='method'><a href="module-Logger.html#~setHandler">setHandler</a></li><li data-type='method'><a href="module-Logger.html#~setHistoryMaxSize">setHistoryMaxSize</a></li><li data-type='method'><a href="module-Logger.html#~setLevel">setLevel</a></li></ul></li><li class="accordion collapsed child" id=810655><div class="accordion-heading child"><a href="module-SdpParser.html">SdpParser</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="module-SdpParser.html#~adaptCodecName">adaptCodecName</a></li><li data-type='method'><a href="module-SdpParser.html#~getAvailableHeaderExtensionIdRange">getAvailableHeaderExtensionIdRange</a></li><li data-type='method'><a href="module-SdpParser.html#~getAvailablePayloadTypeRange">getAvailablePayloadTypeRange</a></li><li data-type='method'><a href="module-SdpParser.html#~removeSdpLine">removeSdpLine</a></li><li data-type='method'><a href="module-SdpParser.html#~renegotiate">renegotiate</a></li><li data-type='method'><a href="module-SdpParser.html#~setAbsoluteCaptureTime">setAbsoluteCaptureTime</a></li><li data-type='method'><a href="module-SdpParser.html#~setDependencyDescriptor">setDependencyDescriptor</a></li><li data-type='method'><a href="module-SdpParser.html#~setDTX">setDTX</a></li><li data-type='method'><a href="module-SdpParser.html#~setMultiopus">setMultiopus</a></li><li data-type='method'><a href="module-SdpParser.html#~setSimulcast">setSimulcast</a></li><li data-type='method'><a href="module-SdpParser.html#~setStereo">setStereo</a></li><li data-type='method'><a href="module-SdpParser.html#~setVideoBitrate">setVideoBitrate</a></li><li data-type='method'><a href="module-SdpParser.html#~updateMissingVideoExtensions">updateMissingVideoExtensions</a></li></ul></li></ul> </div><div class="accordion collapsed" id="1490423" > <h3 class="accordion-heading">Classes<svg><use xlink:href="#down-icon"></use></svg></h3><ul class="accordion-content"><li class="accordion collapsed child" id=4205529><div class="accordion-heading child"><a href="BaseWebRTC.html">BaseWebRTC</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="BaseWebRTC.html#getRTCPeerConnection">getRTCPeerConnection</a></li><li data-type='method'><a href="BaseWebRTC.html#isActive">isActive</a></li><li data-type='method'><a href="BaseWebRTC.html#reconnect">reconnect</a></li><li data-type='method'><a href="BaseWebRTC.html#setReconnect">setReconnect</a></li><li data-type='method'><a href="BaseWebRTC.html#stop">stop</a></li></ul></li><li class="accordion collapsed child" id=8899913><div class="accordion-heading child"><a href="PeerConnection.html">PeerConnection</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="PeerConnection.html#.getCapabilities">getCapabilities</a></li><li data-type='method'><a href="PeerConnection.html#addRemoteTrack">addRemoteTrack</a></li><li data-type='method'><a href="PeerConnection.html#closeRTCPeer">closeRTCPeer</a></li><li data-type='method'><a href="PeerConnection.html#createRTCPeer">createRTCPeer</a></li><li data-type='method'><a href="PeerConnection.html#getRTCLocalSDP">getRTCLocalSDP</a></li><li data-type='method'><a href="PeerConnection.html#getRTCPeer">getRTCPeer</a></li><li data-type='method'><a href="PeerConnection.html#getRTCPeerStatus">getRTCPeerStatus</a></li><li data-type='method'><a href="PeerConnection.html#getTracks">getTracks</a></li><li data-type='method'><a href="PeerConnection.html#initStats">initStats</a></li><li data-type='method'><a href="PeerConnection.html#replaceTrack">replaceTrack</a></li><li data-type='method'><a href="PeerConnection.html#setRTCRemoteSDP">setRTCRemoteSDP</a></li><li data-type='method'><a href="PeerConnection.html#stopStats">stopStats</a></li><li data-type='method'><a href="PeerConnection.html#updateBandwidthRestriction">updateBandwidthRestriction</a></li><li data-type='method'><a href="PeerConnection.html#updateBitrate">updateBitrate</a></li></ul></li><li class="accordion collapsed child" id=281125><div class="accordion-heading child"><a href="Publish.html">Publish</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="Publish.html#connect">connect</a></li><li data-type='method'><a href="Publish.html#getRTCPeerConnection">getRTCPeerConnection</a></li><li data-type='method'><a href="Publish.html#isActive">isActive</a></li><li data-type='method'><a href="Publish.html#reconnect">reconnect</a></li><li data-type='method'><a href="Publish.html#record">record</a></li><li data-type='method'><a href="Publish.html#setReconnect">setReconnect</a></li><li data-type='method'><a href="Publish.html#stop">stop</a></li><li data-type='method'><a href="Publish.html#unrecord">unrecord</a></li></ul></li><li class="accordion collapsed child" id=6958554><div class="accordion-heading child"><a href="Signaling.html">Signaling</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="Signaling.html#close">close</a></li><li data-type='method'><a href="Signaling.html#cmd">cmd</a></li><li data-type='method'><a href="Signaling.html#connect">connect</a></li><li data-type='method'><a href="Signaling.html#publish">publish</a></li><li data-type='method'><a href="Signaling.html#subscribe">subscribe</a></li></ul></li><li class="accordion collapsed child" id=3108999><div class="accordion-heading child"><a href="StreamEvents.html">StreamEvents</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="StreamEvents.html#.getEventsLocation">getEventsLocation</a></li><li data-type='method'><a href="StreamEvents.html#.init">init</a></li><li data-type='method'><a href="StreamEvents.html#.setEventsLocation">setEventsLocation</a></li><li data-type='method'><a href="StreamEvents.html#onUserCount">onUserCount</a></li><li data-type='method'><a href="StreamEvents.html#stop">stop</a></li></ul></li><li class="accordion collapsed child" id=9464527><div class="accordion-heading child"><a href="View.html">View</a><svg><use xlink:href="#down-icon"></use></svg></div><ul class='methods accordion-content'><li data-type='method'><a href="View.html#addRemoteTrack">addRemoteTrack</a></li><li data-type='method'><a href="View.html#connect">connect</a></li><li data-type='method'><a href="View.html#getRTCPeerConnection">getRTCPeerConnection</a></li><li data-type='method'><a href="View.html#isActive">isActive</a></li><li data-type='method'><a href="View.html#project">project</a></li><li data-type='method'><a href="View.html#reconnect">reconnect</a></li><li data-type='method'><a href="View.html#select">select</a></li><li data-type='method'><a href="View.html#setReconnect">setReconnect</a></li><li data-type='method'><a href="View.html#stop">stop</a></li><li data-type='method'><a href="View.html#unproject">unproject</a></li></ul></li></ul> </div><div class="accordion collapsed" id="2939770" > <h3 class="accordion-heading">Events<svg><use xlink:href="#down-icon"></use></svg></h3><ul class="accordion-content"><li class="accordion-list" id=""><a href="BaseWebRTC.html#event:reconnect">reconnect</a></li><li class="accordion-list" id=""><a href="PeerConnection.html#event:connectionStateChange">connectionStateChange</a></li><li class="accordion-list" id=""><a href="PeerConnection.html#event:stats">stats</a></li><li class="accordion-list" id=""><a href="PeerConnection.html#event:track">track</a></li><li class="accordion-list" id=""><a href="Publish.html#event:reconnect">reconnect</a></li><li class="accordion-list" id=""><a href="Signaling.html#event:broadcastEvent">broadcastEvent</a></li><li class="accordion-list" id=""><a href="Signaling.html#event:wsConnectionClose">wsConnectionClose</a></li><li class="accordion-list" id=""><a href="Signaling.html#event:wsConnectionError">wsConnectionError</a></li><li class="accordion-list" id=""><a href="Signaling.html#event:wsConnectionSuccess">wsConnectionSuccess</a></li><li class="accordion-list" id=""><a href="View.html#event:reconnect">reconnect</a></li></ul> </div><div class="accordion collapsed" id="3049150" > <h3 class="accordion-heading">Global<svg><use xlink:href="#down-icon"></use></svg></h3><ul class="accordion-content"><li class="accordion-list" id=""><a href="global.html#addCandidateReport">addCandidateReport</a></li><li class="accordion-list" id=""><a href="global.html#addInboundRtpReport">addInboundRtpReport</a></li><li class="accordion-list" id=""><a href="global.html#addOutboundRtpReport">addOutboundRtpReport</a></li><li class="accordion-list" id=""><a href="global.html#addPeerEvents">addPeerEvents</a></li><li class="accordion-list" id=""><a href="global.html#AudioCodec">AudioCodec</a></li><li class="accordion-list" id=""><a href="global.html#calculatePacketsLostDelta">calculatePacketsLostDelta</a></li><li class="accordion-list" id=""><a href="global.html#calculatePacketsLostRatio">calculatePacketsLostRatio</a></li><li class="accordion-list" id=""><a href="global.html#ConnectionStats">ConnectionStats</a></li><li class="accordion-list" id=""><a href="global.html#DirectorPublisherOptions">DirectorPublisherOptions</a></li><li class="accordion-list" id=""><a href="global.html#DirectorSubscriberOptions">DirectorSubscriberOptions</a></li><li class="accordion-list" id=""><a href="global.html#getBaseRtpReportData">getBaseRtpReportData</a></li><li class="accordion-list" id=""><a href="global.html#getCodecData">getCodecData</a></li><li class="accordion-list" id=""><a href="global.html#getMediaType">getMediaType</a></li><li class="accordion-list" id=""><a href="global.html#InboundStats">InboundStats</a></li><li class="accordion-list" id=""><a href="global.html#LayerInfo">LayerInfo</a></li><li class="accordion-list" id=""><a href="global.html#loggerHandler">loggerHandler</a></li><li class="accordion-list" id=""><a href="global.html#LogLevel">LogLevel</a></li><li class="accordion-list" id=""><a href="global.html#onUserCountCallback">onUserCountCallback</a></li><li class="accordion-list" id=""><a href="global.html#OnUserCountOptions">OnUserCountOptions</a></li><li class="accordion-list" id=""><a href="global.html#OutboundStats">OutboundStats</a></li><li class="accordion-list" id=""><a href="global.html#SignalingPublishOptions">SignalingPublishOptions</a></li><li class="accordion-list" id=""><a href="global.html#SignalingSubscribeOptions">SignalingSubscribeOptions</a></li><li class="accordion-list" id=""><a href="global.html#tokenGeneratorCallback">tokenGeneratorCallback</a></li><li class="accordion-list" id=""><a href="global.html#TrackReport">TrackReport</a></li><li class="accordion-list" id=""><a href="global.html#VideoCodec">VideoCodec</a></li><li class="accordion-list" id=""><a href="global.html#WowzaCapability">WowzaCapability</a></li><li class="accordion-list" id=""><a href="global.html#WowzaDirectorResponse">WowzaDirectorResponse</a></li></ul> </div>
</nav>
<div class="navbar-ham" id="navbar-ham">
<div>
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
</div>
</div>
<div id="main" class="main-content">
<h1 id='page-title' class="page-title">
utils/BaseWebRTC.js
</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import EventEmitter from 'events'
import PeerConnection, { webRTCEvents } from '../PeerConnection'
import { signalingEvents } from '../Signaling'
let logger
const maxReconnectionInterval = 32000
const baseInterval = 1000
/**
* @typedef {Object} WowzaDirectorResponse
* @property {Array<String>} urls - WebSocket available URLs.
* @property {String} jwt - Access token for signaling initialization.
* @property {Array<RTCIceServer>} iceServers - Object which represents a list of Ice servers.
*/
/**
* Callback invoke when a new connection path is needed.
*
* @callback tokenGeneratorCallback
* @returns {Promise<WowzaDirectorResponse>} Promise object which represents the result of getting the new connection path.
*
* You can use your own token generator or use the <a href='Director'>Director available methods</a>.
*/
/**
* @class BaseWebRTC
* @extends EventEmitter
* @classdesc Base class for common actions about peer connection and reconnect mechanism for Publishers and Viewer instances.
*
* @constructor
* @param {String} streamName - Wowza existing stream name.
* @param {tokenGeneratorCallback} tokenGenerator - Callback function executed when a new token is needed.
* @param {Object} loggerInstance - Logger instance from the extended classes.
* @param {Boolean} autoReconnect - Enable auto reconnect.
*/
export default class BaseWebRTC extends EventEmitter {
constructor (streamName, tokenGenerator, loggerInstance, autoReconnect) {
super()
logger = loggerInstance
if (!streamName) {
logger.error('Stream Name is required to construct this module.')
throw new Error('Stream Name is required to construct this module.')
}
if (!tokenGenerator) {
logger.error('Token generator is required to construct this module.')
throw new Error('Token generator is required to construct this module.')
}
this.webRTCPeer = new PeerConnection()
this.signaling = null
this.streamName = streamName
this.autoReconnect = autoReconnect
this.reconnectionInterval = baseInterval
this.alreadyDisconnected = false
this.firstReconnection = true
this.stopReconnection = false
this.isReconnecting = false
this.tokenGenerator = tokenGenerator
this.options = null
}
/**
* Get current RTC peer connection.
* @returns {RTCPeerConnection} Object which represents the RTCPeerConnection.
*/
getRTCPeerConnection () {
return this.webRTCPeer ? this.webRTCPeer.getRTCPeer() : null
}
/**
* Stops connection.
*/
stop () {
logger.info('Stopping')
this.webRTCPeer.closeRTCPeer()
this.signaling?.close()
this.signaling = null
this.stopReconnection = true
this.webRTCPeer = new PeerConnection()
}
/**
* Get if the current connection is active.
* @returns {Boolean} - True if connected, false if not.
*/
isActive () {
const rtcPeerState = this.webRTCPeer.getRTCPeerStatus()
logger.info('Broadcast status: ', rtcPeerState || 'not_established')
return rtcPeerState === 'connected'
}
/**
* Sets reconnection if autoReconnect is enabled.
*/
setReconnect () {
this.signaling.on('migrate', () => this.replaceConnection())
if (this.autoReconnect) {
this.signaling.on(signalingEvents.connectionError, () => {
if (this.firstReconnection || !this.alreadyDisconnected) {
this.firstReconnection = false
this.reconnect({ error: new Error('Signaling error: wsConnectionError') })
}
})
this.webRTCPeer.on(webRTCEvents.connectionStateChange, (state) => {
if ((state === 'failed' || (state === 'disconnected' && this.alreadyDisconnected)) && this.firstReconnection) {
this.firstReconnection = false
this.reconnect({ error: new Error('Connection state change: RTCPeerConnectionState disconnected') })
} else if (state === 'disconnected') {
this.alreadyDisconnected = true
setTimeout(() => this.reconnect({ error: new Error('Connection state change: RTCPeerConnectionState disconnected') }), 1500)
} else {
this.alreadyDisconnected = false
}
})
}
}
/**
* Reconnects to last broadcast.
* @fires BaseWebRTC#reconnect
* @param {Object} [data] - This object contains the error property. It may be expanded to contain more information in the future.
* @property {String} error - The value sent in the first [reconnect event]{@link BaseWebRTC#event:reconnect} within the error key of the payload
*/
async reconnect (data) {
try {
logger.info('Attempting to reconnect...')
if (!this.isActive() && !this.stopReconnection && !this.isReconnecting) {
this.stop()
/**
* Emits with every reconnection attempt made when an active stream
* stopped unexpectedly.
*
* @event BaseWebRTC#reconnect
* @type {Object}
* @property {Number} timeout - Next retry interval in milliseconds.
* @property {Error} error - Error object with cause of failure. Possible errors are: <ul> <li> <code>Signaling error: wsConnectionError</code> if there was an error in the Websocket connection. <li> <code>Connection state change: RTCPeerConnectionState disconnected</code> if there was an error in the RTCPeerConnection. <li> <code>Attempting to reconnect</code> if the reconnect was trigered externally. <li> Or any internal error thrown by either <a href="Publish#connect">Publish.connect</a> or <a href="View#connect">View.connect</a> methods</ul>
*/
this.emit('reconnect', { timeout: (nextReconnectInterval(this.reconnectionInterval)), error: data?.error ? data?.error : new Error('Attempting to reconnect') })
this.isReconnecting = true
await this.connect(this.options)
this.alreadyDisconnected = false
this.reconnectionInterval = baseInterval
this.firstReconnection = true
this.isReconnecting = false
}
} catch (error) {
this.isReconnecting = false
this.reconnectionInterval = nextReconnectInterval(this.reconnectionInterval)
logger.error(`Reconnection failed, retrying in ${this.reconnectionInterval}ms. `, error)
setTimeout(() => this.reconnect({ error }), this.reconnectionInterval)
}
}
}
const nextReconnectInterval = (interval) => {
return interval < maxReconnectionInterval ? interval * 2 : interval
}
</code></pre>
</article>
</section>
</div>
<footer class="footer" id="footer">
</footer>
<script src="scripts/third-party/prettify.js"></script>
<script src="scripts/third-party/lang-css.js"></script>
<script type="text/javascript" src="scripts/misc.js"></script>
<script>prettyPrint();</script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/fix-code-block.js"></script>
<script src="scripts/fix-navbar.js"></script>
<script src="scripts/search.js"></script>
<script src="scripts/third-party/fuse.js"></script>
<script>
var list = [{"title":"Director","link":"<a href=\"module-Director.html\">Director</a>"},{"title":"module:Director~getEndpoint","link":"<a href=\"module-Director.html#~getEndpoint\">module:Director~getEndpoint ▸ undefined</a>"},{"title":"module:Director~getLiveDomain","link":"<a href=\"module-Director.html#~getLiveDomain\">module:Director~getLiveDomain ▸ undefined</a>"},{"title":"module:Director~getPublisher","link":"<a href=\"module-Director.html#~getPublisher\">module:Director~getPublisher ▸ undefined</a>"},{"title":"module:Director~getSubscriber","link":"<a href=\"module-Director.html#~getSubscriber\">module:Director~getSubscriber ▸ undefined</a>"},{"title":"module:Director~setEndpoint","link":"<a href=\"module-Director.html#~setEndpoint\">module:Director~setEndpoint ▸ undefined</a>"},{"title":"module:Director~setLiveDomain","link":"<a href=\"module-Director.html#~setLiveDomain\">module:Director~setLiveDomain ▸ undefined</a>"},{"title":"Logger","link":"<a href=\"module-Logger.html\">Logger</a>"},{"title":"module:Logger~get","link":"<a href=\"module-Logger.html#~get\">module:Logger~get ▸ undefined</a>"},{"title":"module:Logger~getHistory","link":"<a href=\"module-Logger.html#~getHistory\">module:Logger~getHistory ▸ undefined</a>"},{"title":"module:Logger~getHistoryMaxSize","link":"<a href=\"module-Logger.html#~getHistoryMaxSize\">module:Logger~getHistoryMaxSize ▸ undefined</a>"},{"title":"module:Logger~getLevel","link":"<a href=\"module-Logger.html#~getLevel\">module:Logger~getLevel ▸ undefined</a>"},{"title":"module:Logger~setHandler","link":"<a href=\"module-Logger.html#~setHandler\">module:Logger~setHandler ▸ undefined</a>"},{"title":"module:Logger~setHistoryMaxSize","link":"<a href=\"module-Logger.html#~setHistoryMaxSize\">module:Logger~setHistoryMaxSize ▸ undefined</a>"},{"title":"module:Logger~setLevel","link":"<a href=\"module-Logger.html#~setLevel\">module:Logger~setLevel ▸ undefined</a>"},{"title":"SdpParser","link":"<a href=\"module-SdpParser.html\">SdpParser</a>"},{"title":"module:SdpParser~adaptCodecName","link":"<a href=\"module-SdpParser.html#~adaptCodecName\">module:SdpParser~adaptCodecName ▸ undefined</a>"},{"title":"module:SdpParser~getAvailableHeaderExtensionIdRange","link":"<a href=\"module-SdpParser.html#~getAvailableHeaderExtensionIdRange\">module:SdpParser~getAvailableHeaderExtensionIdRange ▸ undefined</a>"},{"title":"module:SdpParser~getAvailablePayloadTypeRange","link":"<a href=\"module-SdpParser.html#~getAvailablePayloadTypeRange\">module:SdpParser~getAvailablePayloadTypeRange ▸ undefined</a>"},{"title":"module:SdpParser~removeSdpLine","link":"<a href=\"module-SdpParser.html#~removeSdpLine\">module:SdpParser~removeSdpLine ▸ undefined</a>"},{"title":"module:SdpParser~renegotiate","link":"<a href=\"module-SdpParser.html#~renegotiate\">module:SdpParser~renegotiate ▸ undefined</a>"},{"title":"module:SdpParser~setAbsoluteCaptureTime","link":"<a href=\"module-SdpParser.html#~setAbsoluteCaptureTime\">module:SdpParser~setAbsoluteCaptureTime ▸ undefined</a>"},{"title":"module:SdpParser~setDependencyDescriptor","link":"<a href=\"module-SdpParser.html#~setDependencyDescriptor\">module:SdpParser~setDependencyDescriptor ▸ undefined</a>"},{"title":"module:SdpParser~setDTX","link":"<a href=\"module-SdpParser.html#~setDTX\">module:SdpParser~setDTX ▸ undefined</a>"},{"title":"module:SdpParser~setMultiopus","link":"<a href=\"module-SdpParser.html#~setMultiopus\">module:SdpParser~setMultiopus ▸ undefined</a>"},{"title":"module:SdpParser~setSimulcast","link":"<a href=\"module-SdpParser.html#~setSimulcast\">module:SdpParser~setSimulcast ▸ undefined</a>"},{"title":"module:SdpParser~setStereo","link":"<a href=\"module-SdpParser.html#~setStereo\">module:SdpParser~setStereo ▸ undefined</a>"},{"title":"module:SdpParser~setVideoBitrate","link":"<a href=\"module-SdpParser.html#~setVideoBitrate\">module:SdpParser~setVideoBitrate ▸ undefined</a>"},{"title":"module:SdpParser~updateMissingVideoExtensions","link":"<a href=\"module-SdpParser.html#~updateMissingVideoExtensions\">module:SdpParser~updateMissingVideoExtensions ▸ undefined</a>"},{"title":"BaseWebRTC","link":"<a href=\"BaseWebRTC.html\">BaseWebRTC</a>"},{"title":"BaseWebRTC#getRTCPeerConnection","link":"<a href=\"BaseWebRTC.html#getRTCPeerConnection\">BaseWebRTC ▸ getRTCPeerConnection</a>"},{"title":"BaseWebRTC#isActive","link":"<a href=\"BaseWebRTC.html#isActive\">BaseWebRTC ▸ isActive</a>"},{"title":"BaseWebRTC#reconnect","link":"<a href=\"BaseWebRTC.html#reconnect\">BaseWebRTC ▸ reconnect</a>"},{"title":"BaseWebRTC#setReconnect","link":"<a href=\"BaseWebRTC.html#setReconnect\">BaseWebRTC ▸ setReconnect</a>"},{"title":"BaseWebRTC#stop","link":"<a href=\"BaseWebRTC.html#stop\">BaseWebRTC ▸ stop</a>"},{"title":"PeerConnection","link":"<a href=\"PeerConnection.html\">PeerConnection</a>"},{"title":"PeerConnection.getCapabilities","link":"<a href=\"PeerConnection.html#.getCapabilities\">PeerConnection ▸ getCapabilities</a>"},{"title":"PeerConnection#addRemoteTrack","link":"<a href=\"PeerConnection.html#addRemoteTrack\">PeerConnection ▸ addRemoteTrack</a>"},{"title":"PeerConnection#closeRTCPeer","link":"<a href=\"PeerConnection.html#closeRTCPeer\">PeerConnection ▸ closeRTCPeer</a>"},{"title":"PeerConnection#createRTCPeer","link":"<a href=\"PeerConnection.html#createRTCPeer\">PeerConnection ▸ createRTCPeer</a>"},{"title":"PeerConnection#getRTCLocalSDP","link":"<a href=\"PeerConnection.html#getRTCLocalSDP\">PeerConnection ▸ getRTCLocalSDP</a>"},{"title":"PeerConnection#getRTCPeer","link":"<a href=\"PeerConnection.html#getRTCPeer\">PeerConnection ▸ getRTCPeer</a>"},{"title":"PeerConnection#getRTCPeerStatus","link":"<a href=\"PeerConnection.html#getRTCPeerStatus\">PeerConnection ▸ getRTCPeerStatus</a>"},{"title":"PeerConnection#getTracks","link":"<a href=\"PeerConnection.html#getTracks\">PeerConnection ▸ getTracks</a>"},{"title":"PeerConnection#initStats","link":"<a href=\"PeerConnection.html#initStats\">PeerConnection ▸ initStats</a>"},{"title":"PeerConnection#replaceTrack","link":"<a href=\"PeerConnection.html#replaceTrack\">PeerConnection ▸ replaceTrack</a>"},{"title":"PeerConnection#setRTCRemoteSDP","link":"<a href=\"PeerConnection.html#setRTCRemoteSDP\">PeerConnection ▸ setRTCRemoteSDP</a>"},{"title":"PeerConnection#stopStats","link":"<a href=\"PeerConnection.html#stopStats\">PeerConnection ▸ stopStats</a>"},{"title":"PeerConnection#updateBandwidthRestriction","link":"<a href=\"PeerConnection.html#updateBandwidthRestriction\">PeerConnection ▸ updateBandwidthRestriction</a>"},{"title":"PeerConnection#updateBitrate","link":"<a href=\"PeerConnection.html#updateBitrate\">PeerConnection ▸ updateBitrate</a>"},{"title":"Publish","link":"<a href=\"Publish.html\">Publish</a>"},{"title":"Publish#connect","link":"<a href=\"Publish.html#connect\">Publish ▸ connect</a>"},{"title":"Publish#getRTCPeerConnection","link":"<a href=\"Publish.html#getRTCPeerConnection\">Publish ▸ getRTCPeerConnection</a>"},{"title":"Publish#isActive","link":"<a href=\"Publish.html#isActive\">Publish ▸ isActive</a>"},{"title":"Publish#reconnect","link":"<a href=\"Publish.html#reconnect\">Publish ▸ reconnect</a>"},{"title":"Publish#record","link":"<a href=\"Publish.html#record\">Publish ▸ record</a>"},{"title":"Publish#setReconnect","link":"<a href=\"Publish.html#setReconnect\">Publish ▸ setReconnect</a>"},{"title":"Publish#stop","link":"<a href=\"Publish.html#stop\">Publish ▸ stop</a>"},{"title":"Publish#unrecord","link":"<a href=\"Publish.html#unrecord\">Publish ▸ unrecord</a>"},{"title":"Signaling","link":"<a href=\"Signaling.html\">Signaling</a>"},{"title":"Signaling#close","link":"<a href=\"Signaling.html#close\">Signaling ▸ close</a>"},{"title":"Signaling#cmd","link":"<a href=\"Signaling.html#cmd\">Signaling ▸ cmd</a>"},{"title":"Signaling#connect","link":"<a href=\"Signaling.html#connect\">Signaling ▸ connect</a>"},{"title":"Signaling#publish","link":"<a href=\"Signaling.html#publish\">Signaling ▸ publish</a>"},{"title":"Signaling#subscribe","link":"<a href=\"Signaling.html#subscribe\">Signaling ▸ subscribe</a>"},{"title":"StreamEvents","link":"<a href=\"StreamEvents.html\">StreamEvents</a>"},{"title":"StreamEvents.getEventsLocation","link":"<a href=\"StreamEvents.html#.getEventsLocation\">StreamEvents ▸ getEventsLocation</a>"},{"title":"StreamEvents.init","link":"<a href=\"StreamEvents.html#.init\">StreamEvents ▸ init</a>"},{"title":"StreamEvents.setEventsLocation","link":"<a href=\"StreamEvents.html#.setEventsLocation\">StreamEvents ▸ setEventsLocation</a>"},{"title":"StreamEvents#onUserCount","link":"<a href=\"StreamEvents.html#onUserCount\">StreamEvents ▸ onUserCount</a>"},{"title":"StreamEvents#stop","link":"<a href=\"StreamEvents.html#stop\">StreamEvents ▸ stop</a>"},{"title":"View","link":"<a href=\"View.html\">View</a>"},{"title":"View#addRemoteTrack","link":"<a href=\"View.html#addRemoteTrack\">View ▸ addRemoteTrack</a>"},{"title":"View#connect","link":"<a href=\"View.html#connect\">View ▸ connect</a>"},{"title":"View#getRTCPeerConnection","link":"<a href=\"View.html#getRTCPeerConnection\">View ▸ getRTCPeerConnection</a>"},{"title":"View#isActive","link":"<a href=\"View.html#isActive\">View ▸ isActive</a>"},{"title":"View#project","link":"<a href=\"View.html#project\">View ▸ project</a>"},{"title":"View#reconnect","link":"<a href=\"View.html#reconnect\">View ▸ reconnect</a>"},{"title":"View#select","link":"<a href=\"View.html#select\">View ▸ select</a>"},{"title":"View#setReconnect","link":"<a href=\"View.html#setReconnect\">View ▸ setReconnect</a>"},{"title":"View#stop","link":"<a href=\"View.html#stop\">View ▸ stop</a>"},{"title":"View#unproject","link":"<a href=\"View.html#unproject\">View ▸ unproject</a>"},{"title":"reconnect","link":"<a href=\"BaseWebRTC.html#event:reconnect\">reconnect</a>"},{"title":"connectionStateChange","link":"<a href=\"PeerConnection.html#event:connectionStateChange\">connectionStateChange</a>"},{"title":"stats","link":"<a href=\"PeerConnection.html#event:stats\">stats</a>"},{"title":"track","link":"<a href=\"PeerConnection.html#event:track\">track</a>"},{"title":"reconnect","link":"<a href=\"Publish.html#event:reconnect\">reconnect</a>"},{"title":"broadcastEvent","link":"<a href=\"Signaling.html#event:broadcastEvent\">broadcastEvent</a>"},{"title":"wsConnectionClose","link":"<a href=\"Signaling.html#event:wsConnectionClose\">wsConnectionClose</a>"},{"title":"wsConnectionError","link":"<a href=\"Signaling.html#event:wsConnectionError\">wsConnectionError</a>"},{"title":"wsConnectionSuccess","link":"<a href=\"Signaling.html#event:wsConnectionSuccess\">wsConnectionSuccess</a>"},{"title":"reconnect","link":"<a href=\"View.html#event:reconnect\">reconnect</a>"},{"title":"addCandidateReport","link":"<a href=\"global.html#addCandidateReport\">addCandidateReport</a>"},{"title":"addInboundRtpReport","link":"<a href=\"global.html#addInboundRtpReport\">addInboundRtpReport</a>"},{"title":"addOutboundRtpReport","link":"<a href=\"global.html#addOutboundRtpReport\">addOutboundRtpReport</a>"},{"title":"addPeerEvents","link":"<a href=\"global.html#addPeerEvents\">addPeerEvents</a>"},{"title":"AudioCodec","link":"<a href=\"global.html#AudioCodec\">AudioCodec</a>"},{"title":"calculatePacketsLostDelta","link":"<a href=\"global.html#calculatePacketsLostDelta\">calculatePacketsLostDelta</a>"},{"title":"calculatePacketsLostRatio","link":"<a href=\"global.html#calculatePacketsLostRatio\">calculatePacketsLostRatio</a>"},{"title":"ConnectionStats","link":"<a href=\"global.html#ConnectionStats\">ConnectionStats</a>"},{"title":"DirectorPublisherOptions","link":"<a href=\"global.html#DirectorPublisherOptions\">DirectorPublisherOptions</a>"},{"title":"DirectorSubscriberOptions","link":"<a href=\"global.html#DirectorSubscriberOptions\">DirectorSubscriberOptions</a>"},{"title":"getBaseRtpReportData","link":"<a href=\"global.html#getBaseRtpReportData\">getBaseRtpReportData</a>"},{"title":"getCodecData","link":"<a href=\"global.html#getCodecData\">getCodecData</a>"},{"title":"getMediaType","link":"<a href=\"global.html#getMediaType\">getMediaType</a>"},{"title":"InboundStats","link":"<a href=\"global.html#InboundStats\">InboundStats</a>"},{"title":"LayerInfo","link":"<a href=\"global.html#LayerInfo\">LayerInfo</a>"},{"title":"loggerHandler","link":"<a href=\"global.html#loggerHandler\">loggerHandler</a>"},{"title":"LogLevel","link":"<a href=\"global.html#LogLevel\">LogLevel</a>"},{"title":"onUserCountCallback","link":"<a href=\"global.html#onUserCountCallback\">onUserCountCallback</a>"},{"title":"OnUserCountOptions","link":"<a href=\"global.html#OnUserCountOptions\">OnUserCountOptions</a>"},{"title":"OutboundStats","link":"<a href=\"global.html#OutboundStats\">OutboundStats</a>"},{"title":"SignalingPublishOptions","link":"<a href=\"global.html#SignalingPublishOptions\">SignalingPublishOptions</a>"},{"title":"SignalingSubscribeOptions","link":"<a href=\"global.html#SignalingSubscribeOptions\">SignalingSubscribeOptions</a>"},{"title":"tokenGeneratorCallback","link":"<a href=\"global.html#tokenGeneratorCallback\">tokenGeneratorCallback</a>"},{"title":"TrackReport","link":"<a href=\"global.html#TrackReport\">TrackReport</a>"},{"title":"VideoCodec","link":"<a href=\"global.html#VideoCodec\">VideoCodec</a>"},{"title":"WowzaCapability","link":"<a href=\"global.html#WowzaCapability\">WowzaCapability</a>"},{"title":"WowzaDirectorResponse","link":"<a href=\"global.html#WowzaDirectorResponse\">WowzaDirectorResponse</a>"}];
var options =
setupSearch(list, options)
</script>
</body>
</html>