mirror of
https://github.com/fluencelabs/dweb-transports
synced 2025-03-15 18:30:49 +00:00
* 0.1.59: Add DwebTransports.statuses synchronous API
This commit is contained in:
parent
c348e56d8f
commit
1ab97ade44
@ -126,6 +126,7 @@ See [Dweb document index](./DOCUMENTINDEX.md) for a list of the repos that make
|
|||||||
|
|
||||||
### Release Notes
|
### 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.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.57: Fix heartbeat timer stopping
|
||||||
* 0.1.56: tweak http queue; changes to stop, status, info to support heartbeat on HTTP
|
* 0.1.56: tweak http queue; changes to stop, status, info to support heartbeat on HTTP
|
||||||
|
@ -17,6 +17,8 @@ class Transports {
|
|||||||
_optionspaused Saves paused option for setup
|
_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) {
|
constructor(options) {
|
||||||
// THIS IS UNUSED - ALL METHODS ARE STATIC, THERE IS NO Transports INSTANCE
|
// 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.
|
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('&')
|
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) {
|
static p_statuses(cb) {
|
||||||
/*
|
/*
|
||||||
resolves to: a dictionary of statuses of transports, e.g. { TransportHTTP: STATUS_CONNECTED }
|
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}})
|
const res = this.statuses({connected: false}); // No errors possible
|
||||||
if (cb) { cb(null, res)} else { return new Promise((resolve, reject) => resolve(res))}
|
if (cb) { cb(null, res)} else { return new Promise((resolve, reject) => resolve(res))}
|
||||||
}
|
}
|
||||||
static validFor(urls, func, opts) { //TODO-RELOAD check for noCache support
|
static validFor(urls, func, opts) { //TODO-RELOAD check for noCache support
|
||||||
/*
|
/*
|
||||||
|
21316
dist/dweb-transports-bundle.js
vendored
21316
dist/dweb-transports-bundle.js
vendored
File diff suppressed because one or more lines are too long
@ -29,7 +29,7 @@ function queueSetup({concurrency}) {
|
|||||||
if (task.loopguard === ((typeof window != "undefined") && window.loopguard)) {
|
if (task.loopguard === ((typeof window != "undefined") && window.loopguard)) {
|
||||||
fetch(task.req)
|
fetch(task.req)
|
||||||
.then(res => {
|
.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);
|
httpTaskQueue.concurrency = Math.min(httpTaskQueue.concurrency+1, httpTaskQueue.running()+6);
|
||||||
//debug("Raising concurrency to %s", httpTaskQueue.concurrency);
|
//debug("Raising concurrency to %s", httpTaskQueue.concurrency);
|
||||||
cb(null);
|
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.
|
// Using window.fetch, because it doesn't appear to be in scope otherwise in the browser.
|
||||||
let req = new Request(httpurl, init);
|
let req = new Request(httpurl, init);
|
||||||
//let response = await fetch(req);
|
//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)
|
// 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.
|
// Note response.body gets a stream and response.blob gets a blob and response.arrayBuffer gets a buffer.
|
||||||
if (response.ok) {
|
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
|
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
|
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
|
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) {
|
httptools.p_POST = function(httpurl, opts={}, cb) {
|
||||||
|
@ -53,5 +53,5 @@
|
|||||||
"test": "cd src; node ./test.js",
|
"test": "cd src; node ./test.js",
|
||||||
"help": "echo 'test (test it)'; echo 'build (creates dweb-transports-bundle)'"
|
"help": "echo 'test (test it)'; echo 'build (creates dweb-transports-bundle)'"
|
||||||
},
|
},
|
||||||
"version": "0.1.58"
|
"version": "0.1.59"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user