From 823950d87de6fdcbff27ba3590bae75193ef76b0 Mon Sep 17 00:00:00 2001 From: d3x0r Date: Wed, 22 Mar 2017 17:10:22 -0700 Subject: [PATCH] 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. --- gun.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gun.js b/gun.js index f6038157..cf6d2aa2 100644 --- a/gun.js +++ b/gun.js @@ -2323,7 +2323,7 @@ Gun.on('out', function(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. message = JSON.stringify(at); //if(++count){ console.log("msg OUT:", count, Gun.obj.ify(message)) } @@ -2375,7 +2375,7 @@ function open(peer, as){ if(!peer || !peer.url){ return } 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(){ reconnect(peer, as); };