Skip to content
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
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
alert("Sorry, the build of your browser does not support WebSockets. Please use latest Chrome or Webkit nightly");
return;
}

ws = new WebSocket("ws://localhost:8080/");
ws.onmessage = function(evt) {
ws.onmessage = function(evt) {
data = eval("(" + evt.data + ")");
var p = $("<div class='tweet' style='display:none'><div class='content'><a class='main-screenname' href='http://www.twitter.com/" + data.user.screen_name + "/status/" + data.id + "' target='_blank'>" + data.user.screen_name + "</a> " + data.text + "</div></div>");
if($('#tweets div.tweet').size() > 15) {
Expand Down
2 changes: 1 addition & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var message = "";

request.addListener('response', function (response) {
response.setEncoding("utf8");

response.addListener("data", function (chunk) {

message += chunk;
Expand Down
6 changes: 3 additions & 3 deletions vendor/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/

/* Modified by Dan Webb not to require Narwhal's binary library */

var encodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
Expand Down Expand Up @@ -50,8 +50,8 @@ exports.encode = function (str) {
out.push(encodeChars.charCodeAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)));
out.push(encodeChars.charCodeAt(c3 & 0x3F));
}
var str = "";

var str = "";
out.forEach(function(chr) { str += String.fromCharCode(chr) });
return str;
};
Expand Down
24 changes: 12 additions & 12 deletions vendor/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ var sys = require("sys"),
'origin': /^(.+)$/,
},
handshakeTemplate75 = [
'HTTP/1.1 101 Web Socket Protocol Handshake',
'Upgrade: WebSocket',
'HTTP/1.1 101 Web Socket Protocol Handshake',
'Upgrade: WebSocket',
'Connection: Upgrade',
'WebSocket-Origin: {origin}',
'WebSocket-Location: ws://{host}{resource}',
Expand Down Expand Up @@ -70,13 +70,13 @@ exports.createServer = function (websocketListener, options) {
var emitter = new process.EventEmitter(),
handshaked = false,
buffer = "";

function handle(data) {
buffer += data;

var chunks = buffer.split("\ufffd"),
count = chunks.length - 1; // last is "" or a partial packet

for(var i = 0; i < count; i++) {
var chunk = chunks[i];
if(chunk[0] == "\u0000") {
Expand All @@ -86,7 +86,7 @@ exports.createServer = function (websocketListener, options) {
return;
}
}

buffer = chunks[count];
}

Expand Down Expand Up @@ -150,7 +150,7 @@ exports.createServer = function (websocketListener, options) {
var hash = crypto.createHash("md5")
, key1 = pack(parseInt(numkey1/spaces1))
, key2 = pack(parseInt(numkey2/spaces2));

hash.update(key1);
hash.update(key2);
hash.update(upgradeHead);
Expand Down Expand Up @@ -196,23 +196,23 @@ exports.createServer = function (websocketListener, options) {
});

emitter.remoteAddress = socket.remoteAddress;

emitter.write = function (data) {
try {
socket.write('\u0000', 'binary');
socket.write(data, 'utf8');
socket.write('\uffff', 'binary');
} catch(e) {
// Socket not open for writing,
} catch(e) {
// Socket not open for writing,
// should get "close" event just before.
socket.end();
}
}

emitter.end = function () {
socket.end();
}

websocketListener(emitter); // emits: "connect", "data", "close", provides: write(data), end()
});
}
Expand Down