MCPcopy
hub / github.com/cortesi/devd / DevdReconnectingWebSocket

Function DevdReconnectingWebSocket

livereload/static/client.js:6–246  ·  view source on GitHub ↗
(url, protocols, options)

Source from the content-addressed store, hash-verified

4 }
5
6 function DevdReconnectingWebSocket(url, protocols, options) {
7
8 // Default settings
9 var settings = {
10
11 /** Whether this instance should log debug messages. */
12 debug: false,
13
14 /** Whether or not the websocket should attempt to connect immediately upon instantiation. */
15 automaticOpen: true,
16
17 /** The number of milliseconds to delay before attempting to reconnect. */
18 reconnectInterval: 1000,
19 /** The maximum number of milliseconds to delay a reconnection attempt. */
20 maxReconnectInterval: 30000,
21 /** The rate of increase of the reconnect delay. Allows reconnect attempts to back off when problems persist. */
22 reconnectDecay: 1.5,
23
24 /** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
25 timeoutInterval: 2000,
26
27 /** The maximum number of reconnection attempts to make. Unlimited if null. */
28 maxReconnectAttempts: null,
29
30 /** The binary type, possible values 'blob' or 'arraybuffer', default 'blob'. */
31 binaryType: 'blob'
32 }
33 if (!options) {
34 options = {};
35 }
36
37 // Overwrite and define settings with options if they exist.
38 for (var key in settings) {
39 if (typeof options[key] !== 'undefined') {
40 this[key] = options[key];
41 } else {
42 this[key] = settings[key];
43 }
44 }
45
46 // These should be treated as read-only properties
47
48 /** The URL as resolved by the constructor. This is always an absolute URL. Read only. */
49 this.url = url;
50
51 /** The number of attempted reconnects since starting, or the last successful connection. Read only. */
52 this.reconnectAttempts = 0;
53
54 /**
55 * The current state of the connection.
56 * Can be one of: WebSocket.CONNECTING, WebSocket.OPEN, WebSocket.CLOSING, WebSocket.CLOSED
57 * Read only.
58 */
59 this.readyState = WebSocket.CONNECTING;
60
61 /**
62 * A string indicating the name of the sub-protocol the server selected; this will be one of
63 * the strings specified in the protocols parameter when creating the WebSocket object.

Callers

nothing calls this directly

Calls 1

generateEventFunction · 0.85

Tested by

no test coverage detected