Skip to content

Commit

Permalink
Merge pull request #174 from ibc/master
Browse files Browse the repository at this point in the history
W3CWebSocket: Use just one or two arguments (fixes #173)
  • Loading branch information
theturtle32 committed Dec 2, 2014
2 parents 08fc659 + 12a32d9 commit 5a86cd6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
22 changes: 19 additions & 3 deletions lib/browser.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
var _global = (function() { return this; })();
var nativeWebSocket = _global.WebSocket || _global.MozWebSocket;


/**
* W3CWebSocket constructor.
* Expose a W3C WebSocket class with just one or two arguments.
*/
var W3CWebSocket = _global.WebSocket || _global.MozWebSocket;
function W3CWebSocket(uri, protocols) {
var instance;

if (protocols) {
instance = new nativeWebSocket(uri, protocols);
}
else {
instance = new nativeWebSocket(uri);
}

return instance;
}

if (nativeWebSocket) {
W3CWebSocket.prototype = nativeWebSocket.prototype;
}


/**
* Module exports.
*/
module.exports = {
'w3cwebsocket' : W3CWebSocket ? W3CWebSocket : null,
'w3cwebsocket' : nativeWebSocket ? W3CWebSocket : null,
'version' : require('./version')
};
6 changes: 3 additions & 3 deletions test/shared/test-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function prepare(callback) {
response.writeHead(404);
response.end();
});

wsServer = new WebSocketServer({
httpServer: server,
autoAcceptConnections: false,
Expand All @@ -20,7 +20,7 @@ function prepare(callback) {
keepalive: false,
disableNagleAlgorithm: false
});

server.listen(64321, function(err) {
if (err) {
return callback(err);
Expand All @@ -35,7 +35,7 @@ function stopServer() {
server.close();
}
catch(e) {
console.warn("stopServer threw", e);
console.warn('stopServer threw', e);
}
}

Expand Down

3 comments on commit 5a86cd6

@ibc
Copy link
Collaborator

@ibc ibc commented on 5a86cd6 Dec 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Let me know when 1.0.14 will be released as I need to update some dependencies :)

@theturtle32
Copy link
Owner Author

@theturtle32 theturtle32 commented on 5a86cd6 Dec 2, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibc
Copy link
Collaborator

@ibc ibc commented on 5a86cd6 Dec 2, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, don't worry! Please take your time.
Thanks a lot.

Please # to comment.