Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/ws/README.md

    r59329aa re29cc2e  
    22
    33[![Version npm](https://img.shields.io/npm/v/ws.svg?logo=npm)](https://www.npmjs.com/package/ws)
    4 [![Build](https://img.shields.io/github/workflow/status/websockets/ws/CI/master?label=build&logo=github)](https://github.com/websockets/ws/actions?query=workflow%3ACI+branch%3Amaster)
    5 [![Windows x86 Build](https://img.shields.io/appveyor/ci/lpinca/ws/master.svg?logo=appveyor)](https://ci.appveyor.com/project/lpinca/ws)
     4[![Linux Build](https://img.shields.io/travis/websockets/ws/master.svg?logo=travis)](https://travis-ci.org/websockets/ws)
     5[![Windows Build](https://img.shields.io/appveyor/ci/lpinca/ws/master.svg?logo=appveyor)](https://ci.appveyor.com/project/lpinca/ws)
    66[![Coverage Status](https://img.shields.io/coveralls/websockets/ws/master.svg)](https://coveralls.io/github/websockets/ws)
    77
     
    3333  - [External HTTP/S server](#external-https-server)
    3434  - [Multiple servers sharing a single HTTP/S server](#multiple-servers-sharing-a-single-https-server)
    35   - [Client authentication](#client-authentication)
    3635  - [Server broadcast](#server-broadcast)
    3736  - [echo.websocket.org demo](#echowebsocketorg-demo)
    38   - [Use the Node.js streams API](#use-the-nodejs-streams-api)
    3937  - [Other examples](#other-examples)
     38- [Error handling best practices](#error-handling-best-practices)
    4039- [FAQ](#faq)
    4140  - [How to get the IP address of the client?](#how-to-get-the-ip-address-of-the-client)
     
    5756```
    5857
    59 ### Opt-in for performance
     58### Opt-in for performance and spec compliance
    6059
    6160There are 2 optional modules that can be installed along side with the ws
     
    6867  frames.
    6968- `npm install --save-optional utf-8-validate`: Allows to efficiently check if a
    70   message contains valid UTF-8.
     69  message contains valid UTF-8 as required by the spec.
    7170
    7271## API docs
    7372
    74 See [`/doc/ws.md`](./doc/ws.md) for Node.js-like documentation of ws classes and
    75 utility functions.
     73See [`/doc/ws.md`](./doc/ws.md) for Node.js-like docs for the ws classes.
    7674
    7775## WebSocket compression
     
    196194const WebSocket = require('ws');
    197195
    198 const server = https.createServer({
     196const server = new https.createServer({
    199197  cert: fs.readFileSync('/path/to/cert.pem'),
    200198  key: fs.readFileSync('/path/to/key.pem')
     
    218216const http = require('http');
    219217const WebSocket = require('ws');
    220 const url = require('url');
    221218
    222219const server = http.createServer();
     
    251248```
    252249
    253 ### Client authentication
    254 
    255 ```js
    256 const http = require('http');
    257 const WebSocket = require('ws');
    258 
    259 const server = http.createServer();
    260 const wss = new WebSocket.Server({ noServer: true });
    261 
    262 wss.on('connection', function connection(ws, request, client) {
    263   ws.on('message', function message(msg) {
    264     console.log(`Received message ${msg} from user ${client}`);
     250### Server broadcast
     251
     252```js
     253const WebSocket = require('ws');
     254
     255const wss = new WebSocket.Server({ port: 8080 });
     256
     257// Broadcast to all.
     258wss.broadcast = function broadcast(data) {
     259  wss.clients.forEach(function each(client) {
     260    if (client.readyState === WebSocket.OPEN) {
     261      client.send(data);
     262    }
    265263  });
    266 });
    267 
    268 server.on('upgrade', function upgrade(request, socket, head) {
    269   // This function is not defined on purpose. Implement it with your own logic.
    270   authenticate(request, (err, client) => {
    271     if (err || !client) {
    272       socket.write('HTTP/1.1 401 Unauthorized\r\n\r\n');
    273       socket.destroy();
    274       return;
    275     }
    276 
    277     wss.handleUpgrade(request, socket, head, function done(ws) {
    278       wss.emit('connection', ws, request, client);
    279     });
    280   });
    281 });
    282 
    283 server.listen(8080);
    284 ```
    285 
    286 Also see the provided [example][session-parse-example] using `express-session`.
    287 
    288 ### Server broadcast
    289 
    290 A client WebSocket broadcasting to all connected WebSocket clients, including
    291 itself.
    292 
    293 ```js
    294 const WebSocket = require('ws');
    295 
    296 const wss = new WebSocket.Server({ port: 8080 });
     264};
    297265
    298266wss.on('connection', function connection(ws) {
    299267  ws.on('message', function incoming(data) {
    300     wss.clients.forEach(function each(client) {
    301       if (client.readyState === WebSocket.OPEN) {
    302         client.send(data);
    303       }
    304     });
    305   });
    306 });
    307 ```
    308 
    309 A client WebSocket broadcasting to every other connected WebSocket clients,
    310 excluding itself.
    311 
    312 ```js
    313 const WebSocket = require('ws');
    314 
    315 const wss = new WebSocket.Server({ port: 8080 });
    316 
    317 wss.on('connection', function connection(ws) {
    318   ws.on('message', function incoming(data) {
     268    // Broadcast to everyone else.
    319269    wss.clients.forEach(function each(client) {
    320270      if (client !== ws && client.readyState === WebSocket.OPEN) {
     
    353303```
    354304
    355 ### Use the Node.js streams API
    356 
    357 ```js
    358 const WebSocket = require('ws');
    359 
    360 const ws = new WebSocket('wss://echo.websocket.org/', {
    361   origin: 'https://websocket.org'
    362 });
    363 
    364 const duplex = WebSocket.createWebSocketStream(ws, { encoding: 'utf8' });
    365 
    366 duplex.pipe(process.stdout);
    367 process.stdin.pipe(duplex);
    368 ```
    369 
    370305### Other examples
    371306
     
    375310Otherwise, see the test cases.
    376311
     312## Error handling best practices
     313
     314```js
     315// If the WebSocket is closed before the following send is attempted
     316ws.send('something');
     317
     318// Errors (both immediate and async write errors) can be detected in an optional
     319// callback. The callback is also the only way of being notified that data has
     320// actually been sent.
     321ws.send('something', function ack(error) {
     322  // If error is not defined, the send has been completed, otherwise the error
     323  // object will indicate what failed.
     324});
     325
     326// Immediate errors can also be handled with `try...catch`, but **note** that
     327// since sends are inherently asynchronous, socket write failures will *not* be
     328// captured when this technique is used.
     329try {
     330  ws.send('something');
     331} catch (e) {
     332  /* handle error */
     333}
     334```
     335
    377336## FAQ
    378337
     
    387346
    388347wss.on('connection', function connection(ws, req) {
    389   const ip = req.socket.remoteAddress;
     348  const ip = req.connection.remoteAddress;
    390349});
    391350```
     
    433392  });
    434393}, 30000);
    435 
    436 wss.on('close', function close() {
    437   clearInterval(interval);
    438 });
    439394```
    440395
     
    452407  clearTimeout(this.pingTimeout);
    453408
    454   // Use `WebSocket#terminate()`, which immediately destroys the connection,
    455   // instead of `WebSocket#close()`, which waits for the close timer.
    456   // Delay should be equal to the interval at which your server
    457   // sends out pings plus a conservative assumption of the latency.
     409  // Use `WebSocket#terminate()` and not `WebSocket#close()`. Delay should be
     410  // equal to the interval at which your server sends out pings plus a
     411  // conservative assumption of the latency.
    458412  this.pingTimeout = setTimeout(() => {
    459413    this.terminate();
     
    483437[MIT](LICENSE)
    484438
     439[https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
     440[socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
     441[client-report]: http://websockets.github.io/ws/autobahn/clients/
     442[server-report]: http://websockets.github.io/ws/autobahn/servers/
     443[permessage-deflate]: https://tools.ietf.org/html/rfc7692
    485444[changelog]: https://github.com/websockets/ws/releases
    486 [client-report]: http://websockets.github.io/ws/autobahn/clients/
    487 [https-proxy-agent]: https://github.com/TooTallNate/node-https-proxy-agent
    488445[node-zlib-bug]: https://github.com/nodejs/node/issues/8871
    489446[node-zlib-deflaterawdocs]:
    490447  https://nodejs.org/api/zlib.html#zlib_zlib_createdeflateraw_options
    491 [permessage-deflate]: https://tools.ietf.org/html/rfc7692
    492 [server-report]: http://websockets.github.io/ws/autobahn/servers/
    493 [session-parse-example]: ./examples/express-session-parse
    494 [socks-proxy-agent]: https://github.com/TooTallNate/node-socks-proxy-agent
    495448[ws-server-options]:
    496449  https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback
Note: See TracChangeset for help on using the changeset viewer.