/** * Copyright 2025 Angus.Fenying * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import * as NodeHttp from 'node:http'; import * as NodeHttps from 'node:https'; import * as cL from './Constants'; import type * as dL from './Decl'; /** * The handshake options for WebSocket client. */ export interface IClientHandshakeOptions { /** * The sub-protocols to be requested. * * If not specified, no sub-protocol will be requested. * When the server can not recognize any of the requested sub-protocols, * it might reject the handshake. */ subProtocols?: string[]; } /** * The connection options for WebSocket client. */ export interface IWsConnectOptionsBase { /** * The timeout for connecting to the server. * * @see cL.DEFAULT_CONNECT_TIMEOUT */ connectTimeout?: number; /** * The mode of receiving frames. * * @see cL.EFrameReceiveMode.STANDARD */ frameReceiveMode?: cL.EFrameReceiveMode; /** * The maximum size of each message. * * @see cL.DEFAULT_MAX_MESSAGE_SIZE */ maxMessageSize?: number; /** * The options for the handshake. * * @default {} */ wsHandshakeOpts?: IClientHandshakeOptions; /** * Whether to force a new connection. * * > In some case, the underlying HTTP/HTTPS agent may reuse an existing * > connection in the connection pool. This may cause some issues like * > CONN_RESET during the handshake. If you meet such issues, set this * > option to `true` to force a new connection. * * @default true */ forceNewConnection?: boolean; } /** * The type for the options of secure WebSocket client. * This type is the combination of `https.RequestOptions` and * `IWsConnectOptionsBase`. * * @see {@link IWsConnectOptionsBase} * * @noInheritDoc */ export interface IWssConnectOptions extends NodeHttps.RequestOptions, IWsConnectOptionsBase { } /** * The type for the options of plain WebSocket client. * This type is the combination of `http.RequestOptions` and * `IWsConnectOptionsBase`. * * @see {@link IWsConnectOptionsBase} * * @noInheritDoc */ export interface IWsConnectOptions extends NodeHttp.RequestOptions, IWsConnectOptionsBase { } /** * Establish a WebSocket connection to a server via HTTPS. * * @param opts The options for the connection. * * @returns The promise of the WebSocket client. * * @deprecated Use `createSecureClient` method instead, because the client can * not process early data sent by server correctly if you use this method. And * this method will be removed in the future. */ export declare function wssConnect(opts: IWssConnectOptions): Promise; /** * Establish a WebSocket connection to a server via plain HTTP. * * @param opts The options for the connection. * * @returns The promise of the WebSocket client. * * @deprecated Use `createClient` method instead, because the client can not * process early data sent by server correctly if you use this method. And this * method will be removed in the future. */ export declare function wsConnect(opts: IWsConnectOptions): Promise; /** * Create a WebSocket client via HTTPS. * * > The client will not connect to the server automatically. You need to call * > the `connect` method to establish the connection. * > Before calling `connect`, you must setup the event listeners to handle * > the events emitted during the connection. * * @param opts The options for the connection. * * @returns The secure WebSocket client. */ export declare function createSecureClient(opts: IWssConnectOptions): dL.IClient; /** * Create a WebSocket client via plain HTTP. * * > The client will not connect to the server automatically. You need to call * > the `connect` method to establish the connection. * > Before calling `connect`, you must setup the event listeners to handle * > the events emitted during the connection. * * @param opts The options for the connection. * * @returns The plain WebSocket client. */ export declare function createClient(opts: IWsConnectOptions): dL.IClient; //# sourceMappingURL=Client.d.ts.map