mirror of
https://github.com/fluencelabs/dweb-transports
synced 2025-04-25 06:42:17 +00:00
ServiceWorker - status support
This commit is contained in:
parent
93228d71fd
commit
d527236697
@ -13,7 +13,8 @@ class Transport {
|
|||||||
Superclass should merge with default options, call super
|
Superclass should merge with default options, call super
|
||||||
|
|
||||||
Fields:
|
Fields:
|
||||||
statuselement: If set is an HTML Element that should be adjusted to indicate status.
|
statuselement: If set is an HTML Element that should be adjusted to indicate status (this is managed by Transports, just stored on Transport)
|
||||||
|
statuscb: Callback when status changes
|
||||||
name: Short name of element e.g. HTTP IPFS WEBTORRENT
|
name: Short name of element e.g. HTTP IPFS WEBTORRENT
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,13 @@ 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 async p_statuses(t) { //TODO-API
|
||||||
|
/*
|
||||||
|
Return a dictionary of statuses of transports
|
||||||
|
*/
|
||||||
|
return this._transports.map((t) => { return {"name": t.name, "status": t.status}})
|
||||||
|
}
|
||||||
|
|
||||||
static validFor(urls, func, options) {
|
static validFor(urls, func, options) {
|
||||||
/*
|
/*
|
||||||
Finds an array or Transports that can support this URL.
|
Finds an array or Transports that can support this URL.
|
||||||
@ -476,12 +483,16 @@ class Transports {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async refreshstatus(t) {
|
static async refreshstatus(t) {
|
||||||
|
//Note "this' undefined as called as callback
|
||||||
let statusclasses = ["transportstatus0","transportstatus1","transportstatus2","transportstatus3","transportstatus4"];
|
let statusclasses = ["transportstatus0","transportstatus1","transportstatus2","transportstatus3","transportstatus4"];
|
||||||
let el = t.statuselement;
|
let el = t.statuselement;
|
||||||
if (el) {
|
if (el) {
|
||||||
el.classList.remove(...statusclasses);
|
el.classList.remove(...statusclasses);
|
||||||
el.classList.add(statusclasses[t.status]);
|
el.classList.add(statusclasses[t.status]);
|
||||||
}
|
}
|
||||||
|
if (Transports.statuscb) {
|
||||||
|
Transports.statuscb(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async p_connect(options, verbose) {
|
static async p_connect(options, verbose) {
|
||||||
@ -499,13 +510,17 @@ class Transports {
|
|||||||
if (! tabbrevs.length) { tabbrevs = ["HTTP", "YJS", "IPFS", "WEBTORRENT"]; }
|
if (! tabbrevs.length) { tabbrevs = ["HTTP", "YJS", "IPFS", "WEBTORRENT"]; }
|
||||||
tabbrevs = tabbrevs.map(n => n.toUpperCase());
|
tabbrevs = tabbrevs.map(n => n.toUpperCase());
|
||||||
let transports = this.setup0(tabbrevs, options, verbose);
|
let transports = this.setup0(tabbrevs, options, verbose);
|
||||||
|
//TODO-SW copy this statuselement buildout somewhere for proxy too
|
||||||
|
if (options.statuscb) {
|
||||||
|
this.statuscb = options.statuscb;
|
||||||
|
}
|
||||||
if (!!options.statuselement) {
|
if (!!options.statuselement) {
|
||||||
//TODO-SW need to return status through messages
|
//TODO-SW need to return status through messages
|
||||||
while (statuselement.lastChild) {statuselement.removeChild(statuselement.lastChild); } // Remove any exist status
|
while (statuselement.lastChild) {statuselement.removeChild(statuselement.lastChild); } // Remove any exist status
|
||||||
statuselement.appendChild(
|
statuselement.appendChild(
|
||||||
utils.createElement("UL", {}, transports.map(t => {
|
utils.createElement("UL", {}, transports.map(t => {
|
||||||
let el = utils.createElement("LI",
|
let el = utils.createElement("LI",
|
||||||
{onclick: "this.source.togglePaused(DwebTransports.refreshstatus);", source: t},
|
{onclick: "this.source.togglePaused(DwebTransports.refreshstatus);", source: t, name: t.name}, //TODO-SW figure out how t osend this back
|
||||||
t.name);
|
t.name);
|
||||||
t.statuselement = el; // Save status element on transport
|
t.statuselement = el; // Save status element on transport
|
||||||
return el;
|
return el;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user