mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 18:14:53 +02:00
Newt registration?
This commit is contained in:
parent
e141263b7e
commit
40734184af
11 changed files with 89 additions and 53 deletions
|
@ -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
|
||||
};
|
||||
};
|
42
server/routers/newt/handleRegisterMessage.ts
Normal file
42
server/routers/newt/handleRegisterMessage.ts
Normal 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
|
||||
};
|
||||
};
|
|
@ -1,3 +1,3 @@
|
|||
export * from "./createNewt";
|
||||
export * from "./getToken";
|
||||
export * from "./handleNewtMessage";
|
||||
export * from "./handleRegisterMessage";
|
Loading…
Add table
Add a link
Reference in a new issue