Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Replaces (unpublished) websocket-server with 'ws' module. #151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.jshintrc
.idea
Procfile
20 changes: 2 additions & 18 deletions lib/cube/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@ var util = require("util"),
http = require("http"),
dgram = require("dgram"),
websocket = require("websocket"),
websprocket = require("websocket-server"),
WebSocketServer = require("ws").Server,
static = require("node-static"),
database = require('./database');

// And then this happened:
websprocket.Connection = require("../../node_modules/websocket-server/lib/ws/connection");

// Configuration for WebSocket requests.
var wsOptions = {
maxReceivedFrameSize: 0x10000,
Expand All @@ -33,27 +30,14 @@ module.exports = function(options) {

var server = {},
primary = http.createServer(),
secondary = websprocket.createServer(),
secondary = new WebSocketServer({ server: primary }),
file = new static.Server("static"),
meta,
endpoints = {ws: [], http: []},
id = 0;

secondary.server = primary;

// Register primary WebSocket listener with fallback.
primary.on("upgrade", function(request, socket, head) {
if ("sec-websocket-version" in request.headers) {
request = new websocket.request(socket, request, wsOptions);
request.readHandshake();
connect(request.accept(request.requestedProtocols[0], request.origin), request.httpRequest);
} else if (request.method === "GET"
&& /^websocket$/i.test(request.headers.upgrade)
&& /^upgrade$/i.test(request.headers.connection)) {
new websprocket.Connection(secondary.manager, secondary.options, request, socket, head);
}
});

// Register secondary WebSocket listener.
secondary.on("connection", function(connection) {
connection.socket = connection._socket;
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cube",
"version": "0.2.12",
"version": "0.2.13",
"description": "A system for analyzing time series data using MongoDB and Node.",
"keywords": [
"time series"
Expand All @@ -14,13 +14,14 @@
"type": "git",
"url": "http://github.com/square/cube.git"
},
"scripts":{"test":"./node_modules/.bin/vows"},
"main": "./lib/cube",
"dependencies": {
"mongodb": "~1.3.18",
"mongodb": "^1.4",
"node-static": "0.6.5",
"pegjs": "0.7.0",
"vows": "0.7.0",
"websocket": "1.0.8",
"websocket-server": "1.4.04"
"ws": "^0.7.1"
}
}