Add get options cat.wsp

gets options passed to Gun( { wsc: { ...} } ) and puts wsc options in wsp which is used to contain a working state 'count' right now.  In addition to 'count' it will now contain 'wsc' which are the options passed to the gun instance.  This is cached on the 'cat' so the lookup should only be one time.
Since 'cat' becomes 'peer' later, peer.wsp.wsc are the new options.  These will always exist for the WebSocket call.  They default to 'null' and or Empty so no change will be expected without additional options.
This commit is contained in:
d3x0r 2017-03-22 17:10:22 -07:00 committed by GitHub
parent e60d7acee0
commit 823950d87d

4
gun.js
View File

@ -2323,7 +2323,7 @@
Gun.on('out', function(at){ Gun.on('out', function(at){
this.to.next(at); this.to.next(at);
var cat = at.gun._.root._, wsp = cat.wsp || (cat.wsp = {}); var cat = at.gun._.root._, wsp = cat.wsp || (cat.wsp = {wsc: at.gun.back('opt.wsc') || {protocols:null} });
if(at.wsp && 1 === wsp.count){ return } // if the message came FROM the only peer we are connected to, don't echo it back. if(at.wsp && 1 === wsp.count){ return } // if the message came FROM the only peer we are connected to, don't echo it back.
message = JSON.stringify(at); message = JSON.stringify(at);
//if(++count){ console.log("msg OUT:", count, Gun.obj.ify(message)) } //if(++count){ console.log("msg OUT:", count, Gun.obj.ify(message)) }
@ -2375,7 +2375,7 @@
function open(peer, as){ function open(peer, as){
if(!peer || !peer.url){ return } if(!peer || !peer.url){ return }
var url = peer.url.replace('http', 'ws'); var url = peer.url.replace('http', 'ws');
var wire = peer.wire = new WebSocket(url); var wire = peer.wire = new WebSocket(url, peer.wsc.protocols, peer.wsc );
wire.onclose = function(){ wire.onclose = function(){
reconnect(peer, as); reconnect(peer, as);
}; };