ccdeck 3.53.3 → 3.80.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 (58) hide show
  1. package/README.md +55 -3
  2. package/THIRD_PARTY_NOTICES.md +31 -1
  3. package/dist/web/assets/{BrowserWatchModal-CJ0CW4Go.js → BrowserWatchModal-Bfvo_8H6.js} +1 -1
  4. package/dist/web/assets/{IntegrationModal-DlJzBN8b.js → IntegrationModal-GS5jIQ_J.js} +1 -1
  5. package/dist/web/assets/{RadioPanel-CHl3s3OH.js → RadioPanel-Bxd2ElWb.js} +1 -1
  6. package/dist/web/assets/{TrafficRadar-Cw3i0Hux.js → TrafficRadar-FgHBI2Oh.js} +1 -1
  7. package/dist/web/assets/{UsageHistoryModal-CiB5-CTH.js → UsageHistoryModal-APwKtE2J.js} +1 -1
  8. package/dist/web/assets/{app-2vj7uk2U.js → app-BzHVsgB2.js} +69 -69
  9. package/dist/web/assets/{index-D1YZbdq3.js → index-7whwMaPX.js} +1 -1
  10. package/dist/web/index.html +2 -2
  11. package/node_modules/ws/LICENSE +20 -0
  12. package/node_modules/ws/README.md +540 -0
  13. package/node_modules/ws/browser.js +8 -0
  14. package/node_modules/ws/index.js +22 -0
  15. package/node_modules/ws/lib/buffer-util.js +142 -0
  16. package/node_modules/ws/lib/constants.js +19 -0
  17. package/node_modules/ws/lib/event-target.js +292 -0
  18. package/node_modules/ws/lib/extension.js +203 -0
  19. package/node_modules/ws/lib/limiter.js +55 -0
  20. package/node_modules/ws/lib/permessage-deflate.js +530 -0
  21. package/node_modules/ws/lib/receiver.js +743 -0
  22. package/node_modules/ws/lib/sender.js +610 -0
  23. package/node_modules/ws/lib/stream.js +161 -0
  24. package/node_modules/ws/lib/subprotocol.js +62 -0
  25. package/node_modules/ws/lib/validation.js +152 -0
  26. package/node_modules/ws/lib/websocket-server.js +562 -0
  27. package/node_modules/ws/lib/websocket.js +1426 -0
  28. package/node_modules/ws/package.json +74 -0
  29. package/node_modules/ws/wrapper.mjs +21 -0
  30. package/package.json +5 -3
  31. package/release-notes.json +37 -0
  32. package/src/server/account-engine.mjs +87 -0
  33. package/src/server/account-routes.mjs +31 -3
  34. package/src/server/codex-auto.mjs +7 -18
  35. package/src/server/codex-engine-adapter.mjs +272 -0
  36. package/src/server/codex-engine-bridge.mjs +47 -0
  37. package/src/server/codex-engine-config.mjs +42 -0
  38. package/src/server/codex-engine-rpc.mjs +88 -0
  39. package/src/server/codex-handoff.mjs +20 -0
  40. package/src/server/codex-interactive-engine.mjs +335 -0
  41. package/src/server/codex-live-checkpoint.mjs +55 -0
  42. package/src/server/codex-live-credentials.mjs +214 -0
  43. package/src/server/codex-live-engine.mjs +577 -0
  44. package/src/server/codex-live-handoff.mjs +300 -0
  45. package/src/server/codex-live-lease.mjs +64 -0
  46. package/src/server/codex-live-rpc.mjs +155 -0
  47. package/src/server/codex-quota.mjs +36 -2
  48. package/src/server/codex-selection.mjs +62 -8
  49. package/src/server/codex-share.mjs +193 -0
  50. package/src/server/codex-terminal-runner.mjs +38 -1
  51. package/src/server/codex-terminal.mjs +15 -3
  52. package/src/server/codex-watch.mjs +3 -1
  53. package/src/server/codex-windows-private.mjs +96 -0
  54. package/src/server/codex-windows-private.ps1 +140 -0
  55. package/src/server/codex-windows-proxy.mjs +53 -0
  56. package/src/server/index.mjs +7 -1
  57. package/src/server/login-service.mjs +2 -0
  58. package/src/server/pinned-build.mjs +2 -0
