Skip to content

Commit

Permalink
feat(http): add abstract websocket types
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 12, 2024
1 parent 1e74c3c commit 1e2d09f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
58 changes: 57 additions & 1 deletion packages/http/src/adapter/index.d.ts
@@ -1,6 +1,62 @@
import { LookupAddress } from 'dns'
import { HTTP } from '../index.ts'

export { WebSocket }
export function loadFile(url: string): Promise<HTTP.FileResponse | undefined>
export function lookup(address: string): Promise<LookupAddress>

export namespace WebSocket {
/** The connection is not yet open. */
export const CONNECTING = 0
/** The connection is open and ready to communicate. */
export const OPEN = 1
/** The connection is in the process of closing. */
export const CLOSING = 2
/** The connection is closed. */
export const CLOSED = 3

export type ReadyState =
| typeof CONNECTING
| typeof OPEN
| typeof CLOSING
| typeof CLOSED

export interface EventMap {
open: Event
error: ErrorEvent
message: MessageEvent
close: CloseEvent
}

export interface EventListener {
(event: Event): void
}

export interface Event {
type: string
target: WebSocket
}

export interface CloseEvent extends Event {
code: number
reason: string
}

export interface MessageEvent extends Event {
data: string
}

export interface ErrorEvent extends Event {
message?: string
}
}

export interface WebSocket {
readonly url?: string
readonly protocol?: string
readonly readyState?: number
close(code?: number, reason?: string): void
send(data: string): void
dispatchEvent?(event: any): boolean
addEventListener<K extends keyof WebSocket.EventMap>(type: K, listener: (event: WebSocket.EventMap[K]) => void): void
removeEventListener<K extends keyof WebSocket.EventMap>(type: K, listener: (event: WebSocket.EventMap[K]) => void): void
}
3 changes: 0 additions & 3 deletions readme.md

This file was deleted.

0 comments on commit 1e2d09f

Please sign in to comment.