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

Commit

Permalink
Whitespace & Repo cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
miksago committed Jul 20, 2010
1 parent 9587cdf commit 38a8af4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 69 deletions.
8 changes: 4 additions & 4 deletions examples/chat-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ server.addListener("listening", function(){
// Handle WebSocket Requests
server.addListener("connection", function(conn){
conn.storage.set("username", "user_"+conn.id);

conn.send("** Connected as: user_"+conn.id);
conn.send("** Type `/nick USERNAME` to change your username");

conn.broadcast("** "+conn.storage.get("username")+" connected");

conn.addListener("message", function(message){
if(message[0] == "/"){
// set username
if((matches = message.match(/^\/nick (\w+)$/i)) && matches[1]){
conn.storage.set("username", matches[1]);
conn.send("** you are now known as: "+matches[1]);

// get message count
} else if(/^\/stats/.test(message)){
conn.send("** you have sent "+conn.storage.get("messages", 0)+" messages.");
Expand Down
18 changes: 9 additions & 9 deletions examples/chat.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
$(function(){
var history = [], idx = 0;
$("#message").focus();

$(window).bind("focus", function(){
$("#message").focus();
});

var logpanel = $("#log");

function sendmsg(){
if(conn && conn.readyState == 1){
var msg = $("#message").val();
Expand All @@ -51,17 +51,17 @@
$("#message").val("");
}
};

$("#sendbtn").bind("click", function(){
sendmsg();
});

$("#message").bind("keydown", function(e){
if(e.which == 13){
sendmsg();
}
})

function scrollToBottom() {
window.scrollBy(0, document.body.scrollHeight - document.body.scrollTop);
};
Expand All @@ -73,15 +73,15 @@

if (window["WebSocket"]) {
conn = new WebSocket("ws://"+document.location.host+"/");

conn.onmessage = function(evt) {
log(evt.data);
};

conn.onclose = function() {
log("** you have been disconnected");
};

conn.onopen = function(){
log("** you have been connected");
$("#sendbtn").removeAttr("disabled");
Expand Down
6 changes: 3 additions & 3 deletions examples/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@
conn = new WebSocket("ws://"+(document.location.host != "" ? document.location.host : "localhost:8000")+"/test");
conn.onmessage = function(evt) {
log(evt.data);

// conn.close();
// log(connections++);
// connect();

// if(recvd == 0){
// conn.id = parseInt(evt.data.match(/\: ([0-9]+)/)[1], 10);
// }
// recvd++;
};

conn.onclose = function() {
log("closed");
};
Expand Down
4 changes: 2 additions & 2 deletions examples/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ function serveFile(req, res){
if(req.method == "GET"){
if( req.url.indexOf("favicon") > -1 ){
log("HTTP: inbound request, served nothing, (favicon)");

res.writeHead(200, {'Content-Type': 'image/x-icon'});
res.end("");
} else {
log("HTTP: inbound request, served client.html");

res.writeHead(200, {'Content-Type': 'text/html', 'Connection': 'close'});
fs.createReadStream( path.normalize(path.join(__dirname, "client.html")), {
'flags': 'r',
Expand Down
2 changes: 1 addition & 1 deletion examples/echo-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ server.addListener("listening", function(){
// Handle WebSocket Requests
server.addListener("connection", function(conn){
conn.send("Connection: "+conn.id);

conn.addListener("message", function(message){
conn.broadcast("<"+conn.id+"> "+message);
});
Expand Down
4 changes: 2 additions & 2 deletions lib/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ exports.createServer = function(options, server){

function Server(options, server){
var ws = this;

events.EventEmitter.call(this);

this.options = mixin({
debug: false, // Boolean: Show debug information.
version: "auto", // String: Value must be either: draft75, draft76, auto
Expand Down
22 changes: 11 additions & 11 deletions lib/ws/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Manager(showDebug){
} else {
debug = function(){};
}

this._head = null;
this._tail = null;
this._length = 0;
Expand All @@ -31,51 +31,51 @@ Manager.prototype.attach = function(id, client){
_next: null,
client: client
};

if(this._length == 0) {
this._head = connection;
this._tail = connection;
} else {
this._tail._next = connection;
this._tail = connection;
}

++this._length;

debug("Attached: "+id, this._length);
};

Manager.prototype.detach = function(id, callback){
var previous = current = this._head;

while(current !== null){
if(current.id === id){
previous._next = current._next;
this._length--;

if(current.id === this._head.id){
this._head = current._next;
}
if(current.id === this._tail.id){
this._tail = previous;
}

break;
} else {
previous = current;
current = current._next;
}
}

delete current, previous;

debug("Detached: "+id, this._length);
callback();
};

Manager.prototype.find = function(id, callback){
var current = this._head;

while(current !== null){
if(current.id === id){
callback(current.id);
Expand All @@ -88,7 +88,7 @@ Manager.prototype.find = function(id, callback){

Manager.prototype.forEach = function(callback){
var current = this._head;

while(current !== null){
callback(current.client);
current = current._next;
Expand Down
22 changes: 11 additions & 11 deletions lib/ws/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,60 @@

var Storage = function(){
var data = {};

return {
set: function(key, value){
return data[key] = value;
},

get: function(key, def){
if(data[key] !== undefined){
return data[key];
} else {
return def;
}
},

exists: function(key){
return data[key] !== undefined;
},

incr: function(key){
if(data[key] === undefined){
data[key] = 0;
}

if(typeof(data[key]) === "number"){
return data[key]++;
}
},

decr: function(key){
if(typeof(data[key]) === "number"){
return data[key]--;
}
},

push: function(key, value){
if(data[key] === undefined){
data[key] = [];
}

if(Array.isArray(data[key])){
data[key].push(value);
}
},

pop: function(key){
if(data[key] !== undefined && Array.isArray(data[key])){
return data[key].pop();
}
},

del: function(key){
data[key] = undefined;
},

to_json: function(){
return JSON.stringify(data);
}
Expand Down
26 changes: 0 additions & 26 deletions utils/logger.js

This file was deleted.

0 comments on commit 38a8af4

Please sign in to comment.