Setup default option

if wsc doesn't previosuly exist, create a empty option block.
add option 'protocols' for wsc that can specify the optional protocols before the options.
Options will also only apply to node client websockets; (package 'ws'), browser websockets only take 1 with 1 optional parameter (being the list of protocols to connect with; so I added that optional param for compatibility.
This commit is contained in:
d3x0r 2016-12-21 12:09:10 -08:00 committed by GitHub
parent f548db293b
commit f28b62fd4c

View File

@ -83,6 +83,7 @@ function Peer (url, options) {
this.setMaxListeners(Infinity);
this.options = options || {};
this.options.wsc = options.wsc || { protocols: null };
// Messages sent before the socket is ready.
this.deferredMsgs = [];
@ -134,7 +135,7 @@ API.connect = function () {
var url = this.url;
// Open a new websocket.
var socket = new WebSocket(url, this.options.wsc);
var socket = new WebSocket(url, this.options.wsc.protocols, this.options.wsc);
// Re-use the previous listeners.
socket._events = this._events;