mirror of
https://github.com/amark/gun.git
synced 2025-06-06 06:06:50 +00:00
Merge pull request #297 from d3x0r/patch-5
pass gun's options to websocket
This commit is contained in:
commit
eddbbf6247
9
gun.js
9
gun.js
@ -2198,9 +2198,9 @@
|
||||
);
|
||||
}
|
||||
|
||||
function Client (url, options) {
|
||||
function Client (url, options, wscOptions ) {
|
||||
if (!(this instanceof Client)) {
|
||||
return new Client(url, options);
|
||||
return new Client(url, options, wscOptions);
|
||||
}
|
||||
|
||||
this.url = Client.formatURL(url);
|
||||
@ -2211,6 +2211,7 @@
|
||||
this.on = Gun.on;
|
||||
|
||||
this.options = options || {};
|
||||
this.options.wsc = wscOptions;
|
||||
this.resetBackoff();
|
||||
}
|
||||
|
||||
@ -2234,7 +2235,7 @@
|
||||
|
||||
connect: function () {
|
||||
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;
|
||||
|
||||
// Forward messages into the emitter.
|
||||
@ -2416,7 +2417,7 @@
|
||||
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.
|
||||
Client.pool[url] = client;
|
||||
|
@ -83,6 +83,8 @@ function Peer (url, options) {
|
||||
this.setMaxListeners(Infinity);
|
||||
|
||||
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.
|
||||
this.deferredMsgs = [];
|
||||
@ -134,7 +136,7 @@ API.connect = function () {
|
||||
var url = this.url;
|
||||
|
||||
// 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.
|
||||
socket._events = this._events;
|
||||
|
Loading…
x
Reference in New Issue
Block a user