Merge pull request #297 from d3x0r/patch-5

pass gun's options to websocket
This commit is contained in:
Mark Nadal 2016-12-22 23:01:12 -07:00 committed by GitHub
commit eddbbf6247
2 changed files with 8 additions and 5 deletions

9
gun.js
View File

@ -2198,9 +2198,9 @@
); );
} }
function Client (url, options) { function Client (url, options, wscOptions ) {
if (!(this instanceof Client)) { if (!(this instanceof Client)) {
return new Client(url, options); return new Client(url, options, wscOptions);
} }
this.url = Client.formatURL(url); this.url = Client.formatURL(url);
@ -2211,6 +2211,7 @@
this.on = Gun.on; this.on = Gun.on;
this.options = options || {}; this.options = options || {};
this.options.wsc = wscOptions;
this.resetBackoff(); this.resetBackoff();
} }
@ -2234,7 +2235,7 @@
connect: function () { connect: function () {
var client = this; var client = this;
var socket = new Client.WebSocket(this.url); var socket = new Client.WebSocket(this.url, this.options.wsc.protocols, this.options.wsc );
this.socket = socket; this.socket = socket;
// Forward messages into the emitter. // Forward messages into the emitter.
@ -2416,7 +2417,7 @@
return; return;
} }
var client = new Client(url, options.backoff); var client = new Client(url, options.backoff, gun.Back('opt.wsc') || {protocols:null});
// Add it to the pool. // Add it to the pool.
Client.pool[url] = client; Client.pool[url] = client;

View File

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