fix ready behavior

This commit is contained in:
CoolElectronics 2024-03-03 17:38:12 -05:00
parent a5b462f696
commit 1cc513560e
No known key found for this signature in database
GPG key ID: F63593D168636C50
7 changed files with 33 additions and 15 deletions

2
dist/Switcher.d.ts vendored
View file

@ -23,5 +23,5 @@ declare class Switcher {
}
export declare function findSwitcher(): Switcher;
export declare function SetTransport(name: string, ...config: any[]): void;
export declare function SetSingletonTransport(client: BareTransport): void;
export declare function SetSingletonTransport(client: BareTransport): Promise<void>;
export {};

14
dist/bare.cjs vendored
View file

@ -179,6 +179,11 @@
self.BCC_VERSION = "3.0.4";
console.warn("BCC_VERSION: " + self.BCC_VERSION);
function initTransport(name, config) {
let cl = new ((0, eval)(name))(...config);
cl.initpromise = cl.init();
return cl;
}
class Switcher {
active = null;
channel = new BroadcastChannel("bare-mux");
@ -191,7 +196,7 @@
break;
case "set":
const { name, config } = data;
this.active = new ((0, eval)(name))(...config);
this.active = initTransport(name, config);
break;
}
});
@ -228,11 +233,12 @@
findSwitcher();
function SetTransport(name, ...config) {
let switcher = findSwitcher();
switcher.active = new ((0, eval)(name))(...config);
switcher.active = initTransport(name, config);
switcher.channel.postMessage({ type: "set", data: { name, config } });
}
function SetSingletonTransport(client) {
async function SetSingletonTransport(client) {
let switcher = findSwitcher();
await client.init();
switcher.active = client;
switcher.channel.postMessage({ type: "setremote" });
}
@ -446,7 +452,7 @@
throw "there are no bare clients";
const client = switcher.active;
if (!client.ready)
await client.init();
await client.initpromise;
for (let i = 0;; i++) {
if ('host' in headers)
headers.host = urlO.host;

2
dist/bare.cjs.map vendored

File diff suppressed because one or more lines are too long

14
dist/index.js vendored
View file

@ -175,6 +175,11 @@ class RemoteTransport {
self.BCC_VERSION = "3.0.4";
console.warn("BCC_VERSION: " + self.BCC_VERSION);
function initTransport(name, config) {
let cl = new ((0, eval)(name))(...config);
cl.initpromise = cl.init();
return cl;
}
class Switcher {
active = null;
channel = new BroadcastChannel("bare-mux");
@ -187,7 +192,7 @@ class Switcher {
break;
case "set":
const { name, config } = data;
this.active = new ((0, eval)(name))(...config);
this.active = initTransport(name, config);
break;
}
});
@ -224,11 +229,12 @@ function findSwitcher() {
findSwitcher();
function SetTransport(name, ...config) {
let switcher = findSwitcher();
switcher.active = new ((0, eval)(name))(...config);
switcher.active = initTransport(name, config);
switcher.channel.postMessage({ type: "set", data: { name, config } });
}
function SetSingletonTransport(client) {
async function SetSingletonTransport(client) {
let switcher = findSwitcher();
await client.init();
switcher.active = client;
switcher.channel.postMessage({ type: "setremote" });
}
@ -442,7 +448,7 @@ class BareClient {
throw "there are no bare clients";
const client = switcher.active;
if (!client.ready)
await client.init();
await client.initpromise;
for (let i = 0;; i++) {
if ('host' in headers)
headers.host = urlO.host;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -340,7 +340,7 @@ export class BareClient {
let switcher = findSwitcher();
if (!switcher.active) throw "there are no bare clients";
const client = switcher.active;
if (!client.ready) await client.init();
if (!client.ready) await (client as any).initpromise;
for (let i = 0; ; i++) {
if ('host' in headers) headers.host = urlO.host;

View file

@ -22,6 +22,11 @@ declare global {
}
}
function initTransport(name: string, config: any) {
let cl = new ((0, eval)(name))(...config);
cl.initpromise = cl.init();
return cl;
}
class Switcher {
active: BareTransport | null = null;
@ -36,7 +41,7 @@ class Switcher {
break;
case "set":
const { name, config } = data;
this.active = new ((0, eval)(name))(...config);
this.active = initTransport(name, config);
break;
}
});
@ -76,12 +81,13 @@ findSwitcher();
export function SetTransport(name: string, ...config: any[]) {
let switcher = findSwitcher();
switcher.active = new ((0, eval)(name))(...config);
switcher.active = initTransport(name, config);
switcher.channel.postMessage({ type: "set", data: { name, config } });
}
export function SetSingletonTransport(client: BareTransport) {
export async function SetSingletonTransport(client: BareTransport) {
let switcher = findSwitcher();
await client.init();
switcher.active = client;
switcher.channel.postMessage({ type: "setremote" });
}