Newt registration?

This commit is contained in:
Owen Schwartz 2024-11-15 21:53:58 -05:00
parent e141263b7e
commit 40734184af
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
11 changed files with 89 additions and 53 deletions

View file

@ -1,22 +0,0 @@
// messageHandlers/chat.ts
import { MessageHandler } from "../ws";
export const handleNewtMessage: MessageHandler = async (context) => {
const { message, senderNewtId, sendToClient } = context;
// Process chat message
// ... your chat logic here ...
// Example response
return {
message: {
type: 'newt_response',
data: {
originalMessage: message.data,
timestamp: new Date().toISOString()
}
},
broadcast: false, // Send to all clients
excludeSender: false // Include sender in broadcast
};
};

View file

@ -0,0 +1,42 @@
import db from "@server/db";
import { MessageHandler } from "../ws";
import { sites } from "@server/db/schema";
import { eq } from "drizzle-orm";
export const handleRegisterMessage: MessageHandler = async (context) => {
const { message, newt, sendToClient } = context;
if (!newt) {
console.log("Newt not found");
return;
}
if (!newt.siteId) {
console.log("Newt has no site!"); // TODO: Maybe we create the site here?
return;
}
const siteId = newt.siteId;
// get the site
const site = await db
.select()
.from(sites)
.where(eq(sites.siteId, siteId))
.limit(1);
const { publicKey } = message.data;
return {
message: {
type: 'newt/wg/connect',
data: {
publicKey: 'publicKey',
}
},
broadcast: false, // Send to all clients
excludeSender: false // Include sender in broadcast
};
};

View file

@ -1,3 +1,3 @@
export * from "./createNewt";
export * from "./getToken";
export * from "./handleNewtMessage";
export * from "./handleRegisterMessage";