Merge branch 'master' into develop

This commit is contained in:
Mark Nadal 2016-11-13 10:02:42 -08:00
commit 30b4aaa6f7
3 changed files with 78 additions and 37 deletions

View File

@ -80,7 +80,7 @@ Designed with ♥ by Mark Nadal, the gun team, and many amazing contributors. L
Thanks to the following people who have contributed to GUN, via code, issues, or conversation (this list has quickly become tremendously behind! We'll probably turn this into a dedicated wiki page so you can add yourself): Thanks to the following people who have contributed to GUN, via code, issues, or conversation (this list has quickly become tremendously behind! We'll probably turn this into a dedicated wiki page so you can add yourself):
[agborkowski](https://github.com/agborkowski); [alexlafroscia](https://github.com/alexlafroscia); [anubiann00b](https://github.com/anubiann00b); [bromagosa](https://github.com/bromagosa); [coolaj86](https://github.com/coolaj86); [d-oliveros](https://github.com/d-oliveros), [danscan](https://github.com/danscan); **[forrestjt](https://github.com/forrestjt) ([file.js](https://github.com/amark/gun/blob/master/lib/file.js))**; [gedw99](https://github.com/gedw99); [HelloCodeMing](https://github.com/HelloCodeMing); **[JosePedroDias](https://github.com/josepedrodias) ([graph visualizer](http://acor.sl.pt:9966))**; **[jveres](https://github.com/jveres) ([todoMVC](https://github.com/jveres/todomvc))**; [ndarilek](https://github.com/ndarilek); [onetom](https://github.com/onetom); [phpnode](https://github.com/phpnode); [PsychoLlama](https://github.com/PsychoLlama); **[RangerMauve](https://github.com/RangerMauve) ([schema](https://github.com/gundb/gun-schema))**; [riston](https://github.com/riston); [rootsical](https://github.com/rootsical); [rrrene](https://github.com/rrrene); [sbeleidy](https://github.com/sbeleidy) [ssr1ram](https://github.com/ssr1ram); **[Stefdv](https://github.com/stefdv) ([Polymer/web components](http://stefdv.github.io/gun-collection/components/gun-collection/))**; [Xe](https://github.com/Xe); [zot](https://github.com/zot); [agborkowski](https://github.com/agborkowski); [alexlafroscia](https://github.com/alexlafroscia); [anubiann00b](https://github.com/anubiann00b); [bromagosa](https://github.com/bromagosa); [coolaj86](https://github.com/coolaj86); [d-oliveros](https://github.com/d-oliveros), [danscan](https://github.com/danscan); **[forrestjt](https://github.com/forrestjt) ([file.js](https://github.com/amark/gun/blob/master/lib/file.js))**; [gedw99](https://github.com/gedw99); [HelloCodeMing](https://github.com/HelloCodeMing); **[JosePedroDias](https://github.com/josepedrodias) ([graph visualizer](http://acor.sl.pt:9966))**; **[jveres](https://github.com/jveres) ([todoMVC](https://github.com/jveres/todomvc))**; [ndarilek](https://github.com/ndarilek); [onetom](https://github.com/onetom); [phpnode](https://github.com/phpnode); [PsychoLlama](https://github.com/PsychoLlama); **[RangerMauve](https://github.com/RangerMauve) ([schema](https://github.com/gundb/gun-schema))**; **[robertheessels](https://github.com/swifty) ([gun-p2p-auth](https://github.com/swifty/gun-p2p-auth))**; [riston](https://github.com/riston); [rootsical](https://github.com/rootsical); [rrrene](https://github.com/rrrene); [sbeleidy](https://github.com/sbeleidy) [ssr1ram](https://github.com/ssr1ram); **[Stefdv](https://github.com/stefdv) ([Polymer/web components](http://stefdv.github.io/gun-collection/components/gun-collection/))**; [Xe](https://github.com/Xe); [zot](https://github.com/zot);
[ayurmedia](https://github.com/ayurmedia); [ayurmedia](https://github.com/ayurmedia);
This list of contributors was manually compiled and alphabetically sorted. If we missed you, please submit an issue so we can get you added! This list of contributors was manually compiled and alphabetically sorted. If we missed you, please submit an issue so we can get you added!

49
gun.js
View File

@ -1372,11 +1372,32 @@
if(r.ws(opt, cb)){ return } if(r.ws(opt, cb)){ return }
r.jsonp(opt, cb); r.jsonp(opt, cb);
} }
var queues = r.queues = {};
r.ws = function(opt, cb){ r.ws = function(opt, cb){
var ws, WS = r.WebSocket || window.WebSocket || window.mozWebSocket || window.webkitWebSocket; var ws, WS = r.WebSocket || window.WebSocket || window.mozWebSocket || window.webkitWebSocket;
if(!WS){ return } if(!WS){ return }
if(ws = r.ws.peers[opt.base]){
if(!ws.readyState){ return setTimeout(function(){ r.ws(opt, cb) },10), true } // Queued offline updates.
var queue = queues[opt.base];
// Create the queue if it doesn't exist.
if (!queue) {
queue = queues[opt.base] = {};
}
// Try to de-duplicate queued messages.
var reqID = ((opt || {}).headers || {}).id || Gun.text.random(9);
ws = r.ws.peers[opt.base];
if(ws && (ws.readyState <= ws.OPEN)){
if(ws.readyState === ws.CONNECTING){
queue[reqID] = [opt, cb];
return true;
}
var req = {}; var req = {};
if(opt.headers){ req.headers = opt.headers } if(opt.headers){ req.headers = opt.headers }
if(opt.body){ req.body = opt.body } if(opt.body){ req.body = opt.body }
@ -1386,13 +1407,33 @@
if(res.body || res.end){ delete r.ws.cbs[req.headers['ws-rid']] } if(res.body || res.end){ delete r.ws.cbs[req.headers['ws-rid']] }
cb(err,res); cb(err,res);
} }
ws.send(JSON.stringify(req),function(err){})
ws.send(JSON.stringify(req),function(err){});
return true; return true;
} }
if(ws === false){ return } if(ws === false){ return }
// If we've made it this far, the socket isn't open.
queue[reqID] = [opt, cb];
try{ws = r.ws.peers[opt.base] = new WS(opt.base.replace('http','ws')); try{ws = r.ws.peers[opt.base] = new WS(opt.base.replace('http','ws'));
}catch(e){} }catch(e){}
ws.onopen = function(o){ r.back = 2; r.ws(opt, cb) };
ws.onopen = function(o){
// Send the queued messages.
Gun.obj.map(queue, function (deferred) {
r.ws.apply(null, deferred);
});
// Clear the queue.
queue = queues[opt.base] = {};
// Reset the reconnect backoff.
r.back = 2;
};
ws.onclose = function(c){ ws.onclose = function(c){
if(!c){ return } if(!c){ return }
if(ws && ws.close instanceof Function){ ws.close() } if(ws && ws.close instanceof Function){ ws.close() }

View File

@ -1,6 +1,6 @@
{ {
"name": "gun", "name": "gun",
"version": "0.3.998", "version": "0.3.999",
"description": "Graph engine", "description": "Graph engine",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {