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

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" });
}