*Use setup event to ensure the RPC channels are setup for the stream only after state sync from the master protomux

This commit is contained in:
Derrick Hammer 2023-04-06 13:42:42 -04:00
parent 97190201c4
commit 88a191ae13
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 1 deletions

View File

@ -1,8 +1,13 @@
import { addHandler, handleMessage } from "libkmodule"; import { addHandler, handleMessage } from "libkmodule";
import type { ActiveQuery } from "libkmodule"; import type { ActiveQuery } from "libkmodule";
import { createClient, SwarmClient } from "@lumeweb/kernel-swarm-client"; import {
createClient,
Socket,
SwarmClient,
} from "@lumeweb/kernel-swarm-client";
import { RpcNetwork, RpcQueryOptions } from "@lumeweb/rpc-client"; import { RpcNetwork, RpcQueryOptions } from "@lumeweb/rpc-client";
import type { RPCRequest, RPCResponse } from "@lumeweb/interface-relay"; import type { RPCRequest, RPCResponse } from "@lumeweb/interface-relay";
import { setupStream } from "@lumeweb/rpc-client";
onmessage = handleMessage; onmessage = handleMessage;
@ -98,6 +103,10 @@ async function createNetwork(def = true): Promise<number> {
const id = nextId(); const id = nextId();
networkInstances.set(id, dhtInstance); networkInstances.set(id, dhtInstance);
dhtInstance.swarm.on("setup", (socket: Socket) => {
setupStream(socket);
});
return id; return id;
} }