Skip to content

Commit ba7018e

Browse files
committed
🎉 feat: ws
1 parent 0edc913 commit ba7018e

File tree

4 files changed

+11
-198
lines changed

4 files changed

+11
-198
lines changed

example/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const app = new Elysia({
99
})
1010
.use(cors())
1111
.use(swagger())
12-
.ws('/ws', {
13-
open() {
14-
console.log('OPENED')
12+
.ws('/ws/:id', {
13+
open({ data }) {
14+
console.log(data.params)
1515
},
1616
message(ws, message) {
1717
ws.send(message)

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ import { ServerWebSocket } from 'elysia/ws/bun'
3838
import { parseSetCookies } from 'elysia/adapter/utils'
3939

4040
const toServerWebSocket = (ws: ServerWebSocket) => {
41-
// @ts-ignore
42-
ws.data = ws.context
41+
// @ts-ignore, context.context is intentional
42+
// first context is srvx.context (alias of bun.ws.data)
43+
// second context is Elysia context
44+
ws.data = ws.context.context
4345
ws.sendText = ws.send
4446
ws.sendBinary = ws.send
4547
ws.publishText = ws.publish

src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import type { Context } from 'elysia/context'
2-
import { isNotEmpty } from 'elysia/utils'
1+
import { FastResponse as Response } from 'srvx'
32
import type { ReadStream } from 'fs'
43

4+
import { isNotEmpty } from 'elysia/utils'
5+
import type { Context } from 'elysia/context'
6+
57
export const handleFile = (
68
response: ReadStream | File | Blob,
79
set?: Context['set']

src/ws.ts

Lines changed: 0 additions & 191 deletions
This file was deleted.

0 commit comments

Comments
 (0)