forked from sfu-innovation/cmpt-474
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Izaak Schroeder
committed
Feb 28, 2014
1 parent
e14d7a7
commit 7db8085
Showing
9 changed files
with
184 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
define(['events', 'util'], function(events, util) { | ||
|
||
function IO(opts) { | ||
EventEmitter.call(this); | ||
//var path = window.location.protocol+'//'+window.location.host+'/io'; | ||
var path = '/io'; | ||
this.socket = new SockJS(path); | ||
this.socket.onopen = function() { | ||
console.log('OPEN') | ||
} | ||
this.socket.onmessage = function() { | ||
console.log('MESSAGE') | ||
} | ||
this.socket.onclose = function() { | ||
console.log('CLOSE') | ||
} | ||
} | ||
util.inherits(IO, events.EventEmitter); | ||
|
||
return IO; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
require(['jquery', 'ansi'], function($, Ansi) { | ||
|
||
// properly render escape sequences | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,7 @@ table tr { | |
} | ||
|
||
table td, table th { | ||
|
||
vertical-align: top; | ||
} | ||
|
||
table tbody td { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
|
||
var WebSocket = require('ws'), | ||
async = require('async'), | ||
express = require('express'), | ||
app = express(); | ||
|
||
|
||
function hybi(req, socket, head, cb) { | ||
// handle premature socket errors | ||
var errorHandler = function() { | ||
try { socket.destroy(); } catch (e) {} | ||
} | ||
socket.on('error', errorHandler); | ||
|
||
// verify key presence | ||
if (!req.get('sec-websocket-key')) | ||
return next({ statusCode: 400, error: 'HYBI_NO_KEY' }) | ||
|
||
// verify version | ||
var version = parseInt(req.get('sec-websocket-version')); | ||
if ([8, 13].indexOf(version) === -1) | ||
return next({ statusCode: 400, error: 'HYBI_INVALID_VERSION', version: version }); | ||
|
||
// verify protocol | ||
var protocols = req.get('sec-websocket-protocol'); | ||
|
||
// verify client | ||
var origin = version < 13 ? req.get('sec-websocket-origin') : req.get('origin'); | ||
|
||
async.serial([ | ||
function authorize(next) { | ||
var info = { | ||
origin: origin, | ||
secure: typeof req.connection.authorized !== 'undefined' || typeof req.connection.encrypted !== 'undefined', | ||
req: req | ||
}; | ||
|
||
if (this.options.verifyClient.length == 2) { | ||
this.options.verifyClient(info, function(result) { | ||
if (!result) abortConnection(socket, 401, 'Unauthorized') | ||
else completeHybiUpgrade1(); | ||
}); | ||
return; | ||
} | ||
else if (!this.options.verifyClient(info)) { | ||
abortConnection(socket, 401, 'Unauthorized'); | ||
return; | ||
} | ||
}, | ||
function protocol(next) { | ||
// choose from the sub-protocols | ||
if (typeof self.options.handleProtocols == 'function') { | ||
var protList = (protocols || "").split(/, */); | ||
var callbackCalled = false; | ||
var res = self.options.handleProtocols(protList, function(result, protocol) { | ||
callbackCalled = true; | ||
if (!result) abortConnection(socket, 404, 'Unauthorized') | ||
else completeHybiUpgrade2(protocol); | ||
}); | ||
|
||
if (!callbackCalled) { | ||
// the handleProtocols handler never called our callback | ||
abortConnection(socket, 501, 'Could not process protocols'); | ||
} | ||
return; | ||
} | ||
else { | ||
if (typeof protocols !== 'undefined') { | ||
completeHybiUpgrade2(protocols.split(/, */)[0]); | ||
} | ||
else { | ||
completeHybiUpgrade2(); | ||
} | ||
} | ||
}, | ||
function complete(next) { | ||
var headers = [ | ||
'HTTP/1.1 101 Switching Protocols', | ||
'Connection: Upgrade', | ||
'Upgrade: websocket', | ||
'Sec-WebSocket-Accept: '+crypto.createHash('sha1') | ||
.update(req.get('sec-websocket-key') + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11") | ||
.digest('base64'), | ||
]; | ||
|
||
if (typeof protocol != 'undefined') | ||
headers.push('Sec-WebSocket-Protocol: '+protocol); | ||
|
||
socket.setTimeout(0); | ||
socket.setNoDelay(true); | ||
|
||
try { | ||
socket.write(headers.concat('', '').join('\r\n')); | ||
} | ||
catch (e) { | ||
// if the upgrade write fails, shut the connection down hard | ||
try { socket.destroy(); } catch (e) {} | ||
return; | ||
} | ||
|
||
var client = new WebSocket([req, socket, head], { | ||
protocolVersion: version, | ||
protocol: protocol | ||
}); | ||
|
||
// signal upgrade complete | ||
socket.removeListener('error', errorHandler); | ||
next(undefined, client); | ||
} | ||
], next); | ||
} | ||
|
||
|
||
|
||
app.on('upgrade', function(req, socket, head) { | ||
hybi(req, socket, Buffer(head)); | ||
}); | ||
|
||
module.exports = app; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters