Skip to content

Commit

Permalink
add: webSocketController for tying
Browse files Browse the repository at this point in the history
  • Loading branch information
Celesca committed Nov 25, 2024
1 parent 72d6d2d commit 9652449
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/controllers/webSocketController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Elysia, t } from "elysia";

export const webSocketController = new Elysia({ prefix: "/ws" })
.ws("/", {
// validate incoming message
body: t.Object({
message: t.String()
}),
query: t.Object({
id: t.String()
}),
// handle incoming message
message(ws, { message }) {
// Get schma from 'ws.data'
const { id } = ws.data.query;
ws.send({
id,
message,
time: Date.now()
})
}
})
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { hackathonController } from "./controllers/hackathonController";
import { teamController } from "./controllers/teamController";
import { ratingController } from "./controllers/ratingController";
import { personalController } from "./controllers/personalController";
import { webSocketController } from "./controllers/webSocketController";

const app = new Elysia()
.get("/", () => "Hello Elysia")
Expand Down

0 comments on commit 9652449

Please sign in to comment.