Skip to content

Commit

Permalink
Expose listener class
Browse files Browse the repository at this point in the history
Bumped node version
Updated client
Make sure constructors are called
Added tests
  • Loading branch information
rauchg committed Jul 28, 2010
1 parent 910de83 commit 3d11b17
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The `Socket.IO` server provides seamless supports for a variety of transports in
Requirements
------------

- Node v0.1.94+
- Node v0.1.102+
- [Socket.IO client](http://github.com/LearnBoost/Socket.IO) to connect from the browser

How to use
Expand Down
2 changes: 1 addition & 1 deletion example/client
Submodule client updated from 09094a to c42d18
3 changes: 2 additions & 1 deletion example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ server = http.createServer(function(req, res){
res.end();
} catch(e){
send404(res);
}
}
break;
}

Expand All @@ -47,6 +47,7 @@ var buffer = [],
io = io.listen(server);

io.on('connection', function(client){
console.log('test');
client.send(json({ buffer: buffer }));
client.broadcast(json({ announcement: client.sessionId + ' connected' }));

Expand Down
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var Listener = require('./lib/socket.io/listener');

this.listen = function(server, options){
return new Listener(server, options);
exports.Listener = require('./lib/socket.io/listener');
exports.listen = function(server, options){
return new exports.Listener(server, options);
};
12 changes: 10 additions & 2 deletions lib/socket.io/transports/flashsocket.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
var net = require('net'),
WebSocket = require('./websocket'),
listeners = [],
netserver,

Flashsocket = module.exports = function(){};
Flashsocket = module.exports = function(){
Client.apply(this, arguments);
};

require('sys').inherits(Flashsocket, WebSocket);

Flashsocket.httpUpgrade = true;

Flashsocket.init = function(listener){
listeners.push(listener);
listener.server.on('close', function(){
try {
netserver.close();
} catch(e){}
});
};

try {
net.createServer(function(socket){
netserver = net.createServer(function(socket){
socket.write('<?xml version="1.0"?>\n');
socket.write('<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">\n');
socket.write('<cross-domain-policy>\n');
Expand Down
4 changes: 3 additions & 1 deletion lib/socket.io/transports/htmlfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Client = require('../client'),
qs = require('querystring'),

HTMLFile = module.exports = function(){};
HTMLFile = module.exports = function(){
Client.apply(this, arguments);
};

require('sys').inherits(HTMLFile, Client);

Expand Down
4 changes: 3 additions & 1 deletion lib/socket.io/transports/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ var Client = require('../client'),
Buffer = require('buffer').Buffer,
crypto = require('crypto'),

WebSocket = module.exports = function(){};
WebSocket = module.exports = function(){
Client.apply(this, arguments);
};

require('sys').inherits(WebSocket, Client);

Expand Down
4 changes: 3 additions & 1 deletion lib/socket.io/transports/xhr-multipart.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Client = require('../client'),
qs = require('querystring'),

Multipart = module.exports = function(){};
Multipart = module.exports = function(){
Client.apply(this, arguments);
};

require('sys').inherits(Multipart, Client);

Expand Down
4 changes: 3 additions & 1 deletion lib/socket.io/transports/xhr-polling.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var Client = require('../client'),
qs = require('querystring'),

Polling = module.exports = function(){};
Polling = module.exports = function(){
Client.apply(this, arguments);
};

require('sys').inherits(Polling, Client);

Expand Down
52 changes: 52 additions & 0 deletions tests/io.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var io = require('./../'),
Listener = io.Listener,
Client = require('./../lib/socket.io/client'),
WebSocket = require('./support/node-websocket-client/lib/websocket').WebSocket,
empty = new Function,
port = 8080,

create = function(fn){
var server = require('http').createServer(empty), client;
server.listen(port, function(){
client = new WebSocket('ws://localhost:'+ port++ +'/socket.io/websocket', 'borf');
});
return {server: server, client: client, close: function(){
client.close();
server.close();
}};
};

module.exports = {
'test server initialization': function(assert){
var http = create(),
sio = io.listen(http.server);
assert.ok(sio instanceof Listener);
http.close();
},

'test connection and handshake': function(assert){
var server = require('http').createServer(empty),
sio = io.listen(server),
client,
clientCount = 0,

close = function(){
client.close();
server.close();
assert.ok(clientCount, 1);
};

server.listen(port, function(){
client = new WebSocket('ws://localhost:'+ port++ +'/socket.io/websocket', 'borf');
client.onmessage = function(){
console.log('test');
};
});

sio.on('connection', function(client){
console.log('test');
clientCount++;
assert.ok(client instanceof Client);
});
}
};

0 comments on commit 3d11b17

Please sign in to comment.