You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.5 KiB
38 lines
1.5 KiB
import type * as http from 'http'; |
|
import type * as ws from 'ws'; |
|
import { ServerOptions } from '../server.mjs'; |
|
import { ConnectionInitMessage, Disposable } from '../common.mjs'; |
|
type WebSocket = typeof ws.prototype; |
|
type WebSocketServer = ws.Server; |
|
/** |
|
* The extra that will be put in the `Context`. |
|
* |
|
* @category Server/ws |
|
*/ |
|
export interface Extra { |
|
/** |
|
* The actual socket connection between the server and the client. |
|
*/ |
|
readonly socket: WebSocket; |
|
/** |
|
* The initial HTTP upgrade request before the actual |
|
* socket and connection is established. |
|
*/ |
|
readonly request: http.IncomingMessage; |
|
} |
|
/** |
|
* Use the server on a [ws](https://github.com/websockets/ws) ws server. |
|
* This is a basic starter, feel free to copy the code over and adjust it to your needs |
|
* |
|
* @category Server/ws |
|
*/ |
|
export declare function useServer<P extends ConnectionInitMessage['payload'] = ConnectionInitMessage['payload'], E extends Record<PropertyKey, unknown> = Record<PropertyKey, never>>(options: ServerOptions<P, Extra & Partial<E>>, ws: WebSocketServer, |
|
/** |
|
* The timeout between dispatched keep-alive messages. Internally uses the [ws Ping and Pongs]((https://developer.mozilla.org/en-US/docs/Web/API/wss_API/Writing_ws_servers#Pings_and_Pongs_The_Heartbeat_of_wss)) |
|
* to check that the link between the clients and the server is operating and to prevent the link |
|
* from being broken due to idling. |
|
* |
|
* @default 12_000 // 12 seconds |
|
*/ |
|
keepAlive?: number): Disposable; |
|
export {};
|
|
|