ziron-client
Version:
197 lines (196 loc) • 6.6 kB
TypeScript
import { ClientOptions as WSClientOptions } from "ws";
import TokenStore from "../main/tokenStore/TokenStore";
export interface AutoReconnectOptions {
/**
* @description
* Defines if the client should try to reconnect to the server when the connection is lost.
* Notice that the client will automatically resubscribe all previous channels.
* @default true
*/
active?: boolean;
/**
* @description
* Initial delay in milliseconds.
* @default 5000
*/
initialDelay?: number;
/**
* @description
* Randomness in milliseconds.
* @default 5000
*/
randomness?: number;
/**
* @description
* Miltiplier (decimal)
* @default 1.5
*/
multiplier?: number;
/**
* @description
* Max delay in milliseconds.
* @default 60000
*/
maxDelay?: number | null;
}
export default interface SocketOptions {
/**
* @description
* The hostname where the client should connect to.
* @default The current host (from the URL) or localhost.
*/
hostname?: string;
/**
* @description
* The port where the client should connect to.
* @default Port from the current URL if it fails it is 80 or 443 if the secure option is true.
*/
port?: number;
/**
* @description
* Indicates if the client should use TLS (SSL) to create a secure connection to the server.
* @default Is true if the current protocol of the URL is https.
*/
secure?: boolean;
/**
* @description
* The URL path where the server processes ws handshakes.
* Notice multiple slashes at the end are not supported and will be removed.
* @default '/'.
*/
path?: string;
/**
* @description
* Specifies options for the auto reconnect feature.
* @default
* {
* active: true,
* initialDelay: 5000,
* multiplier: 1.5,
* randomness: 5000,
* maxDelay: 60000
* }
*/
autoReconnect?: AutoReconnectOptions;
/**
* @description
* Indicates if channels should be resubscribed automatically after a reconnect.
*/
autoResubscribe?: boolean;
/**
* @description
* Specifies the default connect timeout.
* @default 20000
*/
connectTimeout?: number;
/**
* @description
* Defines the default timeout in milliseconds for
* receiving the response of an invoke.
* The timeout only starts when the data of the invoke is completely transmitted,
* and all containing streams are closed.
* Notice that an individual response timeout can be specified for
* an invoke that overrides this option value.
* @default 7000
*/
responseTimeout?: number;
/**
* @description
* Specifies the default transmit send timeout.
* The send timeout specifies the time limit in that the package should be sent.
* If the timeout is reached, the package will be rejected.
* When the connection is not open the package is pushed into the buffer.
* Soon as possible, the buffer is flushed. If the send timeout is null,
* the package will never be rejected and waits until the connection is open.
* @default null
*/
transmitSendTimeout?: null | number;
/**
* @description
* Specifies the default invoke send timeout.
* The send timeout specifies the time limit in that the package should be sent.
* If the timeout is reached, the package will be rejected.
* When the connection is not open the package is pushed into the buffer.
* Soon as possible, the buffer is flushed. If the send timeout is null,
* the package will never be rejected and waits until the connection is open.
* @default 3000
*/
invokeSendTimeout?: null | number;
/**
* @description
* This attachment will be sent to the server when
* the client is creating his connection and
* can be accessed from the server-side.
* @default undefined
*/
handshakeAttachment?: any;
/**
* @description
* Passes options to the underlying WS module socket.
* Be careful this module is only used when the Browser WebSocket is not available.
*/
wsOptions?: WSClientOptions;
/**
* @description
* Specifies the token store that is used to store the signed JSON web token.
* The client loads the store's token when no signed token
* is available in the in-memory variable.
* You can implement your own store.
* However, the client already provides an implemented
* local storage token store that uses the local storage of a browser.
* This store helps to reload the signed token when the client
* opens a new tab or reloads the site in the browser.
* @default undefined
*/
tokenStore?: TokenStore | null;
/**
* @description
* Advanced option.
* Defines a byte mark to evaluate if the socket
* write-buffer backpressure is low.
* Write streams will pause when the backpressure
* is not low and are waiting for low pressure.
* @default 209715 Bytes
*/
lowSendBackpressureMark?: number;
/**
* @description
* The maximum package buffer size in bytes.
* Whenever a package should be sent in an unconnected state or
* with a batch time, it is pushed to the buffer.
* When a new package would exceed the buffer size,
* the buffer will be flushed automatically.
* When it is not possible to flush the buffer duo to a not open state,
* an InsufficientBufferSizeError will be thrown.
* Notice that the UTF-8 byte size of string packages is only estimated.
* @default Number.POSITIVE_INFINITY
*/
maxPackageBufferSize?: number;
/**
* @description
* Advanced option.
* Defines the timeout in milliseconds for receiving
* the referenced binary content packet of a text packet.
* @default 10000
*/
binaryContentPacketTimeout?: number;
/**
* @description
* Advanced option.
* This option defines how many
* streams are allowed in a package.
* @default 20
*/
streamsPerPackageLimit?: number;
/**
* @description
* Advanced option.
* This option species if chunks
* of streams can contain streams.
* @default false
*/
chunksCanContainStreams?: boolean;
}
export declare const DEFAULT_HOSTNAME: string;
export declare const DEFAULT_SECURE: boolean;
export declare function getDefaultPort(secure: boolean): number;