How to use the websocket.connection function in websocket

To help you get started, we’ve selected a few websocket examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyter-attic / dashboards_server / app / ws-rewriter.js View on Github external
/**
 * Copyright (c) Jupyter Development Team.
 * Distributed under the terms of the Modified BSD License.
 */
var debug = require('debug')('dashboard-proxy:server');
var error = require('debug')('dashboard-proxy:server:error');
var EventEmitter = require('events').EventEmitter;
var nbstore = require('./notebook-store');
var Promise = require('es6-promise').Promise;
var urljoin = require('url-join');
var util = require('util');
var WebSocketClient = require('websocket').client;
var WebSocketConnection = require('websocket').connection;
var WebSocketServer = require('websocket').server;

// 5 MB, half of tornado's (kernel gateway's) max_buffer_size
// 10 MB caused issues, see comment in tornado source code as to why (?)
var FRAGMENTATION_THRESHOLD = 0x3200000;

/**
 * Websocket proxy between client/browser and kernel gateway which rewrites execution requests to
 * the gateway, replacing numeric index values with the associated code block.
 *
 * Emits the following events:
 * 		'request': function(req: WebSocketRequest, conn: WebSocketConnection)
 * 			Fired when the websocket server handles a request from the client/browser.
 *
 * @param  {Object} args
 * @param  {Server} args.server - HTTP(S) server instance
github Azure / azure-relay-node / hyco-websocket / lib / HybridConnectionsWebSocketRequest.js View on Github external
*
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 ***********************************************************************/

var crypto = require('crypto');
var util = require('util');
var url = require('url');
var EventEmitter = require('events').EventEmitter;
var WebSocketClient = require('websocket').client;
var WebSocketConnection = require('websocket').connection;

var headerValueSplitRegExp = /,\s*/;
var headerParamSplitRegExp = /;\s*/;
var headerSanitizeRegExp = /[\r\n]/g;
var xForwardedForSeparatorRegExp = /,\s*/;
var separators = [
    '(', ')', '<', '>', '@',
    ',', ';', ':', '\\', '\"',
    '/', '[', ']', '?', '=',
    '{', '}', ' ', String.fromCharCode(9)
];

var cookieSeparatorRegEx = /[;,] */;

function HybridConnectionsWebSocketRequest(address, id, httpHeaders, serverConfig) {
    // Superclass Constructor
github Azure / azure-relay-node / hyco-websocket / lib / hybridconnectionswebsocket.js View on Github external
var websocket = require('websocket');

module.exports = {
    'server'         : websocket.server,
    'relayedServer'  : require('./HybridConnectionsWebSocketServer'),
    'client'         : websocket.client,
    'router'         : websocket.router,
    'frame'          : websocket.frame,
    'request'        : websocket.request,
    'relayedRequest' : require('./HybridConnectionsWebSocketRequest'),
    'connection'     : websocket.connection,
    'w3cwebsocket'   : websocket.w3cwebsocket,
    'deprecation'    : websocket.deprecation,
    'version'        : require('./version')
};
github trufflesuite / ganache-core / lib / webSocketServer.js View on Github external
connection.on("message", function(message) {
    let payload;
    try {
      if (message.type === "utf8") {
        payload = JSON.parse(message.utf8Data);
      } else if (message.type === "binary") {
        payload = JSON.parse(message.binaryData.toString("utf8").trim());
      } else {
        throw new Error("Invalid message type");
      }
    } catch (e) {
      connection.close(websocket.connection.CLOSE_REASON_UNPROCESSABLE_INPUT, e.message);
      return;
    }

    self._logPayload(payload);
    self._handleRequest(connection, payload);
  });