mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-15 18:25:37 +02:00
fix: Move more directories
This commit is contained in:
28
cloud/packages/functions/src/api/realtime/actor-core.ts
Normal file
28
cloud/packages/functions/src/api/realtime/actor-core.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { actor } from "actor-core";
|
||||
|
||||
// Define a chat room actor
|
||||
const chatRoom = actor({
|
||||
// Initialize state when the actor is first created
|
||||
createState: () => ({
|
||||
messages: [] as any[],
|
||||
}),
|
||||
|
||||
// Define actions clients can call
|
||||
actions: {
|
||||
// Action to send a message
|
||||
sendMessage: (c, sender, text) => {
|
||||
// Update state
|
||||
c.state.messages.push({ sender, text });
|
||||
|
||||
// Broadcast to all connected clients
|
||||
c.broadcast("newMessage", { sender, text });
|
||||
},
|
||||
|
||||
// Action to get chat history
|
||||
getHistory: (c) => {
|
||||
return c.state.messages;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default chatRoom;
|
||||
28
cloud/packages/functions/src/api/realtime/index.ts
Normal file
28
cloud/packages/functions/src/api/realtime/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { setup } from "actor-core";
|
||||
import chatRoom from "./actor-core";
|
||||
import { createRouter } from "@actor-core/bun";
|
||||
import {
|
||||
FileSystemGlobalState,
|
||||
FileSystemActorDriver,
|
||||
FileSystemManagerDriver,
|
||||
} from "@actor-core/file-system";
|
||||
|
||||
export namespace Realtime {
|
||||
const app = setup({
|
||||
actors: { chatRoom },
|
||||
basePath: "/realtime"
|
||||
});
|
||||
|
||||
const fsState = new FileSystemGlobalState("/tmp");
|
||||
|
||||
const realtimeRouter = createRouter(app, {
|
||||
topology: "standalone",
|
||||
drivers: {
|
||||
manager: new FileSystemManagerDriver(app, fsState),
|
||||
actor: new FileSystemActorDriver(fsState),
|
||||
}
|
||||
});
|
||||
|
||||
export const route = realtimeRouter.router;
|
||||
export const webSocketHandler = realtimeRouter.webSocketHandler;
|
||||
}
|
||||
Reference in New Issue
Block a user