Skip to content

Commit

Permalink
Replace addListener() with on().
Browse files Browse the repository at this point in the history
  • Loading branch information
pgriess committed Dec 5, 2010
1 parent 84980f3 commit 8f378ae
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
14 changes: 7 additions & 7 deletions lib/websocket.js
Expand Up @@ -369,7 +369,7 @@ var WebSocket = function(url, proto, opts) {
if (stream.write('', 'binary')) {
process.nextTick(f);
} else {
stream.addListener('drain', f);
stream.on('drain', f);
}
}
};
Expand Down Expand Up @@ -454,13 +454,13 @@ var WebSocket = function(url, proto, opts) {
throw new Error('Invalid URL scheme \'' + urlScheme + '\' specified.');
}

httpClient.addListener('upgrade', (function() {
httpClient.on('upgrade', (function() {
var data = undefined;

return function(req, s, head) {
stream = s;

stream.addListener('data', function(d) {
stream.on('data', function(d) {
if (d.length <= 0) {
return;
}
Expand Down Expand Up @@ -515,7 +515,7 @@ var WebSocket = function(url, proto, opts) {
// that we added.
httpClient.removeAllListeners('upgrade');
stream.removeAllListeners('data');
stream.addListener('data', dataListener);
stream.on('data', dataListener);

// Fire the 'open' event
process.nextTick(function() {
Expand All @@ -533,13 +533,13 @@ var WebSocket = function(url, proto, opts) {
}
}
});
stream.addListener('fd', fdListener);
stream.addListener('error', errorListener);
stream.on('fd', fdListener);
stream.on('error', errorListener);

stream.emit('data', head);
};
})());
httpClient.addListener('error', function(e) {
httpClient.on('error', function(e) {
httpClient.end();
errorListener(e);
});
Expand Down
12 changes: 6 additions & 6 deletions test/test-basic.js
Expand Up @@ -18,27 +18,27 @@ var serverGotClose = false;

var wss = new WebSocketServer();
wss.listen(PORT, 'localhost');
wss.addListener('connection', function(c) {
wss.on('connection', function(c) {
serverGotConnection = true;

c.write(S_MSG);

c.addListener('message', function(m) {
c.on('message', function(m) {
assert.equal(m, C_MSG);
serverGotMessage = true;
});

c.addListener('close', function() {
c.on('close', function() {
serverGotClose = true;
wss.close();
});
});

var ws = new WebSocket('ws://localhost:' + PORT + '/', 'biff');
ws.addListener('open', function() {
ws.on('open', function() {
clientGotOpen = true;
});
ws.addListener('data', function(buf) {
ws.on('data', function(buf) {
assert.equal(typeof buf, 'object');
assert.equal(buf.toString('utf8'), S_MSG);

Expand All @@ -52,7 +52,7 @@ ws.onmessage = function(m) {
clientGotMessage = true;
};

process.addListener('exit', function() {
process.on('exit', function() {
assert.ok(serverGotConnection);
assert.ok(clientGotOpen);
assert.ok(clientGotData);
Expand Down
4 changes: 2 additions & 2 deletions test/test-readonly-attrs.js
Expand Up @@ -9,11 +9,11 @@ var PORT = 1024 + Math.floor(Math.random() * 4096);

var wss = new WebSocketServer();
wss.listen(PORT, 'localhost');
wss.addListener('connection', function(c) {
wss.on('connection', function(c) {
wss.close();
});
var ws = new WebSocket('ws://localhost:' + PORT + '/', 'biff');
ws.addListener('open', function() {
ws.on('open', function() {
assert.equal(ws.CONNECTING, 0);
try {
ws.CONNECTING = 13;
Expand Down
14 changes: 7 additions & 7 deletions test/test-unix-send-fd.js
Expand Up @@ -18,30 +18,30 @@ var serverReceivedData = false;
var serverReceivedFD = false;

var wss = new WebSocketServer();
wss.addListener('listening', function() {
wss.on('listening', function() {
var ws = new WebSocket('ws+unix://' + PATH);
ws.addListener('data', function(d) {
ws.on('data', function(d) {
assert.equal(d.toString('utf8'), S_MSG);

clientReceivedData = true;

ws.send(C_MSG, 1);
ws.close();
});
ws.addListener('fd', function(fd) {
ws.on('fd', function(fd) {
assert.ok(fd >= 0);

clientReceivedFD = true;
});
});
wss.addListener('connection', function(c) {
wss.on('connection', function(c) {
c.write(S_MSG, 0);
c._req.socket.addListener('fd', function(fd) {
c._req.socket.on('fd', function(fd) {
assert.ok(fd >= 0);

serverReceivedFD = true;
});
c.addListener('message', function(d) {
c.on('message', function(d) {
assert.equal(d, C_MSG);

serverReceivedData = true;
Expand All @@ -51,7 +51,7 @@ wss.addListener('connection', function(c) {
});
wss.listen(PATH);

process.addListener('exit', function() {
process.on('exit', function() {
assert.ok(clientReceivedFD);
assert.ok(clientReceivedData);
assert.ok(serverReceivedFD);
Expand Down
10 changes: 5 additions & 5 deletions test/test-unix-sockets.js
Expand Up @@ -15,27 +15,27 @@ var clientGotOpen = false;
var clientGotData = false;

var wss = new WebSocketServer();
wss.addListener('listening', function() {
wss.on('listening', function() {
var ws = new WebSocket('ws+unix://' + PATH);
ws.addListener('open', function() {
ws.on('open', function() {
clientGotOpen = true;

ws.close();
});
ws.addListener('data', function(d) {
ws.on('data', function(d) {
assert.equal(d.toString('utf8'), S_MSG);
clientGotData = true;
});
});
wss.addListener('connection', function(c) {
wss.on('connection', function(c) {
serverGotConnection = true;

c.write(S_MSG);
wss.close();
});
wss.listen(PATH);

process.addListener('exit', function() {
process.on('exit', function() {
assert.ok(serverGotConnection);
assert.ok(clientGotOpen);
assert.ok(clientGotData);
Expand Down

0 comments on commit 8f378ae

Please sign in to comment.