diff --git a/src/app/chat/[id]/page.tsx b/src/app/chat/[id]/page.tsx index bcbda61..457f80d 100644 --- a/src/app/chat/[id]/page.tsx +++ b/src/app/chat/[id]/page.tsx @@ -22,6 +22,9 @@ export default function DMs() { const sendRequest = async (req: ClientMessage) => { console.log("Sending request:", req); + await targetNode.current?.waitUntilReady(); + await app.node.current?.waitUntilReady(); + switch (req.type) { case "send_message": targetNode.current?.socket?.send(JSON.stringify(req)); diff --git a/src/components/channel/ChannelView.tsx b/src/components/channel/ChannelView.tsx index bdad0ee..c019d6c 100644 --- a/src/components/channel/ChannelView.tsx +++ b/src/components/channel/ChannelView.tsx @@ -26,7 +26,8 @@ export default function ChannelView({
); - const sendRequest = (req: ClientMessage) => { + const sendRequest = async (req: ClientMessage) => { + await node.current?.waitUntilReady(); node.current?.socket?.send(JSON.stringify(req)); console.log(node.current?.socket); }; diff --git a/src/components/channel/PluginChannel.tsx b/src/components/channel/PluginChannel.tsx index 465ac1d..afbf9bc 100644 --- a/src/components/channel/PluginChannel.tsx +++ b/src/components/channel/PluginChannel.tsx @@ -32,7 +32,8 @@ export default function PluginChannel({ parentComm.sendToChild("MESSAGES", messages); }); - parentComm.onMessage("SEND_MESSAGE", (msg: string) => { + parentComm.onMessage("SEND_MESSAGE", async (msg: string) => { + await node.current?.waitUntilReady(); node.current?.socket?.send( JSON.stringify({ type: "send_message", diff --git a/src/lib/node.ts b/src/lib/node.ts index 8b10c18..d5aadcd 100644 --- a/src/lib/node.ts +++ b/src/lib/node.ts @@ -21,6 +21,9 @@ export class NodeClient { private readonly serverId: string; private readonly messageStore: MessageStore; private readonly callbacks: NodeCallbacks; + private ready: boolean; + private readyPromise: Promise