Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Replace addListener() with on().

  • Loading branch information...
commit 8f378ae3f2f32ce23e7844076bcc10d0e96eba7c 1 parent 84980f3
@pgriess authored
View
14 lib/websocket.js
@@ -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);
}
}
};
@@ -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;
}
@@ -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() {
@@ -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);
});
View
12 test/test-basic.js
@@ -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);
@@ -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);
View
4 test/test-readonly-attrs.js
@@ -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;
View
14 test/test-unix-send-fd.js
@@ -18,9 +18,9 @@ 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;
@@ -28,20 +28,20 @@ wss.addListener('listening', function() {
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;
@@ -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);
View
10 test/test-unix-sockets.js
@@ -15,19 +15,19 @@ 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);
@@ -35,7 +35,7 @@ wss.addListener('connection', function(c) {
});
wss.listen(PATH);
-process.addListener('exit', function() {
+process.on('exit', function() {
assert.ok(serverGotConnection);
assert.ok(clientGotOpen);
assert.ok(clientGotData);
Please sign in to comment.
Something went wrong with that request. Please try again.