@@ -1 +1 @@
1
- import"./app-2vj7uk2U.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))i(e);new MutationObserver(e=>{for(const r of e)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function s(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerPolicy&&(r.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?r.credentials="include":e.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(e){if(e.ep)return;e.ep=!0;const r=s(e);fetch(e.href,r)}})();
1
+ import"./app-BzHVsgB2.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))i(e);new MutationObserver(e=>{for(const r of e)if(r.type==="childList")for(const o of r.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&i(o)}).observe(document,{childList:!0,subtree:!0});function s(e){const r={};return e.integrity&&(r.integrity=e.integrity),e.referrerPolicy&&(r.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?r.credentials="include":e.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function i(e){if(e.ep)return;e.ep=!0;const r=s(e);fetch(e.href,r)}})();
@@ -77,8 +77,8 @@
77
77
  document.documentElement.setAttribute("data-density", density === "tightest" || density === "tighter" || density === "compact" || density === "comfortable" ? density : "default");
78
78
  })();
79
79
  </script>
80
- <script type="module" crossorigin src="/assets/index-D1YZbdq3.js"></script>
81
- <link rel="modulepreload" crossorigin href="/assets/app-2vj7uk2U.js">
80
+ <script type="module" crossorigin src="/assets/index-7whwMaPX.js"></script>
81
+ <link rel="modulepreload" crossorigin href="/assets/app-BzHVsgB2.js">
82
82
  <link rel="stylesheet" crossorigin href="/assets/app-xTrs4aEH.css">
83
83
  </head>
