-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): add abstract websocket types
- Loading branch information
Showing
2 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |