Skip to content

Commit

Permalink
Extends WSContext's types
Browse files Browse the repository at this point in the history
  • Loading branch information
hayatosc committed Aug 27, 2024
1 parent f9349ec commit 84cd7cb
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/adapter/bun/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface BunWebSocketData {
protocol: string
}

const createWSContext = (ws: BunServerWebSocket<BunWebSocketData>): WSContext => {
const createWSContext = (ws: BunServerWebSocket<BunWebSocketData>): WSContext<BunServerWebSocket<BunWebSocketData>> => {
return {
send: (source, options) => {
const sendingData =
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/cloudflare-workers/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const upgradeWebSocket: UpgradeWebSocket = (createEvents) => async (c, ne
const client: WebSocket = webSocketPair[0]
const server: WebSocket = webSocketPair[1]

const wsContext: WSContext = {
const wsContext: WSContext<WebSocket> = {
binaryType: 'arraybuffer',
close: (code, reason) => server.close(code, reason),
get protocol() {
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/deno/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const upgradeWebSocket: UpgradeWebSocket<UpgradeWebSocketOptions> =
const events = await createEvents(c)
const { response, socket } = Deno.upgradeWebSocket(c.req.raw, options || {})

const wsContext: WSContext = {
const wsContext: WSContext<WebSocket> = {
binaryType: 'arraybuffer',
close: (code, reason) => socket.close(code, reason),
get protocol() {
Expand Down
4 changes: 2 additions & 2 deletions src/helper/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export type UpgradeWebSocket<T = any> = (

export type WSReadyState = 0 | 1 | 2 | 3

export type WSContext = {
export type WSContext<T = unknown> = {
send(
source: string | ArrayBuffer | Uint8Array,
options?: {
compress: boolean
}
): void
raw?: unknown
raw?: T
binaryType: BinaryType
readyState: WSReadyState
url: URL | null
Expand Down

0 comments on commit 84cd7cb

Please sign in to comment.