84
84
  <body>
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Einar Otto Stangvik <einaros@gmail.com>
2
+ Copyright (c) 2013 Arnout Kazemier and contributors
3
+ Copyright (c) 2016 Luigi Pinca and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,540 @@
1
+ # ws: a Node.js WebSocket library
2
+
3
+ [![Version npm](https://img.shields.io/npm/v/ws.svg?logo=npm)](https://www.npmjs.com/package/ws)
4
+ [![CI](https://img.shields.io/github/actions/workflow/status/websockets/ws/ci.yml?branch=master&label=CI&logo=github)](https://github.com/websockets/ws/actions?query=workflow%3ACI+branch%3Amaster)
5
+ [![Coverage Status](https://img.shields.io/coveralls/websockets/ws/master.svg?logo=coveralls)](https://coveralls.io/github/websockets/ws)
6
+
7
+ ws is a simple to use, blazing fast, and thoroughly tested WebSocket client and
8
+ server implementation.
9
+
10
+ Passes the quite extensive Autobahn test suite: [server][server-report],
11
+ [client][client-report].
12
+
13
+ **Note**: This module does not work in the browser. The client in the docs is a
14
+ reference to a backend with the role of a client in the WebSocket communication.
15
+ Browser clients must use the native
16
+ [`WebSocket`](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
17
+ object. To make the same code work seamlessly on Node.js and the browser, you
18
+ can use one of the many wrappers available on npm, like
19
+ [isomorphic-ws](https://github.com/heineiuo/isomorphic-ws).
20
+
21
+ ## Table of Contents
22
+
23
+ - [Protocol support](#protocol-support)
24
+ - [Installing](#installing)
25
+ - [Opt-in for performance](#opt-in-for-performance)
26
+ - [Legacy opt-in for performance](#legacy-opt-in-for-performance)
27
+ - [API docs](#api-docs)
28
+ - [WebSocket compression](#websocket-compression)
29
+ - [Usage examples](#usage-examples)
30
+ - [Sending and receiving text data](#sending-and-receiving-text-data)
31
+ - [Sending binary data](#sending-binary-data)
32
+ - [Simple server](#simple-server)
33
+ - [External HTTP/S server](#external-https-server)
34
+ - [Multiple servers sharing a single HTTP/S server](#multiple-servers-sharing-a-single-https-server)
35
+ - [Client authentication](#client-authentication)
36
+ - [Server broadcast](#server-broadcast)
37
+ - [Round-trip time](#round-trip-time)
38
+ - [Use the Node.js streams API](#use-the-nodejs-streams-api)
39
+ - [Other examples](#other-examples)
40
+ - [FAQ](#faq)
41
+ - [How to get the IP address of the client?](#how-to-get-the-ip-address-of-the-client)
42
+ - [How to detect and close broken connections?](#how-to-detect-and-close-broken-connections)
43
+ - [How to connect via a proxy?](#how-to-connect-via-a-proxy)
44
+ - [Changelog](#changelog)
45
+ - [License](#license)
46
+
47
+ ## Protocol support
48
+
49
+ - **HyBi drafts 07-12** (Use the option `protocolVersion: 8`)
50
+ - **HyBi drafts 13-17** (Current default, alternatively option
51
+ `protocolVersion: 13`)
52
+
53
+ ## Installing
54
+
55
+ ```
56
+ npm install ws
57
+ ```
58
+
59
+ ### Legacy opt-in for performance
60
+
61
+ On older Node.js versions, ws can leverage optional binary modules to optimize
62
+ performance.
63
+
64
+ - `npm install --save-optional bufferutil`: Provides binary polyfills for
65
+ [`http.websocketMask()`][] and [`http.websocketUnmask()`][].
66
+ - `npm install --save-optional utf-8-validate`: Provides a binary polyfill for
67
+ [`buffer.isUtf8()`][].
68
+
69
+ On newer Node.js versions (v27.0.0-alpha.0.0.0 or later for bufferutil, and
70
+ v18.14.0 or later for utf-8-validate) that feature built-in alternatives, these
71
+ modules are not loaded even if installed.
72
+
73
+ To force ws not to use [bufferutil][] or [utf-8-validate][] on the older Node.js
74
+ versions where they would otherwise be loaded, set the
75
+ [`WS_NO_BUFFER_UTIL`](./doc/ws.md#ws_no_buffer_util) and
76
+ [`WS_NO_UTF_8_VALIDATE`](./doc/ws.md#ws_no_utf_8_validate) environment
77
+ variables. This can be useful to enhance security in systems where a user can
78
+ put a package in the package search path of an application of another user, due
79
+ to how the Node.js resolver algorithm works.
80
+
81
+ ## API docs
82
+
83
+ See [`/doc/ws.md`](./doc/ws.md) for Node.js-like documentation of ws classes and
84
+ utility functions.
85
+
86
+ ## WebSocket compression
87
+
88
+ ws supports the [permessage-deflate extension][permessage-deflate] which enables
89
+ the client and server to negotiate a compression algorithm and its parameters,
90
+ and then selectively apply it to the data payloads of each WebSocket message.
91
+
92
+ The extension is disabled by default on the server and enabled by default on the
93
+ client. It adds a significant overhead in terms of performance and memory
94
+ consumption so we suggest to enable it only if it is really needed.
95
+
96
+ Note that Node.js has a variety of issues with high-performance compression,
97
+ where increased concurrency, especially on Linux, can lead to [catastrophic
98
+ memory fragmentation][node-zlib-bug] and slow performance. If you intend to use
99
+ permessage-deflate in production, it is worthwhile to set up a test
100
+ representative of your workload and ensure Node.js/zlib will handle it with
101
+ acceptable performance and memory usage.
102
+
103
+ Tuning of permessage-deflate can be done via the options defined below. You can
104
+ also use `zlibDeflateOptions` and `zlibInflateOptions`, which is passed directly
105
+ into the creation of [raw deflate/inflate streams][node-zlib-deflaterawdocs].
106
+
107
+ See [the docs][ws-server-options] for more options.
108
+
109
+ ```js
110
+ import WebSocket, { WebSocketServer } from 'ws';
111
+
112
+ const wss = new WebSocketServer({
113
+ port: 8080,
114
+ perMessageDeflate: {
115
+ zlibDeflateOptions: {
116
+ // See zlib defaults.
117
+ chunkSize: 1024,
118
+ memLevel: 7,
119
+ level: 3
120
+ },
121
+ zlibInflateOptions: {
122
+ chunkSize: 10 * 1024
123
+ },
124
+ // Other options settable:
125
+ clientNoContextTakeover: true, // Defaults to negotiated value.
126
+ serverNoContextTakeover: true, // Defaults to negotiated value.
127
+ serverMaxWindowBits: 10, // Defaults to negotiated value.
128
+ // Below options specified as default values.
129
+ concurrencyLimit: 10, // Limits zlib concurrency for perf.
130
+ threshold: 1024 // Size (in bytes) below which messages
131
+ // should not be compressed if context takeover is disabled.
132
+ }
133
+ });
134
+ ```
135
+
136
+ The client will only use the extension if it is supported and enabled on the
137
+ server. To always disable the extension on the client, set the
138
+ `perMessageDeflate` option to `false`.
139
+
140
+ ```js
141
+ import WebSocket from 'ws';
142
+
143
+ const ws = new WebSocket('ws://www.host.com/path', {
144
+ perMessageDeflate: false
145
+ });
146
+ ```
147
+
148
+ ## Usage examples
149
+
150
+ ### Sending and receiving text data
151
+
152
+ ```js
153
+ import WebSocket from 'ws';
154
+
155
+ const ws = new WebSocket('ws://www.host.com/path');
156
+
157
+ ws.on('error', console.error);
158
+
159
+ ws.on('open', function open() {
160
+ ws.send('something');
161
+ });
162
+
163
+ ws.on('message', function message(data) {
164
+ console.log('received: %s', data);
165
+ });
166
+ ```
167
+
168
+ ### Sending binary data
169
+
170
+ ```js
171
+ import WebSocket from 'ws';
172
+
173
+ const ws = new WebSocket('ws://www.host.com/path');
174
+
175
+ ws.on('error', console.error);
176
+
177
+ ws.on('open', function open() {
178
+ const array = new Float32Array(5);
179
+
180
+ for (var i = 0; i < array.length; ++i) {
181
+ array[i] = i / 2;
182
+ }
183
+
184
+ ws.send(array);
185
+ });
186
+ ```
187
+
188
+ ### Simple server
189
+
190
+ ```js
191
+ import { WebSocketServer } from 'ws';
192
+
193
+ const wss = new WebSocketServer({ port: 8080 });
194
+
195
+ wss.on('connection', function connection(ws) {
196
+ ws.on('error', console.error);
197
+
198
+ ws.on('message', function message(data) {
199
+ console.log('received: %s', data);
200
+ });
201
+
202
+ ws.send('something');
203
+ });
204
+ ```
205
+
206
+ ### External HTTP/S server
207
+
208
+ ```js
209
+ import { createServer } from 'https';
210
+ import { readFileSync } from 'fs';
211
+ import { WebSocketServer } from 'ws';
212
+
213
+ const server = createServer({
214
+ cert: readFileSync('/path/to/cert.pem'),
215
+ key: readFileSync('/path/to/key.pem')
216
+ });
217
+ const wss = new WebSocketServer({ server });
218
+
219
+ wss.on('connection', function connection(ws) {
220
+ ws.on('error', console.error);
221
+
222
+ ws.on('message', function message(data) {
223
+ console.log('received: %s', data);
224
+ });
225
+
226
+ ws.send('something');
227
+ });
228
+
229
+ server.listen(8080);
230
+ ```
231
+
232
+ ### Multiple servers sharing a single HTTP/S server
233
+
234
+ ```js
235
+ import { createServer } from 'http';
236
+ import { WebSocketServer } from 'ws';
237
+
238
+ const server = createServer();
239
+ const wss1 = new WebSocketServer({ noServer: true });
240
+ const wss2 = new WebSocketServer({ noServer: true });
241
+
242
+ wss1.on('connection', function connection(ws) {
243
+ ws.on('error', console.error);
244
+
245
+ // ...
246
+ });
247
+
248
+ wss2.on('connection', function connection(ws) {
249
+ ws.on('error', console.error);
250
+
251
+ // ...
252
+ });
253
+
254
+ server.on('upgrade', function upgrade(request, socket, head) {
255
+ const { pathname } = new URL(request.url, 'wss://base.url');
256
+
257
+ if (pathname === '/foo') {
258
+ wss1.handleUpgrade(request, socket, head, function done(ws) {
259
+ wss1.emit('connection', ws, request);
260
+ });
261
+ } else if (pathname === '/bar') {
262
+ wss2.handleUpgrade(request, socket, head, function done(ws) {
263
+ wss2.emit('connection', ws, request);
264
+ });
265
+ } else {
266
+ socket.destroy();
267
+ }
268
+ });
269
+
270
+ server.listen(8080);
271
+ ```
272
+
273
+ ### Client authentication
274
+
275
+ ```js
276
+ import { createServer } from 'http';
277
+ import { WebSocketServer } from 'ws';
278
+
279
+ function onSocketError(err) {
280
+ console.error(err);
281
+ }
282
+
283
+ const server = createServer();
284
+ const wss = new WebSocketServer({ noServer: true });
285
+
286
+ wss.on('connection', function connection(ws, request, client) {
287
+ ws.on('error', console.error);
288
+
289
+ ws.on('message', function message(data) {
290
+ console.log(`Received message ${data} from user ${client}`);
291
+ });
292
+ });
293
+
294
+ server.on('upgrade', function upgrade(request, socket, head) {
295
+ socket.on('error', onSocketError);
296
+
297
+ // This function is not defined on purpose. Implement it with your own logic.
298
+ authenticate(request, function next(err, client) {
299
+ if (err || !client) {
300
+ socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
301
+ socket.destroy();
302
+ return;
303
+ }
304
+
305
+ socket.removeListener('error', onSocketError);
306
+
307
+ wss.handleUpgrade(request, socket, head, function done(ws) {
308
+ wss.emit('connection', ws, request, client);
309
+ });
310
+ });
311
+ });
312
+
313
+ server.listen(8080);
314
+ ```
315
+
316
+ Also see the provided [example][session-parse-example] using `express-session`.
317
+
318
+ ### Server broadcast
319
+
320
+ A client WebSocket broadcasting to all connected WebSocket clients, including
321
+ itself.
322
+
323
+ ```js
324
+ import WebSocket, { WebSocketServer } from 'ws';
325
+
326
+ const wss = new WebSocketServer({ port: 8080 });
327
+
328
+ wss.on('connection', function connection(ws) {
329
+ ws.on('error', console.error);
330
+
331
+ ws.on('message', function message(data, isBinary) {
332
+ wss.clients.forEach(function each(client) {
333
+ if (client.readyState === WebSocket.OPEN) {
334
+ client.send(data, { binary: isBinary });
335
+ }
336
+ });
337
+ });
338
+ });
339
+ ```
340
+
341
+ A client WebSocket broadcasting to every other connected WebSocket clients,
342
+ excluding itself.
343
+
344
+ ```js
345
+ import WebSocket, { WebSocketServer } from 'ws';
346
+
347
+ const wss = new WebSocketServer({ port: 8080 });
348
+
349
+ wss.on('connection', function connection(ws) {
350
+ ws.on('error', console.error);
351
+
352
+ ws.on('message', function message(data, isBinary) {
353
+ wss.clients.forEach(function each(client) {
354
+ if (client !== ws && client.readyState === WebSocket.OPEN) {
355
+ client.send(data, { binary: isBinary });
356
+ }
357
+ });
358
+ });
359
+ });
360
+ ```
361
+
362
+ ### Round-trip time
363
+
364
+ ```js
365
+ import WebSocket from 'ws';
366
+
367
+ const ws = new WebSocket('wss://websocket-echo.com/');
368
+
369
+ ws.on('error', console.error);
370
+
371
+ ws.on('open', function open() {
372
+ console.log('connected');
373
+ ws.send(Date.now());
374
+ });
375
+
376
+ ws.on('close', function close() {
377
+ console.log('disconnected');
378
+ });
379
+
380
+ ws.on('message', function message(data) {
381
+ console.log(`Round-trip time: ${Date.now() - data} ms`);
382
+
383
+ setTimeout(function timeout() {
384
+ ws.send(Date.now());
385
+ }, 500);
386
+ });
387
+ ```
388
+
389
+ ### Use the Node.js streams API
390
+
391
+ ```js
392
+ import WebSocket, { createWebSocketStream } from 'ws';
393
+
394
+ const ws = new WebSocket('wss://websocket-echo.com/');
395
+
396
+ const duplex = createWebSocketStream(ws, { encoding: 'utf8' });
397
+
398
+ duplex.on('error', console.error);
399
+
400
+ duplex.pipe(process.stdout);
401
+ process.stdin.pipe(duplex);
402
+ ```
403
+
404
+ ### Other examples
405
+
406
+ For a full example with a browser client communicating with a ws server, see the
407
+ examples folder.
408
+
409
+ Otherwise, see the test cases.
410
+
411
+ ## FAQ
412
+
413
+ ### How to get the IP address of the client?
414
+
415
+ The remote IP address can be obtained from the raw socket.
416
+
417
+ ```js
418
+ import { WebSocketServer } from 'ws';
419
+
420
+ const wss = new WebSocketServer({ port: 8080 });
421
+
422
+ wss.on('connection', function connection(ws, req) {
423
+ const ip = req.socket.remoteAddress;
424
+
425
+ ws.on('error', console.error);
426
+ });
427
+ ```
428
+
429
+ When the server runs behind a proxy like NGINX, the de-facto standard is to use
430
+ the `X-Forwarded-For` header.
431
+
432
+ ```js
433
+ wss.on('connection', function connection(ws, req) {
434
+ const ip = req.headers['x-forwarded-for'].split(',')[0].trim();
435
+
436
+ ws.on('error', console.error);
437
+ });
438
+ ```
439
+
440
+ ### How to detect and close broken connections?
441
+
442
+ Sometimes, the link between the server and the client can be interrupted in a
443
+ way that keeps both the server and the client unaware of the broken state of the
444
+ connection (e.g. when pulling the cord).
445
+
446
+ In these cases, ping messages can be used as a means to verify that the remote
447
+ endpoint is still responsive.
448
+
449
+ ```js
450
+ import { WebSocketServer } from 'ws';
451
+
452
+ function heartbeat() {
453
+ this.isAlive = true;
454
+ }
455
+
456
+ const wss = new WebSocketServer({ port: 8080 });
457
+
458
+ wss.on('connection', function connection(ws) {
459
+ ws.isAlive = true;
460
+ ws.on('error', console.error);
461
+ ws.on('pong', heartbeat);
462
+ });
463
+
464
+ const interval = setInterval(function ping() {
465
+ wss.clients.forEach(function each(ws) {
466
+ if (ws.isAlive === false) return ws.terminate();
467
+
468
+ ws.isAlive = false;
469
+ ws.ping();
470
+ });
471
+ }, 30000);
472
+
473
+ wss.on('close', function close() {
474
+ clearInterval(interval);
475
+ });
476
+ ```
477
+
478
+ Pong messages are automatically sent in response to ping messages as required by
479
+ the spec.
480
+
481
+ Just like the server example above, your clients might as well lose connection
482
+ without knowing it. You might want to add a ping listener on your clients to
483
+ prevent that. A simple implementation would be:
484
+
485
+ ```js
486
+ import WebSocket from 'ws';
487
+
488
+ function heartbeat() {
489
+ clearTimeout(this.pingTimeout);
490
+
491
+ // Use `WebSocket#terminate()`, which immediately destroys the connection,
492
+ // instead of `WebSocket#close()`, which waits for the close timer.
493
+ // Delay should be equal to the interval at which your server
494
+ // sends out pings plus a conservative assumption of the latency.
495
+ this.pingTimeout = setTimeout(() => {
496
+ this.terminate();
497
+ }, 30000 + 1000);
498
+ }
499
+
500
+ const client = new WebSocket('wss://websocket-echo.com/');
501
+
502
+ client.on('error', console.error);
503
+ client.on('open', heartbeat);
504
+ client.on('ping', heartbeat);
505
+ client.on('close', function clear() {
506
+ clearTimeout(this.pingTimeout);
507
+ });
508
+ ```
509
+
510
+ ### How to connect via a proxy?
511
+
512
+ Use a custom `http.Agent` implementation like [https-proxy-agent][] or
513
+ [socks-proxy-agent][].
514
+
515
+ ## Changelog
516
+
517
+ We're using the GitHub [releases][changelog] for changelog entries.
518
+
519
+ ## License
520
+
521
+ [MIT](LICENSE)
522
+
523
+ [`buffer.isutf8()`]: https://nodejs.org/api/buffer.html#bufferisutf8input
524
+ [`http.websocketMask()`]:
525
+ https://nodejs.org/api/http.html#httpwebsocketmasksource-mask-output-offset-length
526
+ [`http.websocketUnmask()`]:
527
+ https://nodejs.org/api/http.html#httpwebsocketunmaskbuffer-mask
528
+ [bufferutil]: https://github.com/websockets/bufferutil
529
+ [changelog]: https://github.com/websockets/ws/releases
530
+ [client-report]: http://websockets.github.io/ws/autobahn/clients/
531
+ [https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
532
+ [node-zlib-bug]: https://github.com/nodejs/node/issues/8871
533
+ [node-zlib-deflaterawdocs]:
534
+ https://nodejs.org/api/zlib.html#zlib_zlib_createdeflateraw_options
535
+ [permessage-deflate]: https://tools.ietf.org/html/rfc7692
536
+ [server-report]: http://websockets.github.io/ws/autobahn/servers/
537
+ [session-parse-example]: ./examples/express-session-parse
538
+ [socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
539
+ [utf-8-validate]: https://github.com/websockets/utf-8-validate
540
+ [ws-server-options]: ./doc/ws.md#new-websocketserveroptions-callback
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ module.exports = function () {
4
+ throw new Error(
5
+ 'ws does not work in the browser. Browser clients must use the native ' +
6
+ 'WebSocket object'
7
+ );
8
+ };
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const createWebSocketStream = require('./lib/stream');
4
+ const extension = require('./lib/extension');
5
+ const PerMessageDeflate = require('./lib/permessage-deflate');
6
+ const Receiver = require('./lib/receiver');
7
+ const Sender = require('./lib/sender');
8
+ const subprotocol = require('./lib/subprotocol');
9
+ const WebSocket = require('./lib/websocket');
10
+ const WebSocketServer = require('./lib/websocket-server');
11
+
12
+ WebSocket.createWebSocketStream = createWebSocketStream;
13
+ WebSocket.extension = extension;
14
+ WebSocket.PerMessageDeflate = PerMessageDeflate;
15
+ WebSocket.Receiver = Receiver;
16
+ WebSocket.Sender = Sender;
17
+ WebSocket.Server = WebSocketServer;
18
+ WebSocket.subprotocol = subprotocol;
19
+ WebSocket.WebSocket = WebSocket;
20
+ WebSocket.WebSocketServer = WebSocketServer;
21
+
22
+ module.exports = WebSocket;