MCPcopy Index your code
hub / github.com/websockets/ws / constructor

Method constructor

lib/websocket.js:54–94  ·  view source on GitHub ↗

* Create a new `WebSocket`. * * @param {(String|URL)} address The URL to which to connect * @param {(String|String[])} [protocols] The subprotocols * @param {Object} [options] Connection options

(address, protocols, options)

Source from the content-addressed store, hash-verified

52 * @param {Object} [options] Connection options
53 */
54 constructor(address, protocols, options) {
55 super();
56
57 this._binaryType = BINARY_TYPES[0];
58 this._closeCode = 1006;
59 this._closeFrameReceived = false;
60 this._closeFrameSent = false;
61 this._closeMessage = EMPTY_BUFFER;
62 this._closeTimer = null;
63 this._errorEmitted = false;
64 this._extensions = {};
65 this._paused = false;
66 this._protocol = '';
67 this._readyState = WebSocket.CONNECTING;
68 this._receiver = null;
69 this._sender = null;
70 this._socket = null;
71
72 if (address !== null) {
73 this._bufferedAmount = 0;
74 this._isServer = false;
75 this._redirects = 0;
76
77 if (protocols === undefined) {
78 protocols = [];
79 } else if (!Array.isArray(protocols)) {
80 if (typeof protocols === 'object' && protocols !== null) {
81 options = protocols;
82 protocols = [];
83 } else {
84 protocols = [protocols];
85 }
86 }
87
88 initAsClient(this, address, protocols, options);
89 } else {
90 this._autoPong = options.autoPong;
91 this._closeTimeout = options.closeTimeout;
92 this._isServer = true;
93 }
94 }
95
96 /**
97 * For historical reasons, the custom "nodebuffer" type is used by the default

Callers

nothing calls this directly

Calls 1

initAsClientFunction · 0.85

Tested by

no test coverage detected