Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Add support for SockJS #31

Open
wants to merge 1 commit 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Nodejs cli tool for benchmarking websocket servers. Currently supports:
* [Engine.IO](https://github.com/LearnBoost/engine.io)
* [Faye](https://github.com/faye/faye)
* [Primus](https://github.com/primus/primus)
* [SockJS](https://github.com/sockjs/sockjs-client)

## Installation

Expand Down
3 changes: 3 additions & 0 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ switch (workerType) {
case 'primus':
BenchmarkWorker = require('./workers/primusworker.js');
break;
case 'sockjs':
BenchmarkWorker = require('./workers/sockjsworker.js');
break;
default:
logger.error('error workerType ' + workerType);
}
Expand Down
65 changes: 65 additions & 0 deletions lib/workers/sockjsworker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*global module, require*/
var util = require('util'),
SockJS = require('sockjs-client'),
BaseWorker = require('./baseworker.js'),
logger = require('../logger.js');

var pid = process.pid;

/**
* SockJSWorker Worker class inherits form BaseWorker
*/
var SockJSWorker = function (server, generator) {
SockJSWorker.super_.apply(this, arguments);
};

util.inherits(SockJSWorker, BaseWorker);

SockJSWorker.prototype.createClient = function (callback) {
var self = this;

var connect = function (session) {
var client = new SockJS(self.server, undefined, {
timeout: 90 * 1000,
devel: false,
debug: false,
protocols_whitelist: ['websocket'],
info: { "websocket": true, "origins": ["*:*"], "cookie_needed": false, "entropy": 1739246751 }
});
client.disconnect = function () {
client.close();
};
client.session = session;

client.onopen = function () {
client.open = true;
if (self.verbose) {
logger.error("[" + pid + "][WS][SockJS][OPEN]");
}
callback(false, client);
};

client.onerror = function () {
if (self.verbose) {
logger.error("[" + pid + "][WS][SockJS][ERROR]");
}
callback(true, client);
};

client.onclose = function (closeEvent) {
if (!client.open && closeEvent.code !== 1000) {
callback(true, client);
logger.error("*** Client close: " + util.inspect(closeEvent) + "Error:" + new Error().stack);
}
client.session = null;
if (self.verbose) {
logger.error("[" + pid + "][WS][SockJS][CLOSE]");
}
};
};

connect({});

};

module.exports = SockJSWorker;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"faye": "~0.8.9",
"winston": "~0.7.1",
"socket.io": "~0.9.14",
"primus": "~1.5.2"
"primus": "~1.5.2",
"sockjs-client": "^1.0.0-beta.12"
},
"devDependencies": {
"chai": "~1.6.0",
Expand Down