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

primeNG components

Location:
trip-planner-front/node_modules/ws/lib
Files:
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/ws/lib/buffer-util.js

    r59329aa re29cc2e  
    1616
    1717  const target = Buffer.allocUnsafe(totalLength);
    18   let offset = 0;
     18  var offset = 0;
    1919
    20   for (let i = 0; i < list.length; i++) {
     20  for (var i = 0; i < list.length; i++) {
    2121    const buf = list[i];
    22     target.set(buf, offset);
     22    buf.copy(target, offset);
    2323    offset += buf.length;
    2424  }
    25 
    26   if (offset < totalLength) return target.slice(0, offset);
    2725
    2826  return target;
     
    4038 */
    4139function _mask(source, mask, output, offset, length) {
    42   for (let i = 0; i < length; i++) {
     40  for (var i = 0; i < length; i++) {
    4341    output[offset + i] = source[i] ^ mask[i & 3];
    4442  }
     
    5553  // Required until https://github.com/nodejs/node/issues/9006 is resolved.
    5654  const length = buffer.length;
    57   for (let i = 0; i < length; i++) {
     55  for (var i = 0; i < length; i++) {
    5856    buffer[i] ^= mask[i & 3];
    5957  }
     
    8886  if (Buffer.isBuffer(data)) return data;
    8987
    90   let buf;
     88  var buf;
    9189
    9290  if (data instanceof ArrayBuffer) {
    9391    buf = Buffer.from(data);
    9492  } else if (ArrayBuffer.isView(data)) {
    95     buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
     93    buf = viewToBuffer(data);
    9694  } else {
    9795    buf = Buffer.from(data);
    9896    toBuffer.readOnly = false;
     97  }
     98
     99  return buf;
     100}
     101
     102/**
     103 * Converts an `ArrayBuffer` view into a buffer.
     104 *
     105 * @param {(DataView|TypedArray)} view The view to convert
     106 * @return {Buffer} Converted view
     107 * @private
     108 */
     109function viewToBuffer(view) {
     110  const buf = Buffer.from(view.buffer);
     111
     112  if (view.byteLength !== view.buffer.byteLength) {
     113    return buf.slice(view.byteOffset, view.byteOffset + view.byteLength);
    99114  }
    100115
  • trip-planner-front/node_modules/ws/lib/event-target.js

    r59329aa re29cc2e  
    1111   *
    1212   * @param {String} type The name of the event
    13    * @param {Object} target A reference to the target to which the event was
    14    *     dispatched
     13   * @param {Object} target A reference to the target to which the event was dispatched
    1514   */
    1615  constructor(type, target) {
     
    3130   *
    3231   * @param {(String|Buffer|ArrayBuffer|Buffer[])} data The received data
    33    * @param {WebSocket} target A reference to the target to which the event was
    34    *     dispatched
     32   * @param {WebSocket} target A reference to the target to which the event was dispatched
    3533   */
    3634  constructor(data, target) {
     
    5149   * Create a new `CloseEvent`.
    5250   *
    53    * @param {Number} code The status code explaining why the connection is being
    54    *     closed
    55    * @param {String} reason A human-readable string explaining why the
    56    *     connection is closing
    57    * @param {WebSocket} target A reference to the target to which the event was
    58    *     dispatched
     51   * @param {Number} code The status code explaining why the connection is being closed
     52   * @param {String} reason A human-readable string explaining why the connection is closing
     53   * @param {WebSocket} target A reference to the target to which the event was dispatched
    5954   */
    6055  constructor(code, reason, target) {
     
    7772   * Create a new `OpenEvent`.
    7873   *
    79    * @param {WebSocket} target A reference to the target to which the event was
    80    *     dispatched
     74   * @param {WebSocket} target A reference to the target to which the event was dispatched
    8175   */
    8276  constructor(target) {
     
    9690   *
    9791   * @param {Object} error The error that generated this event
    98    * @param {WebSocket} target A reference to the target to which the event was
    99    *     dispatched
     92   * @param {WebSocket} target A reference to the target to which the event was dispatched
    10093   */
    10194  constructor(error, target) {
     
    117110   * Register an event listener.
    118111   *
    119    * @param {String} type A string representing the event type to listen for
     112   * @param {String} method A string representing the event type to listen for
    120113   * @param {Function} listener The listener to add
    121    * @param {Object} [options] An options object specifies characteristics about
    122    *     the event listener
    123    * @param {Boolean} [options.once=false] A `Boolean`` indicating that the
    124    *     listener should be invoked at most once after being added. If `true`,
    125    *     the listener would be automatically removed when invoked.
    126114   * @public
    127115   */
    128   addEventListener(type, listener, options) {
     116  addEventListener(method, listener) {
    129117    if (typeof listener !== 'function') return;
    130118
     
    145133    }
    146134
    147     const method = options && options.once ? 'once' : 'on';
    148 
    149     if (type === 'message') {
     135    if (method === 'message') {
    150136      onMessage._listener = listener;
    151       this[method](type, onMessage);
    152     } else if (type === 'close') {
     137      this.on(method, onMessage);
     138    } else if (method === 'close') {
    153139      onClose._listener = listener;
    154       this[method](type, onClose);
    155     } else if (type === 'error') {
     140      this.on(method, onClose);
     141    } else if (method === 'error') {
    156142      onError._listener = listener;
    157       this[method](type, onError);
    158     } else if (type === 'open') {
     143      this.on(method, onError);
     144    } else if (method === 'open') {
    159145      onOpen._listener = listener;
    160       this[method](type, onOpen);
     146      this.on(method, onOpen);
    161147    } else {
    162       this[method](type, listener);
     148      this.on(method, listener);
    163149    }
    164150  },
     
    167153   * Remove an event listener.
    168154   *
    169    * @param {String} type A string representing the event type to remove
     155   * @param {String} method A string representing the event type to remove
    170156   * @param {Function} listener The listener to remove
    171157   * @public
    172158   */
    173   removeEventListener(type, listener) {
    174     const listeners = this.listeners(type);
     159  removeEventListener(method, listener) {
     160    const listeners = this.listeners(method);
    175161
    176     for (let i = 0; i < listeners.length; i++) {
     162    for (var i = 0; i < listeners.length; i++) {
    177163      if (listeners[i] === listener || listeners[i]._listener === listener) {
    178         this.removeListener(type, listeners[i]);
     164        this.removeListener(method, listeners[i]);
    179165      }
    180166    }
  • trip-planner-front/node_modules/ws/lib/extension.js

    r59329aa re29cc2e  
    3535 */
    3636function push(dest, name, elem) {
    37   if (dest[name] === undefined) dest[name] = [elem];
    38   else dest[name].push(elem);
     37  if (Object.prototype.hasOwnProperty.call(dest, name)) dest[name].push(elem);
     38  else dest[name] = [elem];
    3939}
    4040
     
    4747 */
    4848function parse(header) {
    49   const offers = Object.create(null);
     49  const offers = {};
    5050
    5151  if (header === undefined || header === '') return offers;
    5252
    53   let params = Object.create(null);
    54   let mustUnescape = false;
    55   let isEscaping = false;
    56   let inQuotes = false;
    57   let extensionName;
    58   let paramName;
    59   let start = -1;
    60   let end = -1;
    61   let i = 0;
    62 
    63   for (; i < header.length; i++) {
     53  var params = {};
     54  var mustUnescape = false;
     55  var isEscaping = false;
     56  var inQuotes = false;
     57  var extensionName;
     58  var paramName;
     59  var start = -1;
     60  var end = -1;
     61
     62  for (var i = 0; i < header.length; i++) {
    6463    const code = header.charCodeAt(i);
    6564
     
    7877        if (code === 0x2c) {
    7978          push(offers, name, params);
    80           params = Object.create(null);
     79          params = {};
    8180        } else {
    8281          extensionName = name;
     
    101100        if (code === 0x2c) {
    102101          push(offers, extensionName, params);
    103           params = Object.create(null);
     102          params = {};
    104103          extensionName = undefined;
    105104        }
     
    148147
    149148        if (end === -1) end = i;
    150         let value = header.slice(start, end);
     149        var value = header.slice(start, end);
    151150        if (mustUnescape) {
    152151          value = value.replace(/\\/g, '');
     
    156155        if (code === 0x2c) {
    157156          push(offers, extensionName, params);
    158           params = Object.create(null);
     157          params = {};
    159158          extensionName = undefined;
    160159        }
     
    175174  const token = header.slice(start, end);
    176175  if (extensionName === undefined) {
    177     push(offers, token, params);
     176    push(offers, token, {});
    178177  } else {
    179178    if (paramName === undefined) {
     
    200199  return Object.keys(extensions)
    201200    .map((extension) => {
    202       let configurations = extensions[extension];
     201      var configurations = extensions[extension];
    203202      if (!Array.isArray(configurations)) configurations = [configurations];
    204203      return configurations
     
    207206            .concat(
    208207              Object.keys(params).map((k) => {
    209                 let values = params[k];
     208                var values = params[k];
    210209                if (!Array.isArray(values)) values = [values];
    211210                return values
  • trip-planner-front/node_modules/ws/lib/permessage-deflate.js

    r59329aa re29cc2e  
    11'use strict';
    22
     3const Limiter = require('async-limiter');
    34const zlib = require('zlib');
    45
    56const bufferUtil = require('./buffer-util');
    6 const Limiter = require('./limiter');
    77const { kStatusCode, NOOP } = require('./constants');
    88
    99const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
     10const EMPTY_BLOCK = Buffer.from([0x00]);
     11
    1012const kPerMessageDeflate = Symbol('permessage-deflate');
    1113const kTotalLength = Symbol('total-length');
     
    3032   * Creates a PerMessageDeflate instance.
    3133   *
    32    * @param {Object} [options] Configuration options
    33    * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
    34    *     disabling of server context takeover
    35    * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
    36    *     acknowledge disabling of client context takeover
    37    * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
     34   * @param {Object} options Configuration options
     35   * @param {Boolean} options.serverNoContextTakeover Request/accept disabling
     36   *     of server context takeover
     37   * @param {Boolean} options.clientNoContextTakeover Advertise/acknowledge
     38   *     disabling of client context takeover
     39   * @param {(Boolean|Number)} options.serverMaxWindowBits Request/confirm the
    3840   *     use of a custom server window size
    39    * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
     41   * @param {(Boolean|Number)} options.clientMaxWindowBits Advertise support
    4042   *     for, or request, a custom client window size
    41    * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
    42    *     deflate
    43    * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
    44    *     inflate
    45    * @param {Number} [options.threshold=1024] Size (in bytes) below which
    46    *     messages should not be compressed
    47    * @param {Number} [options.concurrencyLimit=10] The number of concurrent
    48    *     calls to zlib
    49    * @param {Boolean} [isServer=false] Create the instance in either server or
    50    *     client mode
    51    * @param {Number} [maxPayload=0] The maximum allowed message length
     43   * @param {Object} options.zlibDeflateOptions Options to pass to zlib on deflate
     44   * @param {Object} options.zlibInflateOptions Options to pass to zlib on inflate
     45   * @param {Number} options.threshold Size (in bytes) below which messages
     46   *     should not be compressed
     47   * @param {Number} options.concurrencyLimit The number of concurrent calls to
     48   *     zlib
     49   * @param {Boolean} isServer Create the instance in either server or client
     50   *     mode
     51   * @param {Number} maxPayload The maximum allowed message length
    5252   */
    5353  constructor(options, isServer, maxPayload) {
     
    6767          ? this._options.concurrencyLimit
    6868          : 10;
    69       zlibLimiter = new Limiter(concurrency);
     69      zlibLimiter = new Limiter({ concurrency });
    7070    }
    7171  }
     
    134134
    135135    if (this._deflate) {
    136       const callback = this._deflate[kCallback];
    137 
    138136      this._deflate.close();
    139137      this._deflate = null;
    140 
    141       if (callback) {
    142         callback(
    143           new Error(
    144             'The deflate stream was closed while data was being processed'
    145           )
    146         );
    147       }
    148138    }
    149139  }
     
    244234    configurations.forEach((params) => {
    245235      Object.keys(params).forEach((key) => {
    246         let value = params[key];
     236        var value = params[key];
    247237
    248238        if (value.length > 1) {
     
    295285
    296286  /**
    297    * Decompress data. Concurrency limited.
     287   * Decompress data. Concurrency limited by async-limiter.
    298288   *
    299289   * @param {Buffer} data Compressed data
     
    303293   */
    304294  decompress(data, fin, callback) {
    305     zlibLimiter.add((done) => {
     295    zlibLimiter.push((done) => {
    306296      this._decompress(data, fin, (err, result) => {
    307297        done();
     
    312302
    313303  /**
    314    * Compress data. Concurrency limited.
     304   * Compress data. Concurrency limited by async-limiter.
    315305   *
    316306   * @param {Buffer} data Data to compress
     
    320310   */
    321311  compress(data, fin, callback) {
    322     zlibLimiter.add((done) => {
     312    zlibLimiter.push((done) => {
    323313      this._compress(data, fin, (err, result) => {
    324314        done();
     
    346336          : this.params[key];
    347337
    348       this._inflate = zlib.createInflateRaw({
    349         ...this._options.zlibInflateOptions,
    350         windowBits
    351       });
     338      this._inflate = zlib.createInflateRaw(
     339        Object.assign({}, this._options.zlibInflateOptions, { windowBits })
     340      );
    352341      this._inflate[kPerMessageDeflate] = this;
    353342      this._inflate[kTotalLength] = 0;
     
    377366      );
    378367
    379       if (this._inflate._readableState.endEmitted) {
     368      if (fin && this.params[`${endpoint}_no_context_takeover`]) {
    380369        this._inflate.close();
    381370        this._inflate = null;
     
    383372        this._inflate[kTotalLength] = 0;
    384373        this._inflate[kBuffers] = [];
    385 
    386         if (fin && this.params[`${endpoint}_no_context_takeover`]) {
    387           this._inflate.reset();
    388         }
    389374      }
    390375
     
    402387   */
    403388  _compress(data, fin, callback) {
     389    if (!data || data.length === 0) {
     390      process.nextTick(callback, null, EMPTY_BLOCK);
     391      return;
     392    }
     393
    404394    const endpoint = this._isServer ? 'server' : 'client';
    405395
     
    411401          : this.params[key];
    412402
    413       this._deflate = zlib.createDeflateRaw({
    414         ...this._options.zlibDeflateOptions,
    415         windowBits
    416       });
     403      this._deflate = zlib.createDeflateRaw(
     404        Object.assign({}, this._options.zlibDeflateOptions, { windowBits })
     405      );
    417406
    418407      this._deflate[kTotalLength] = 0;
     
    429418    }
    430419
    431     this._deflate[kCallback] = callback;
    432 
    433420    this._deflate.write(data);
    434421    this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
    435422      if (!this._deflate) {
    436423        //
    437         // The deflate stream was closed while data was being processed.
     424        // This `if` statement is only needed for Node.js < 10.0.0 because as of
     425        // commit https://github.com/nodejs/node/commit/5e3f5164, the flush
     426        // callback is no longer called if the deflate stream is closed while
     427        // data is being processed.
    438428        //
    439429        return;
    440430      }
    441431
    442       let data = bufferUtil.concat(
     432      var data = bufferUtil.concat(
    443433        this._deflate[kBuffers],
    444434        this._deflate[kTotalLength]
     
    447437      if (fin) data = data.slice(0, data.length - 4);
    448438
    449       //
    450       // Ensure that the callback will not be called again in
    451       // `PerMessageDeflate#cleanup()`.
    452       //
    453       this._deflate[kCallback] = null;
    454 
    455       this._deflate[kTotalLength] = 0;
    456       this._deflate[kBuffers] = [];
    457 
    458439      if (fin && this.params[`${endpoint}_no_context_takeover`]) {
    459         this._deflate.reset();
     440        this._deflate.close();
     441        this._deflate = null;
     442      } else {
     443        this._deflate[kTotalLength] = 0;
     444        this._deflate[kBuffers] = [];
    460445      }
    461446
  • trip-planner-front/node_modules/ws/lib/receiver.js

    r59329aa re29cc2e  
    2929   * Creates a Receiver instance.
    3030   *
    31    * @param {String} [binaryType=nodebuffer] The type for binary data
    32    * @param {Object} [extensions] An object containing the negotiated extensions
    33    * @param {Boolean} [isServer=false] Specifies whether to operate in client or
    34    *     server mode
    35    * @param {Number} [maxPayload=0] The maximum allowed message length
    36    */
    37   constructor(binaryType, extensions, isServer, maxPayload) {
     31   * @param {String} binaryType The type for binary data
     32   * @param {Object} extensions An object containing the negotiated extensions
     33   * @param {Number} maxPayload The maximum allowed message length
     34   */
     35  constructor(binaryType, extensions, maxPayload) {
    3836    super();
    3937
     
    4139    this[kWebSocket] = undefined;
    4240    this._extensions = extensions || {};
    43     this._isServer = !!isServer;
    4441    this._maxPayload = maxPayload | 0;
    4542
     
    6966   * @param {String} encoding The character encoding of `chunk`
    7067   * @param {Function} cb Callback
    71    * @private
    7268   */
    7369  _write(chunk, encoding, cb) {
     
    10197    do {
    10298      const buf = this._buffers[0];
    103       const offset = dst.length - n;
    10499
    105100      if (n >= buf.length) {
    106         dst.set(this._buffers.shift(), offset);
     101        this._buffers.shift().copy(dst, dst.length - n);
    107102      } else {
    108         dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
     103        buf.copy(dst, dst.length - n, 0, n);
    109104        this._buffers[0] = buf.slice(n);
    110105      }
     
    123118   */
    124119  startLoop(cb) {
    125     let err;
     120    var err;
    126121    this._loop = true;
    127122
     
    230225    this._masked = (buf[1] & 0x80) === 0x80;
    231226
    232     if (this._isServer) {
    233       if (!this._masked) {
    234         this._loop = false;
    235         return error(RangeError, 'MASK must be set', true, 1002);
    236       }
    237     } else if (this._masked) {
    238       this._loop = false;
    239       return error(RangeError, 'MASK must be clear', true, 1002);
    240     }
    241 
    242227    if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
    243228    else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
     
    336321   */
    337322  getData(cb) {
    338     let data = EMPTY_BUFFER;
     323    var data = EMPTY_BUFFER;
    339324
    340325    if (this._payloadLength) {
     
    416401
    417402      if (this._opcode === 2) {
    418         let data;
     403        var data;
    419404
    420405        if (this._binaryType === 'nodebuffer') {
  • trip-planner-front/node_modules/ws/lib/sender.js

    r59329aa re29cc2e  
    11'use strict';
    22
    3 const { randomFillSync } = require('crypto');
     3const { randomBytes } = require('crypto');
    44
    55const PerMessageDeflate = require('./permessage-deflate');
     
    88const { mask: applyMask, toBuffer } = require('./buffer-util');
    99
    10 const mask = Buffer.alloc(4);
    11 
    1210/**
    1311 * HyBi Sender implementation.
     
    1816   *
    1917   * @param {net.Socket} socket The connection socket
    20    * @param {Object} [extensions] An object containing the negotiated extensions
     18   * @param {Object} extensions An object containing the negotiated extensions
    2119   */
    2220  constructor(socket, extensions) {
     
    3836   * @param {Object} options Options object
    3937   * @param {Number} options.opcode The opcode
    40    * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
    41    *     modified
    42    * @param {Boolean} [options.fin=false] Specifies whether or not to set the
    43    *     FIN bit
    44    * @param {Boolean} [options.mask=false] Specifies whether or not to mask
    45    *     `data`
    46    * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
    47    *     RSV1 bit
     38   * @param {Boolean} options.readOnly Specifies whether `data` can be modified
     39   * @param {Boolean} options.fin Specifies whether or not to set the FIN bit
     40   * @param {Boolean} options.mask Specifies whether or not to mask `data`
     41   * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
    4842   * @return {Buffer[]} The framed data as a list of `Buffer` instances
    4943   * @public
     
    5145  static frame(data, options) {
    5246    const merge = options.mask && options.readOnly;
    53     let offset = options.mask ? 6 : 2;
    54     let payloadLength = data.length;
     47    var offset = options.mask ? 6 : 2;
     48    var payloadLength = data.length;
    5549
    5650    if (data.length >= 65536) {
     
    7872    if (!options.mask) return [target, data];
    7973
    80     randomFillSync(mask, 0, 4);
     74    const mask = randomBytes(4);
    8175
    8276    target[1] |= 0x80;
     
    9892   * Sends a close message to the other peer.
    9993   *
    100    * @param {Number} [code] The status code component of the body
    101    * @param {String} [data] The message component of the body
    102    * @param {Boolean} [mask=false] Specifies whether or not to mask the message
    103    * @param {Function} [cb] Callback
     94   * @param {(Number|undefined)} code The status code component of the body
     95   * @param {String} data The message component of the body
     96   * @param {Boolean} mask Specifies whether or not to mask the message
     97   * @param {Function} cb Callback
    10498   * @public
    10599   */
    106100  close(code, data, mask, cb) {
    107     let buf;
     101    var buf;
    108102
    109103    if (code === undefined) {
     
    115109      buf.writeUInt16BE(code, 0);
    116110    } else {
    117       const length = Buffer.byteLength(data);
    118 
    119       if (length > 123) {
    120         throw new RangeError('The message must not be greater than 123 bytes');
    121       }
    122 
    123       buf = Buffer.allocUnsafe(2 + length);
     111      buf = Buffer.allocUnsafe(2 + Buffer.byteLength(data));
    124112      buf.writeUInt16BE(code, 0);
    125113      buf.write(data, 2);
     
    137125   *
    138126   * @param {Buffer} data The message to send
    139    * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
    140    * @param {Function} [cb] Callback
     127   * @param {Boolean} mask Specifies whether or not to mask `data`
     128   * @param {Function} cb Callback
    141129   * @private
    142130   */
     
    158146   *
    159147   * @param {*} data The message to send
    160    * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
    161    * @param {Function} [cb] Callback
     148   * @param {Boolean} mask Specifies whether or not to mask `data`
     149   * @param {Function} cb Callback
    162150   * @public
    163151   */
     
    165153    const buf = toBuffer(data);
    166154
    167     if (buf.length > 125) {
    168       throw new RangeError('The data size must not be greater than 125 bytes');
    169     }
    170 
    171155    if (this._deflating) {
    172156      this.enqueue([this.doPing, buf, mask, toBuffer.readOnly, cb]);
     
    179163   * Frames and sends a ping message.
    180164   *
    181    * @param {Buffer} data The message to send
    182    * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
    183    * @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
    184    * @param {Function} [cb] Callback
     165   * @param {*} data The message to send
     166   * @param {Boolean} mask Specifies whether or not to mask `data`
     167   * @param {Boolean} readOnly Specifies whether `data` can be modified
     168   * @param {Function} cb Callback
    185169   * @private
    186170   */
     
    202186   *
    203187   * @param {*} data The message to send
    204    * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
    205    * @param {Function} [cb] Callback
     188   * @param {Boolean} mask Specifies whether or not to mask `data`
     189   * @param {Function} cb Callback
    206190   * @public
    207191   */
     
    209193    const buf = toBuffer(data);
    210194
    211     if (buf.length > 125) {
    212       throw new RangeError('The data size must not be greater than 125 bytes');
    213     }
    214 
    215195    if (this._deflating) {
    216196      this.enqueue([this.doPong, buf, mask, toBuffer.readOnly, cb]);
     
    223203   * Frames and sends a pong message.
    224204   *
    225    * @param {Buffer} data The message to send
    226    * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
    227    * @param {Boolean} [readOnly=false] Specifies whether `data` can be modified
    228    * @param {Function} [cb] Callback
     205   * @param {*} data The message to send
     206   * @param {Boolean} mask Specifies whether or not to mask `data`
     207   * @param {Boolean} readOnly Specifies whether `data` can be modified
     208   * @param {Function} cb Callback
    229209   * @private
    230210   */
     
    247227   * @param {*} data The message to send
    248228   * @param {Object} options Options object
    249    * @param {Boolean} [options.compress=false] Specifies whether or not to
    250    *     compress `data`
    251    * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
    252    *     or text
    253    * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
    254    *     last one
    255    * @param {Boolean} [options.mask=false] Specifies whether or not to mask
    256    *     `data`
    257    * @param {Function} [cb] Callback
     229   * @param {Boolean} options.compress Specifies whether or not to compress `data`
     230   * @param {Boolean} options.binary Specifies whether `data` is binary or text
     231   * @param {Boolean} options.fin Specifies whether the fragment is the last one
     232   * @param {Boolean} options.mask Specifies whether or not to mask `data`
     233   * @param {Function} cb Callback
    258234   * @public
    259235   */
     
    261237    const buf = toBuffer(data);
    262238    const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
    263     let opcode = options.binary ? 2 : 1;
    264     let rsv1 = options.compress;
     239    var opcode = options.binary ? 2 : 1;
     240    var rsv1 = options.compress;
    265241
    266242    if (this._firstFragment) {
     
    309285   *
    310286   * @param {Buffer} data The message to send
    311    * @param {Boolean} [compress=false] Specifies whether or not to compress
    312    *     `data`
     287   * @param {Boolean} compress Specifies whether or not to compress `data`
    313288   * @param {Object} options Options object
    314289   * @param {Number} options.opcode The opcode
    315    * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
    316    *     modified
    317    * @param {Boolean} [options.fin=false] Specifies whether or not to set the
    318    *     FIN bit
    319    * @param {Boolean} [options.mask=false] Specifies whether or not to mask
    320    *     `data`
    321    * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
    322    *     RSV1 bit
    323    * @param {Function} [cb] Callback
     290   * @param {Boolean} options.readOnly Specifies whether `data` can be modified
     291   * @param {Boolean} options.fin Specifies whether or not to set the FIN bit
     292   * @param {Boolean} options.mask Specifies whether or not to mask `data`
     293   * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
     294   * @param {Function} cb Callback
    324295   * @private
    325296   */
     
    332303    const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
    333304
    334     this._bufferedBytes += data.length;
    335305    this._deflating = true;
    336306    perMessageDeflate.compress(data, options.fin, (_, buf) => {
    337       if (this._socket.destroyed) {
    338         const err = new Error(
    339           'The socket was closed while data was being compressed'
    340         );
    341 
    342         if (typeof cb === 'function') cb(err);
    343 
    344         for (let i = 0; i < this._queue.length; i++) {
    345           const callback = this._queue[i][4];
    346 
    347           if (typeof callback === 'function') callback(err);
    348         }
    349 
    350         return;
    351       }
    352 
    353       this._bufferedBytes -= data.length;
    354307      this._deflating = false;
    355308      options.readOnly = false;
     
    369322
    370323      this._bufferedBytes -= params[1].length;
    371       Reflect.apply(params[0], this, params.slice(1));
     324      params[0].apply(this, params.slice(1));
    372325    }
    373326  }
     
    388341   *
    389342   * @param {Buffer[]} list The frame to send
    390    * @param {Function} [cb] Callback
     343   * @param {Function} cb Callback
    391344   * @private
    392345   */
  • trip-planner-front/node_modules/ws/lib/validation.js

    r59329aa re29cc2e  
    11'use strict';
     2
     3try {
     4  const isValidUTF8 = require('utf-8-validate');
     5
     6  exports.isValidUTF8 =
     7    typeof isValidUTF8 === 'object'
     8      ? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0
     9      : isValidUTF8;
     10} catch (e) /* istanbul ignore next */ {
     11  exports.isValidUTF8 = () => true;
     12}
    213
    314/**
     
    819 * @public
    920 */
    10 function isValidStatusCode(code) {
     21exports.isValidStatusCode = (code) => {
    1122  return (
    1223    (code >= 1000 &&
    13       code <= 1014 &&
     24      code <= 1013 &&
    1425      code !== 1004 &&
    1526      code !== 1005 &&
     
    1728    (code >= 3000 && code <= 4999)
    1829  );
    19 }
    20 
    21 /**
    22  * Checks if a given buffer contains only correct UTF-8.
    23  * Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
    24  * Markus Kuhn.
    25  *
    26  * @param {Buffer} buf The buffer to check
    27  * @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
    28  * @public
    29  */
    30 function _isValidUTF8(buf) {
    31   const len = buf.length;
    32   let i = 0;
    33 
    34   while (i < len) {
    35     if ((buf[i] & 0x80) === 0) {
    36       // 0xxxxxxx
    37       i++;
    38     } else if ((buf[i] & 0xe0) === 0xc0) {
    39       // 110xxxxx 10xxxxxx
    40       if (
    41         i + 1 === len ||
    42         (buf[i + 1] & 0xc0) !== 0x80 ||
    43         (buf[i] & 0xfe) === 0xc0 // Overlong
    44       ) {
    45         return false;
    46       }
    47 
    48       i += 2;
    49     } else if ((buf[i] & 0xf0) === 0xe0) {
    50       // 1110xxxx 10xxxxxx 10xxxxxx
    51       if (
    52         i + 2 >= len ||
    53         (buf[i + 1] & 0xc0) !== 0x80 ||
    54         (buf[i + 2] & 0xc0) !== 0x80 ||
    55         (buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) || // Overlong
    56         (buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0) // Surrogate (U+D800 - U+DFFF)
    57       ) {
    58         return false;
    59       }
    60 
    61       i += 3;
    62     } else if ((buf[i] & 0xf8) === 0xf0) {
    63       // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    64       if (
    65         i + 3 >= len ||
    66         (buf[i + 1] & 0xc0) !== 0x80 ||
    67         (buf[i + 2] & 0xc0) !== 0x80 ||
    68         (buf[i + 3] & 0xc0) !== 0x80 ||
    69         (buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) || // Overlong
    70         (buf[i] === 0xf4 && buf[i + 1] > 0x8f) ||
    71         buf[i] > 0xf4 // > U+10FFFF
    72       ) {
    73         return false;
    74       }
    75 
    76       i += 4;
    77     } else {
    78       return false;
    79     }
    80   }
    81 
    82   return true;
    83 }
    84 
    85 try {
    86   let isValidUTF8 = require('utf-8-validate');
    87 
    88   /* istanbul ignore if */
    89   if (typeof isValidUTF8 === 'object') {
    90     isValidUTF8 = isValidUTF8.Validation.isValidUTF8; // utf-8-validate@<3.0.0
    91   }
    92 
    93   module.exports = {
    94     isValidStatusCode,
    95     isValidUTF8(buf) {
    96       return buf.length < 150 ? _isValidUTF8(buf) : isValidUTF8(buf);
    97     }
    98   };
    99 } catch (e) /* istanbul ignore next */ {
    100   module.exports = {
    101     isValidStatusCode,
    102     isValidUTF8: _isValidUTF8
    103   };
    104 }
     30};
  • trip-planner-front/node_modules/ws/lib/websocket-server.js

    r59329aa re29cc2e  
    22
    33const EventEmitter = require('events');
    4 const { createHash } = require('crypto');
    5 const { createServer, STATUS_CODES } = require('http');
     4const crypto = require('crypto');
     5const http = require('http');
    66
    77const PerMessageDeflate = require('./permessage-deflate');
     8const extension = require('./extension');
    89const WebSocket = require('./websocket');
    9 const { format, parse } = require('./extension');
    10 const { GUID, kWebSocket } = require('./constants');
     10const { GUID } = require('./constants');
    1111
    1212const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
     
    2222   *
    2323   * @param {Object} options Configuration options
    24    * @param {Number} [options.backlog=511] The maximum length of the queue of
    25    *     pending connections
    26    * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
    27    *     track clients
    28    * @param {Function} [options.handleProtocols] A hook to handle protocols
    29    * @param {String} [options.host] The hostname where to bind the server
    30    * @param {Number} [options.maxPayload=104857600] The maximum allowed message
    31    *     size
    32    * @param {Boolean} [options.noServer=false] Enable no server mode
    33    * @param {String} [options.path] Accept only connections matching this path
    34    * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
     24   * @param {Number} options.backlog The maximum length of the queue of pending
     25   *     connections
     26   * @param {Boolean} options.clientTracking Specifies whether or not to track
     27   *     clients
     28   * @param {Function} options.handleProtocols An hook to handle protocols
     29   * @param {String} options.host The hostname where to bind the server
     30   * @param {Number} options.maxPayload The maximum allowed message size
     31   * @param {Boolean} options.noServer Enable no server mode
     32   * @param {String} options.path Accept only connections matching this path
     33   * @param {(Boolean|Object)} options.perMessageDeflate Enable/disable
    3534   *     permessage-deflate
    36    * @param {Number} [options.port] The port where to bind the server
    37    * @param {http.Server} [options.server] A pre-created HTTP/S server to use
    38    * @param {Function} [options.verifyClient] A hook to reject connections
    39    * @param {Function} [callback] A listener for the `listening` event
     35   * @param {Number} options.port The port where to bind the server
     36   * @param {http.Server} options.server A pre-created HTTP/S server to use
     37   * @param {Function} options.verifyClient An hook to reject connections
     38   * @param {Function} callback A listener for the `listening` event
    4039   */
    4140  constructor(options, callback) {
    4241    super();
    4342
    44     options = {
    45       maxPayload: 100 * 1024 * 1024,
    46       perMessageDeflate: false,
    47       handleProtocols: null,
    48       clientTracking: true,
    49       verifyClient: null,
    50       noServer: false,
    51       backlog: null, // use default (511 as implemented in net.js)
    52       server: null,
    53       host: null,
    54       path: null,
    55       port: null,
    56       ...options
    57     };
     43    options = Object.assign(
     44      {
     45        maxPayload: 100 * 1024 * 1024,
     46        perMessageDeflate: false,
     47        handleProtocols: null,
     48        clientTracking: true,
     49        verifyClient: null,
     50        noServer: false,
     51        backlog: null, // use default (511 as implemented in net.js)
     52        server: null,
     53        host: null,
     54        path: null,
     55        port: null
     56      },
     57      options
     58    );
    5859
    5960    if (options.port == null && !options.server && !options.noServer) {
     
    6465
    6566    if (options.port != null) {
    66       this._server = createServer((req, res) => {
    67         const body = STATUS_CODES[426];
     67      this._server = http.createServer((req, res) => {
     68        const body = http.STATUS_CODES[426];
    6869
    6970        res.writeHead(426, {
     
    8485
    8586    if (this._server) {
    86       const emitConnection = this.emit.bind(this, 'connection');
    87 
    8887      this._removeListeners = addListeners(this._server, {
    8988        listening: this.emit.bind(this, 'listening'),
    9089        error: this.emit.bind(this, 'error'),
    9190        upgrade: (req, socket, head) => {
    92           this.handleUpgrade(req, socket, head, emitConnection);
     91          this.handleUpgrade(req, socket, head, (ws) => {
     92            this.emit('connection', ws, req);
     93          });
    9394        }
    9495      });
     
    121122   * Close the server.
    122123   *
    123    * @param {Function} [cb] Callback
     124   * @param {Function} cb Callback
    124125   * @public
    125126   */
     
    208209
    209210      try {
    210         const offers = parse(req.headers['sec-websocket-extensions']);
     211        const offers = extension.parse(req.headers['sec-websocket-extensions']);
    211212
    212213        if (offers[PerMessageDeflate.extensionName]) {
     
    226227        origin:
    227228          req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
    228         secure: !!(req.socket.authorized || req.socket.encrypted),
     229        secure: !!(req.connection.authorized || req.connection.encrypted),
    229230        req
    230231      };
     
    256257   * @param {Buffer} head The first packet of the upgraded stream
    257258   * @param {Function} cb Callback
    258    * @throws {Error} If called more than once with the same socket
    259259   * @private
    260260   */
     
    265265    if (!socket.readable || !socket.writable) return socket.destroy();
    266266
    267     if (socket[kWebSocket]) {
    268       throw new Error(
    269         'server.handleUpgrade() was called more than once with the same ' +
    270           'socket, possibly due to a misconfiguration'
    271       );
    272     }
    273 
    274     const digest = createHash('sha1')
     267    const digest = crypto
     268      .createHash('sha1')
    275269      .update(key + GUID)
    276270      .digest('base64');
     
    284278
    285279    const ws = new WebSocket(null);
    286     let protocol = req.headers['sec-websocket-protocol'];
     280    var protocol = req.headers['sec-websocket-protocol'];
    287281
    288282    if (protocol) {
     
    300294      if (protocol) {
    301295        headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
    302         ws._protocol = protocol;
     296        ws.protocol = protocol;
    303297      }
    304298    }
     
    306300    if (extensions[PerMessageDeflate.extensionName]) {
    307301      const params = extensions[PerMessageDeflate.extensionName].params;
    308       const value = format({
     302      const value = extension.format({
    309303        [PerMessageDeflate.extensionName]: [params]
    310304      });
     
    328322    }
    329323
    330     cb(ws, req);
     324    cb(ws);
    331325  }
    332326}
     
    340334 * @param {EventEmitter} server The event emitter
    341335 * @param {Object.<String, Function>} map The listeners to add
    342  * @return {Function} A function that will remove the added listeners when
    343  *     called
     336 * @return {Function} A function that will remove the added listeners when called
    344337 * @private
    345338 */
     
    384377function abortHandshake(socket, code, message, headers) {
    385378  if (socket.writable) {
    386     message = message || STATUS_CODES[code];
    387     headers = {
    388       Connection: 'close',
    389       'Content-Type': 'text/html',
    390       'Content-Length': Buffer.byteLength(message),
    391       ...headers
    392     };
     379    message = message || http.STATUS_CODES[code];
     380    headers = Object.assign(
     381      {
     382        Connection: 'close',
     383        'Content-type': 'text/html',
     384        'Content-Length': Buffer.byteLength(message)
     385      },
     386      headers
     387    );
    393388
    394389    socket.write(
    395       `HTTP/1.1 ${code} ${STATUS_CODES[code]}\r\n` +
     390      `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
    396391        Object.keys(headers)
    397392          .map((h) => `${h}: ${headers[h]}`)
  • trip-planner-front/node_modules/ws/lib/websocket.js

    r59329aa re29cc2e  
    22
    33const EventEmitter = require('events');
     4const crypto = require('crypto');
    45const https = require('https');
    56const http = require('http');
    67const net = require('net');
    78const tls = require('tls');
    8 const { randomBytes, createHash } = require('crypto');
    9 const { URL } = require('url');
     9const url = require('url');
    1010
    1111const PerMessageDeflate = require('./permessage-deflate');
     12const EventTarget = require('./event-target');
     13const extension = require('./extension');
    1214const Receiver = require('./receiver');
    1315const Sender = require('./sender');
     
    2022  NOOP
    2123} = require('./constants');
    22 const { addEventListener, removeEventListener } = require('./event-target');
    23 const { format, parse } = require('./extension');
    24 const { toBuffer } = require('./buffer-util');
    2524
    2625const readyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
     
    3736   * Create a new `WebSocket`.
    3837   *
    39    * @param {(String|url.URL)} address The URL to which to connect
    40    * @param {(String|String[])} [protocols] The subprotocols
    41    * @param {Object} [options] Connection options
     38   * @param {(String|url.Url|url.URL)} address The URL to which to connect
     39   * @param {(String|String[])} protocols The subprotocols
     40   * @param {Object} options Connection options
    4241   */
    4342  constructor(address, protocols, options) {
    4443    super();
    4544
     45    this.readyState = WebSocket.CONNECTING;
     46    this.protocol = '';
     47
    4648    this._binaryType = BINARY_TYPES[0];
    47     this._closeCode = 1006;
    4849    this._closeFrameReceived = false;
    4950    this._closeFrameSent = false;
    5051    this._closeMessage = '';
    5152    this._closeTimer = null;
     53    this._closeCode = 1006;
    5254    this._extensions = {};
    53     this._protocol = '';
    54     this._readyState = WebSocket.CONNECTING;
    5555    this._receiver = null;
    5656    this._sender = null;
     
    5858
    5959    if (address !== null) {
    60       this._bufferedAmount = 0;
    6160      this._isServer = false;
    6261      this._redirects = 0;
     
    7574  }
    7675
     76  get CONNECTING() {
     77    return WebSocket.CONNECTING;
     78  }
     79  get CLOSING() {
     80    return WebSocket.CLOSING;
     81  }
     82  get CLOSED() {
     83    return WebSocket.CLOSED;
     84  }
     85  get OPEN() {
     86    return WebSocket.OPEN;
     87  }
     88
    7789  /**
    7890   * This deviates from the WHATWG interface since ws doesn't support the
     
    101113   */
    102114  get bufferedAmount() {
    103     if (!this._socket) return this._bufferedAmount;
    104 
    105     return this._socket._writableState.length + this._sender._bufferedBytes;
     115    if (!this._socket) return 0;
     116
     117    //
     118    // `socket.bufferSize` is `undefined` if the socket is closed.
     119    //
     120    return (this._socket.bufferSize || 0) + this._sender._bufferedBytes;
    106121  }
    107122
     
    114129
    115130  /**
    116    * @type {String}
    117    */
    118   get protocol() {
    119     return this._protocol;
    120   }
    121 
    122   /**
    123    * @type {Number}
    124    */
    125   get readyState() {
    126     return this._readyState;
    127   }
    128 
    129   /**
    130    * @type {String}
    131    */
    132   get url() {
    133     return this._url;
    134   }
    135 
    136   /**
    137131   * Set up the socket and the internal resources.
    138132   *
    139133   * @param {net.Socket} socket The network socket between the server and client
    140134   * @param {Buffer} head The first packet of the upgraded stream
    141    * @param {Number} [maxPayload=0] The maximum allowed message size
     135   * @param {Number} maxPayload The maximum allowed message size
    142136   * @private
    143137   */
    144138  setSocket(socket, head, maxPayload) {
    145139    const receiver = new Receiver(
    146       this.binaryType,
     140      this._binaryType,
    147141      this._extensions,
    148       this._isServer,
    149142      maxPayload
    150143    );
     
    174167    socket.on('error', socketOnError);
    175168
    176     this._readyState = WebSocket.OPEN;
     169    this.readyState = WebSocket.OPEN;
    177170    this.emit('open');
    178171  }
     
    184177   */
    185178  emitClose() {
     179    this.readyState = WebSocket.CLOSED;
     180
    186181    if (!this._socket) {
    187       this._readyState = WebSocket.CLOSED;
    188182      this.emit('close', this._closeCode, this._closeMessage);
    189183      return;
     
    195189
    196190    this._receiver.removeAllListeners();
    197     this._readyState = WebSocket.CLOSED;
    198191    this.emit('close', this._closeCode, this._closeMessage);
    199192  }
     
    214207   *              +---+
    215208   *
    216    * @param {Number} [code] Status code explaining why the connection is closing
    217    * @param {String} [data] A string explaining why the connection is closing
     209   * @param {Number} code Status code explaining why the connection is closing
     210   * @param {String} data A string explaining why the connection is closing
    218211   * @public
    219212   */
     
    230223    }
    231224
    232     this._readyState = WebSocket.CLOSING;
     225    this.readyState = WebSocket.CLOSING;
    233226    this._sender.close(code, data, !this._isServer, (err) => {
    234227      //
     
    254247   * Send a ping.
    255248   *
    256    * @param {*} [data] The data to send
    257    * @param {Boolean} [mask] Indicates whether or not to mask `data`
    258    * @param {Function} [cb] Callback which is executed when the ping is sent
     249   * @param {*} data The data to send
     250   * @param {Boolean} mask Indicates whether or not to mask `data`
     251   * @param {Function} cb Callback which is executed when the ping is sent
    259252   * @public
    260253   */
    261254  ping(data, mask, cb) {
    262     if (this.readyState === WebSocket.CONNECTING) {
    263       throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
    264     }
    265 
    266255    if (typeof data === 'function') {
    267256      cb = data;
     
    272261    }
    273262
     263    if (this.readyState !== WebSocket.OPEN) {
     264      const err = new Error(
     265        `WebSocket is not open: readyState ${this.readyState} ` +
     266          `(${readyStates[this.readyState]})`
     267      );
     268
     269      if (cb) return cb(err);
     270      throw err;
     271    }
     272
    274273    if (typeof data === 'number') data = data.toString();
    275 
    276     if (this.readyState !== WebSocket.OPEN) {
    277       sendAfterClose(this, data, cb);
    278       return;
    279     }
    280 
    281274    if (mask === undefined) mask = !this._isServer;
    282275    this._sender.ping(data || EMPTY_BUFFER, mask, cb);
     
    286279   * Send a pong.
    287280   *
    288    * @param {*} [data] The data to send
    289    * @param {Boolean} [mask] Indicates whether or not to mask `data`
    290    * @param {Function} [cb] Callback which is executed when the pong is sent
     281   * @param {*} data The data to send
     282   * @param {Boolean} mask Indicates whether or not to mask `data`
     283   * @param {Function} cb Callback which is executed when the pong is sent
    291284   * @public
    292285   */
    293286  pong(data, mask, cb) {
    294     if (this.readyState === WebSocket.CONNECTING) {
    295       throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
    296     }
    297 
    298287    if (typeof data === 'function') {
    299288      cb = data;
     
    304293    }
    305294
     295    if (this.readyState !== WebSocket.OPEN) {
     296      const err = new Error(
     297        `WebSocket is not open: readyState ${this.readyState} ` +
     298          `(${readyStates[this.readyState]})`
     299      );
     300
     301      if (cb) return cb(err);
     302      throw err;
     303    }
     304
    306305    if (typeof data === 'number') data = data.toString();
    307 
    308     if (this.readyState !== WebSocket.OPEN) {
    309       sendAfterClose(this, data, cb);
    310       return;
    311     }
    312 
    313306    if (mask === undefined) mask = !this._isServer;
    314307    this._sender.pong(data || EMPTY_BUFFER, mask, cb);
     
    319312   *
    320313   * @param {*} data The message to send
    321    * @param {Object} [options] Options object
    322    * @param {Boolean} [options.compress] Specifies whether or not to compress
    323    *     `data`
    324    * @param {Boolean} [options.binary] Specifies whether `data` is binary or
    325    *     text
    326    * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
    327    *     last one
    328    * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
    329    * @param {Function} [cb] Callback which is executed when data is written out
     314   * @param {Object} options Options object
     315   * @param {Boolean} options.compress Specifies whether or not to compress `data`
     316   * @param {Boolean} options.binary Specifies whether `data` is binary or text
     317   * @param {Boolean} options.fin Specifies whether the fragment is the last one
     318   * @param {Boolean} options.mask Specifies whether or not to mask `data`
     319   * @param {Function} cb Callback which is executed when data is written out
    330320   * @public
    331321   */
    332322  send(data, options, cb) {
    333     if (this.readyState === WebSocket.CONNECTING) {
    334       throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
    335     }
    336 
    337323    if (typeof options === 'function') {
    338324      cb = options;
     
    340326    }
    341327
     328    if (this.readyState !== WebSocket.OPEN) {
     329      const err = new Error(
     330        `WebSocket is not open: readyState ${this.readyState} ` +
     331          `(${readyStates[this.readyState]})`
     332      );
     333
     334      if (cb) return cb(err);
     335      throw err;
     336    }
     337
    342338    if (typeof data === 'number') data = data.toString();
    343339
    344     if (this.readyState !== WebSocket.OPEN) {
    345       sendAfterClose(this, data, cb);
    346       return;
    347     }
    348 
    349     const opts = {
    350       binary: typeof data !== 'string',
    351       mask: !this._isServer,
    352       compress: true,
    353       fin: true,
    354       ...options
    355     };
     340    const opts = Object.assign(
     341      {
     342        binary: typeof data !== 'string',
     343        mask: !this._isServer,
     344        compress: true,
     345        fin: true
     346      },
     347      options
     348    );
    356349
    357350    if (!this._extensions[PerMessageDeflate.extensionName]) {
     
    375368
    376369    if (this._socket) {
    377       this._readyState = WebSocket.CLOSING;
     370      this.readyState = WebSocket.CLOSING;
    378371      this._socket.destroy();
    379372    }
     
    382375
    383376readyStates.forEach((readyState, i) => {
    384   const descriptor = { enumerable: true, value: i };
    385 
    386   Object.defineProperty(WebSocket.prototype, readyState, descriptor);
    387   Object.defineProperty(WebSocket, readyState, descriptor);
    388 });
    389 
    390 [
    391   'binaryType',
    392   'bufferedAmount',
    393   'extensions',
    394   'protocol',
    395   'readyState',
    396   'url'
    397 ].forEach((property) => {
    398   Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
     377  WebSocket[readyState] = i;
    399378});
    400379
     
    405384['open', 'error', 'close', 'message'].forEach((method) => {
    406385  Object.defineProperty(WebSocket.prototype, `on${method}`, {
    407     configurable: true,
    408     enumerable: true,
    409386    /**
    410387     * Return the listener of the event.
     
    415392    get() {
    416393      const listeners = this.listeners(method);
    417       for (let i = 0; i < listeners.length; i++) {
     394      for (var i = 0; i < listeners.length; i++) {
    418395        if (listeners[i]._listener) return listeners[i]._listener;
    419396      }
     
    429406    set(listener) {
    430407      const listeners = this.listeners(method);
    431       for (let i = 0; i < listeners.length; i++) {
     408      for (var i = 0; i < listeners.length; i++) {
    432409        //
    433410        // Remove only the listeners added via `addEventListener`.
     
    440417});
    441418
    442 WebSocket.prototype.addEventListener = addEventListener;
    443 WebSocket.prototype.removeEventListener = removeEventListener;
     419WebSocket.prototype.addEventListener = EventTarget.addEventListener;
     420WebSocket.prototype.removeEventListener = EventTarget.removeEventListener;
    444421
    445422module.exports = WebSocket;
     
    449426 *
    450427 * @param {WebSocket} websocket The client to initialize
    451  * @param {(String|url.URL)} address The URL to which to connect
    452  * @param {String} [protocols] The subprotocols
    453  * @param {Object} [options] Connection options
    454  * @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
     428 * @param {(String|url.Url|url.URL)} address The URL to which to connect
     429 * @param {String} protocols The subprotocols
     430 * @param {Object} options Connection options
     431 * @param {(Boolean|Object)} options.perMessageDeflate Enable/disable
    455432 *     permessage-deflate
    456  * @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
     433 * @param {Number} options.handshakeTimeout Timeout in milliseconds for the
    457434 *     handshake request
    458  * @param {Number} [options.protocolVersion=13] Value of the
    459  *     `Sec-WebSocket-Version` header
    460  * @param {String} [options.origin] Value of the `Origin` or
     435 * @param {Number} options.protocolVersion Value of the `Sec-WebSocket-Version`
     436 *     header
     437 * @param {String} options.origin Value of the `Origin` or
    461438 *     `Sec-WebSocket-Origin` header
    462  * @param {Number} [options.maxPayload=104857600] The maximum allowed message
    463  *     size
    464  * @param {Boolean} [options.followRedirects=false] Whether or not to follow
    465  *     redirects
    466  * @param {Number} [options.maxRedirects=10] The maximum number of redirects
    467  *     allowed
     439 * @param {Number} options.maxPayload The maximum allowed message size
     440 * @param {Boolean} options.followRedirects Whether or not to follow redirects
     441 * @param {Number} options.maxRedirects The maximum number of redirects allowed
    468442 * @private
    469443 */
    470444function initAsClient(websocket, address, protocols, options) {
    471   const opts = {
    472     protocolVersion: protocolVersions[1],
    473     maxPayload: 100 * 1024 * 1024,
    474     perMessageDeflate: true,
    475     followRedirects: false,
    476     maxRedirects: 10,
    477     ...options,
    478     createConnection: undefined,
    479     socketPath: undefined,
    480     hostname: undefined,
    481     protocol: undefined,
    482     timeout: undefined,
    483     method: undefined,
    484     host: undefined,
    485     path: undefined,
    486     port: undefined
    487   };
     445  const opts = Object.assign(
     446    {
     447      protocolVersion: protocolVersions[1],
     448      maxPayload: 100 * 1024 * 1024,
     449      perMessageDeflate: true,
     450      followRedirects: false,
     451      maxRedirects: 10
     452    },
     453    options,
     454    {
     455      createConnection: undefined,
     456      socketPath: undefined,
     457      hostname: undefined,
     458      protocol: undefined,
     459      timeout: undefined,
     460      method: undefined,
     461      auth: undefined,
     462      host: undefined,
     463      path: undefined,
     464      port: undefined
     465    }
     466  );
    488467
    489468  if (!protocolVersions.includes(opts.protocolVersion)) {
     
    494473  }
    495474
    496   let parsedUrl;
    497 
    498   if (address instanceof URL) {
     475  var parsedUrl;
     476
     477  if (typeof address === 'object' && address.href !== undefined) {
    499478    parsedUrl = address;
    500     websocket._url = address.href;
     479    websocket.url = address.href;
    501480  } else {
    502     parsedUrl = new URL(address);
    503     websocket._url = address;
     481    //
     482    // The WHATWG URL constructor is not available on Node.js < 6.13.0
     483    //
     484    parsedUrl = url.URL ? new url.URL(address) : url.parse(address);
     485    websocket.url = address;
    504486  }
    505487
     
    513495    parsedUrl.protocol === 'wss:' || parsedUrl.protocol === 'https:';
    514496  const defaultPort = isSecure ? 443 : 80;
    515   const key = randomBytes(16).toString('base64');
     497  const key = crypto.randomBytes(16).toString('base64');
    516498  const get = isSecure ? https.get : http.get;
    517   let perMessageDeflate;
     499  const path = parsedUrl.search
     500    ? `${parsedUrl.pathname || '/'}${parsedUrl.search}`
     501    : parsedUrl.pathname || '/';
     502  var perMessageDeflate;
    518503
    519504  opts.createConnection = isSecure ? tlsConnect : netConnect;
     
    523508    ? parsedUrl.hostname.slice(1, -1)
    524509    : parsedUrl.hostname;
    525   opts.headers = {
    526     'Sec-WebSocket-Version': opts.protocolVersion,
    527     'Sec-WebSocket-Key': key,
    528     Connection: 'Upgrade',
    529     Upgrade: 'websocket',
    530     ...opts.headers
    531   };
    532   opts.path = parsedUrl.pathname + parsedUrl.search;
     510  opts.headers = Object.assign(
     511    {
     512      'Sec-WebSocket-Version': opts.protocolVersion,
     513      'Sec-WebSocket-Key': key,
     514      Connection: 'Upgrade',
     515      Upgrade: 'websocket'
     516    },
     517    opts.headers
     518  );
     519  opts.path = path;
    533520  opts.timeout = opts.handshakeTimeout;
    534521
     
    539526      opts.maxPayload
    540527    );
    541     opts.headers['Sec-WebSocket-Extensions'] = format({
     528    opts.headers['Sec-WebSocket-Extensions'] = extension.format({
    542529      [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
    543530    });
     
    553540    }
    554541  }
    555   if (parsedUrl.username || parsedUrl.password) {
     542  if (parsedUrl.auth) {
     543    opts.auth = parsedUrl.auth;
     544  } else if (parsedUrl.username || parsedUrl.password) {
    556545    opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
    557546  }
    558547
    559548  if (isUnixSocket) {
    560     const parts = opts.path.split(':');
     549    const parts = path.split(':');
    561550
    562551    opts.socketPath = parts[0];
     
    564553  }
    565554
    566   let req = (websocket._req = get(opts));
     555  var req = (websocket._req = get(opts));
    567556
    568557  if (opts.timeout) {
     
    573562
    574563  req.on('error', (err) => {
    575     if (req === null || req.aborted) return;
     564    if (websocket._req.aborted) return;
    576565
    577566    req = websocket._req = null;
    578     websocket._readyState = WebSocket.CLOSING;
     567    websocket.readyState = WebSocket.CLOSING;
    579568    websocket.emit('error', err);
    580569    websocket.emitClose();
     
    598587      req.abort();
    599588
    600       const addr = new URL(location, address);
     589      const addr = url.URL
     590        ? new url.URL(location, address)
     591        : url.resolve(address, location);
    601592
    602593      initAsClient(websocket, addr, protocols, options);
     
    621612    req = websocket._req = null;
    622613
    623     const digest = createHash('sha1')
     614    const digest = crypto
     615      .createHash('sha1')
    624616      .update(key + GUID)
    625617      .digest('base64');
     
    632624    const serverProt = res.headers['sec-websocket-protocol'];
    633625    const protList = (protocols || '').split(/, */);
    634     let protError;
     626    var protError;
    635627
    636628    if (!protocols && serverProt) {
     
    647639    }
    648640
    649     if (serverProt) websocket._protocol = serverProt;
     641    if (serverProt) websocket.protocol = serverProt;
    650642
    651643    if (perMessageDeflate) {
    652644      try {
    653         const extensions = parse(res.headers['sec-websocket-extensions']);
     645        const extensions = extension.parse(
     646          res.headers['sec-websocket-extensions']
     647        );
    654648
    655649        if (extensions[PerMessageDeflate.extensionName]) {
    656650          perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
    657           websocket._extensions[PerMessageDeflate.extensionName] =
    658             perMessageDeflate;
     651          websocket._extensions[
     652            PerMessageDeflate.extensionName
     653          ] = perMessageDeflate;
    659654        }
    660655      } catch (err) {
     
    680675 */
    681676function netConnect(options) {
    682   options.path = options.socketPath;
     677  //
     678  // Override `options.path` only if `options` is a copy of the original options
     679  // object. This is always true on Node.js >= 8 but not on Node.js 6 where
     680  // `options.socketPath` might be `undefined` even if the `socketPath` option
     681  // was originally set.
     682  //
     683  if (options.protocolVersion) options.path = options.socketPath;
    683684  return net.connect(options);
    684685}
     
    693694function tlsConnect(options) {
    694695  options.path = undefined;
    695 
    696   if (!options.servername && options.servername !== '') {
    697     options.servername = net.isIP(options.host) ? '' : options.host;
    698   }
    699 
     696  options.servername = options.servername || options.host;
    700697  return tls.connect(options);
    701698}
     
    711708 */
    712709function abortHandshake(websocket, stream, message) {
    713   websocket._readyState = WebSocket.CLOSING;
     710  websocket.readyState = WebSocket.CLOSING;
    714711
    715712  const err = new Error(message);
     
    718715  if (stream.setHeader) {
    719716    stream.abort();
    720 
    721     if (stream.socket && !stream.socket.destroyed) {
    722       //
    723       // On Node.js >= 14.3.0 `request.abort()` does not destroy the socket if
    724       // called after the request completed. See
    725       // https://github.com/websockets/ws/issues/1869.
    726       //
    727       stream.socket.destroy();
    728     }
    729 
    730717    stream.once('abort', websocket.emitClose.bind(websocket));
    731718    websocket.emit('error', err);
     
    738725
    739726/**
    740  * Handle cases where the `ping()`, `pong()`, or `send()` methods are called
    741  * when the `readyState` attribute is `CLOSING` or `CLOSED`.
    742  *
    743  * @param {WebSocket} websocket The WebSocket instance
    744  * @param {*} [data] The data to send
    745  * @param {Function} [cb] Callback
    746  * @private
    747  */
    748 function sendAfterClose(websocket, data, cb) {
    749   if (data) {
    750     const length = toBuffer(data).length;
    751 
    752     //
    753     // The `_bufferedAmount` property is used only when the peer is a client and
    754     // the opening handshake fails. Under these circumstances, in fact, the
    755     // `setSocket()` method is not called, so the `_socket` and `_sender`
    756     // properties are set to `null`.
    757     //
    758     if (websocket._socket) websocket._sender._bufferedBytes += length;
    759     else websocket._bufferedAmount += length;
    760   }
    761 
    762   if (cb) {
    763     const err = new Error(
    764       `WebSocket is not open: readyState ${websocket.readyState} ` +
    765         `(${readyStates[websocket.readyState]})`
    766     );
    767     cb(err);
    768   }
    769 }
    770 
    771 /**
    772727 * The listener of the `Receiver` `'conclude'` event.
    773728 *
     
    810765  websocket._socket.removeListener('data', socketOnData);
    811766
    812   websocket._readyState = WebSocket.CLOSING;
     767  websocket.readyState = WebSocket.CLOSING;
    813768  websocket._closeCode = err[kStatusCode];
    814769  websocket.emit('error', err);
     
    869824  this.removeListener('end', socketOnEnd);
    870825
    871   websocket._readyState = WebSocket.CLOSING;
     826  websocket.readyState = WebSocket.CLOSING;
    872827
    873828  //
     
    920875  const websocket = this[kWebSocket];
    921876
    922   websocket._readyState = WebSocket.CLOSING;
     877  websocket.readyState = WebSocket.CLOSING;
    923878  websocket._receiver.end();
    924879  this.end();
     
    936891  this.on('error', NOOP);
    937892
    938   if (websocket) {
    939     websocket._readyState = WebSocket.CLOSING;
    940     this.destroy();
    941   }
    942 }
     893  websocket.readyState = WebSocket.CLOSING;
     894  this.destroy();
     895}
Note: See TracChangeset for help on using the changeset viewer.