source: trip-planner-front/node_modules/faye-websocket/lib/faye/websocket.js@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1// API references:
2//
3// * https://html.spec.whatwg.org/multipage/comms.html#network
4// * https://dom.spec.whatwg.org/#interface-eventtarget
5// * https://dom.spec.whatwg.org/#interface-event
6
7'use strict';
8
9var util = require('util'),
10 driver = require('websocket-driver'),
11 API = require('./websocket/api');
12
13var WebSocket = function(request, socket, body, protocols, options) {
14 options = options || {};
15
16 this._stream = socket;
17 this._driver = driver.http(request, { maxLength: options.maxLength, protocols: protocols });
18
19 var self = this;
20 if (!this._stream || !this._stream.writable) return;
21 if (!this._stream.readable) return this._stream.end();
22
23 var catchup = function() { self._stream.removeListener('data', catchup) };
24 this._stream.on('data', catchup);
25
26 API.call(this, options);
27
28 process.nextTick(function() {
29 self._driver.start();
30 self._driver.io.write(body);
31 });
32};
33util.inherits(WebSocket, API);
34
35WebSocket.isWebSocket = function(request) {
36 return driver.isWebSocket(request);
37};
38
39WebSocket.validateOptions = function(options, validKeys) {
40 driver.validateOptions(options, validKeys);
41};
42
43WebSocket.WebSocket = WebSocket;
44WebSocket.Client = require('./websocket/client');
45WebSocket.EventSource = require('./eventsource');
46
47module.exports = WebSocket;
Note: See TracBrowser for help on using the repository browser.