Fixed a few things
This commit is contained in:
@@ -22,6 +22,9 @@ export default function DMs() {
|
|||||||
const sendRequest = async (req: ClientMessage) => {
|
const sendRequest = async (req: ClientMessage) => {
|
||||||
console.log("Sending request:", req);
|
console.log("Sending request:", req);
|
||||||
|
|
||||||
|
await targetNode.current?.waitUntilReady();
|
||||||
|
await app.node.current?.waitUntilReady();
|
||||||
|
|
||||||
switch (req.type) {
|
switch (req.type) {
|
||||||
case "send_message":
|
case "send_message":
|
||||||
targetNode.current?.socket?.send(JSON.stringify(req));
|
targetNode.current?.socket?.send(JSON.stringify(req));
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ export default function ChannelView({
|
|||||||
<div className="h-svh w-full max-h-svh flex flex-col pb-5 pl-5 gap-5" />
|
<div className="h-svh w-full max-h-svh flex flex-col pb-5 pl-5 gap-5" />
|
||||||
);
|
);
|
||||||
|
|
||||||
const sendRequest = (req: ClientMessage) => {
|
const sendRequest = async (req: ClientMessage) => {
|
||||||
|
await node.current?.waitUntilReady();
|
||||||
node.current?.socket?.send(JSON.stringify(req));
|
node.current?.socket?.send(JSON.stringify(req));
|
||||||
console.log(node.current?.socket);
|
console.log(node.current?.socket);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ export default function PluginChannel({
|
|||||||
parentComm.sendToChild("MESSAGES", messages);
|
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(
|
node.current?.socket?.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: "send_message",
|
type: "send_message",
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ export class NodeClient {
|
|||||||
private readonly serverId: string;
|
private readonly serverId: string;
|
||||||
private readonly messageStore: MessageStore;
|
private readonly messageStore: MessageStore;
|
||||||
private readonly callbacks: NodeCallbacks;
|
private readonly callbacks: NodeCallbacks;
|
||||||
|
private ready: boolean;
|
||||||
|
private readyPromise: Promise<void>;
|
||||||
|
private resolveReady!: () => void;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
serverId: string,
|
serverId: string,
|
||||||
@@ -31,6 +34,10 @@ export class NodeClient {
|
|||||||
this.messageStore = messageStore;
|
this.messageStore = messageStore;
|
||||||
this.callbacks = callbacks;
|
this.callbacks = callbacks;
|
||||||
this.name = serverId;
|
this.name = serverId;
|
||||||
|
this.ready = false;
|
||||||
|
this.readyPromise = new Promise((resolve) => {
|
||||||
|
this.resolveReady = resolve;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get socket() {
|
get socket() {
|
||||||
@@ -62,6 +69,11 @@ export class NodeClient {
|
|||||||
this.ws = null;
|
this.ws = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async waitUntilReady() {
|
||||||
|
if (this.ready) return;
|
||||||
|
await this.readyPromise;
|
||||||
|
}
|
||||||
|
|
||||||
private async handleMessage(e: MessageEvent, authToken: string) {
|
private async handleMessage(e: MessageEvent, authToken: string) {
|
||||||
// Voice packet
|
// Voice packet
|
||||||
if (e.data instanceof Blob) {
|
if (e.data instanceof Blob) {
|
||||||
@@ -116,6 +128,9 @@ export class NodeClient {
|
|||||||
this.callbacks.onVoiceJoin?.(userId, channelId, voiceId)
|
this.callbacks.onVoiceJoin?.(userId, channelId, voiceId)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.ready = true;
|
||||||
|
this.resolveReady();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "message_create":
|
case "message_create":
|
||||||
|
|||||||
Reference in New Issue
Block a user