* 0.1.59: Add DwebTransports.statuses synchronous API

This commit is contained in:
Mitra Ardron 2019-07-17 08:15:23 -07:00
parent c348e56d8f
commit 1ab97ade44
5 changed files with 20823 additions and 522 deletions

View File

@ -126,6 +126,7 @@ See [Dweb document index](./DOCUMENTINDEX.md) for a list of the repos that make
### Release Notes
* 0.1.59: Add DwebTransports.statuses synchronous API
* 0.1.58: Upgrade GUN and IPFS to v0.35.0 (0.36 breaks webpack as currently configured)
* 0.1.57: Fix heartbeat timer stopping
* 0.1.56: tweak http queue; changes to stop, status, info to support heartbeat on HTTP

View File

@ -17,6 +17,8 @@ class Transports {
_optionspaused Saves paused option for setup
*/
//TODO a few of these things could be much better as events that are listened for, especially p_statuses
constructor(options) {
// THIS IS UNUSED - ALL METHODS ARE STATIC, THERE IS NO Transports INSTANCE
}
@ -38,12 +40,20 @@ class Transports {
static async p_connectedNamesParm() { // Doesnt strictly need to be async, but for consistency with Proxy it has to be.
return (await this.p_connectedNames()).map(n => "transport="+n).join('&')
}
static statuses({connected=undefined}) { //TODO-API
/*
Return array of statuses,
connected: If true then only connected transports
*/
const ss = Transports._transports.map((t) => { return {"name": t.name, "status": t.status}});
return connected ? ss.filter(s => !s.status) : ss;
}
static p_statuses(cb) {
/*
resolves to: a dictionary of statuses of transports, e.g. { TransportHTTP: STATUS_CONNECTED }
*/
const res = Transports._transports.map((t) => { return {"name": t.name, "status": t.status}})
if (cb) { cb(null, res)} else { return new Promise((resolve, reject) => resolve(res))}
/*
resolves to: a dictionary of statuses of transports, e.g. { TransportHTTP: STATUS_CONNECTED }
*/
const res = this.statuses({connected: false}); // No errors possible
if (cb) { cb(null, res)} else { return new Promise((resolve, reject) => resolve(res))}
}
static validFor(urls, func, opts) { //TODO-RELOAD check for noCache support
/*

File diff suppressed because one or more lines are too long

View File

@ -29,7 +29,7 @@ function queueSetup({concurrency}) {
if (task.loopguard === ((typeof window != "undefined") && window.loopguard)) {
fetch(task.req)
.then(res => {
debug("Fetch of %s succeeded", task.what);
debug("Fetch of %s completed", task.what);
httpTaskQueue.concurrency = Math.min(httpTaskQueue.concurrency+1, httpTaskQueue.running()+6);
//debug("Raising concurrency to %s", httpTaskQueue.concurrency);
cb(null);
@ -122,7 +122,7 @@ httptools.p_httpfetch = async function(httpurl, init, {wantstream=false, retries
// Using window.fetch, because it doesn't appear to be in scope otherwise in the browser.
let req = new Request(httpurl, init);
//let response = await fetch(req);
let response = await queuedFetch(req, 500, retries, "fetching "+httpurl);
let response = await queuedFetch(req, 500, retries, httpurl);
// fetch throws (on Chrome, untested on Firefox or Node) TypeError: Failed to fetch)
// Note response.body gets a stream and response.blob gets a blob and response.arrayBuffer gets a buffer.
if (response.ok) {
@ -175,8 +175,6 @@ httptools.p_GET = function(httpurl, opts={}, cb) {
keepalive: true // Keep alive - mostly we'll be going back to same places a lot
};
const prom = httptools.p_httpfetch(httpurl, init, {retries, wantstream: opts.wantstream}); // This s a real http url
//if (cb) { prom.then((res)=>cb(null,res)).catch((err) => cb(err)); } else { return prom; } // Unpromisify pattern v3
//if (cb) { prom.catch((err) => cb(err)).then((res)=>cb(null,res)).catch((err) => debug("Uncaught error %O",err)); } else { return prom; } // Unpromisify pattern v4
if (cb) { prom.then((res)=>{ try { cb(null,res)} catch(err) { debug("Uncaught error %O",err)}}).catch((err) => cb(err)); } else { return prom; } // Unpromisify pattern v5
}
httptools.p_POST = function(httpurl, opts={}, cb) {

View File

@ -53,5 +53,5 @@
"test": "cd src; node ./test.js",
"help": "echo 'test (test it)'; echo 'build (creates dweb-transports-bundle)'"
},
"version": "0.1.58"
"version": "0.1.59"
}