From f246c246d0ea00af51ca2a2ff87551939b66f2f0 Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sat, 10 Apr 2021 23:35:56 +0200 Subject: [PATCH] Revert "Updated TypeScript to allow defined user data (#312)" This reverts commit 61fa4bd06cf9db078716dc0c70bc5e8274d742f6. --- docs/index.d.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/docs/index.d.ts b/docs/index.d.ts index 6ecc3e0..bcca745 100644 --- a/docs/index.d.ts +++ b/docs/index.d.ts @@ -40,10 +40,7 @@ export type RecognizedString = string | ArrayBuffer | Uint8Array | Int8Array | U /** A WebSocket connection that is valid from open to close event. * Read more about this in the user manual. */ -export type WebSocket = { +export interface WebSocket { /** Sends a message. Make sure to check getBufferedAmount() before sending. Returns true for success, false for built up backpressure that will drain when time is given. * Returning false does not mean nothing was sent, it only means backpressure was built up. This you can check by calling getBufferedAmount() afterwards. * @@ -111,7 +108,9 @@ export type WebSocket { +export interface WebSocketBehavior { /** Maximum length of received message. If a client tries to send you a message larger than this, the connection is immediately closed. Defaults to 16 * 1024. */ maxPayloadLength?: number; /** Maximum amount of seconds that may pass without sending or getting a message. Connection is closed if this timeout passes. Resolution (granularity) for timeouts are typically 4 seconds, rounded to closest. @@ -233,17 +232,17 @@ export interface WebSocketBehavior { */ upgrade?: (res: HttpResponse, req: HttpRequest, context: us_socket_context_t) => void; /** Handler for new WebSocket connection. WebSocket is valid from open to close, no errors. */ - open?: (ws: WebSocket) => void; + open?: (ws: WebSocket) => void; /** Handler for a WebSocket message. Messages are given as ArrayBuffer no matter if they are binary or not. Given ArrayBuffer is valid during the lifetime of this callback (until first await or return) and will be neutered. */ - message?: (ws: WebSocket, message: ArrayBuffer, isBinary: boolean) => void; + message?: (ws: WebSocket, message: ArrayBuffer, isBinary: boolean) => void; /** Handler for when WebSocket backpressure drains. Check ws.getBufferedAmount(). Use this to guide / drive your backpressure throttling. */ - drain?: (ws: WebSocket) => void; + drain?: (ws: WebSocket) => void; /** Handler for close event, no matter if error, timeout or graceful close. You may not use WebSocket after this event. Do not send on this WebSocket from within here, it is closed. */ - close?: (ws: WebSocket, code: number, message: ArrayBuffer) => void; + close?: (ws: WebSocket, code: number, message: ArrayBuffer) => void; /** Handler for received ping control message. You do not need to handle this, pong messages are automatically sent as per the standard. */ - ping?: (ws: WebSocket) => void; + ping?: (ws: WebSocket) => void; /** Handler for received pong control message. */ - pong?: (ws: WebSocket) => void; + pong?: (ws: WebSocket) => void; } /** Options used when constructing an app. Especially for SSLApp. @@ -292,7 +291,7 @@ export interface TemplatedApp { /** Registers an HTTP handler matching specified URL pattern on any HTTP method. */ any(pattern: RecognizedString, handler: (res: HttpResponse, req: HttpRequest) => void) : TemplatedApp; /** Registers a handler matching specified URL pattern where WebSocket upgrade requests are caught. */ - ws(pattern: RecognizedString, behavior: WebSocketBehavior) : TemplatedApp; + ws(pattern: RecognizedString, behavior: WebSocketBehavior) : TemplatedApp; /** Publishes a message under topic, for all WebSockets under this app. See WebSocket.publish. */ publish(topic: RecognizedString, message: RecognizedString, isBinary?: boolean, compress?: boolean) : TemplatedApp; }