engine.io-client
- Version 6.6.3
- Published
- 863 kB
- 5 dependencies
- MIT license
Install
npm i engine.io-client
yarn add engine.io-client
pnpm add engine.io-client
Overview
Client for the realtime Engine
Index
Variables
Functions
Classes
Interfaces
SocketOptions
- addTrailingSlash
- agent
- autoUnref
- ca
- cert
- ciphers
- closeOnBeforeunload
- extraHeaders
- forceBase64
- host
- hostname
- key
- passphrase
- path
- perMessageDeflate
- pfx
- port
- protocols
- query
- rejectUnauthorized
- rememberUpgrade
- requestTimeout
- secure
- timestampParam
- timestampRequests
- transportOptions
- transports
- tryAllTransports
- upgrade
- useNativeTimers
- withCredentials
Variables
variable protocol
const protocol: number;
variable transports
const transports: { websocket: typeof WS; webtransport: typeof WT; polling: typeof XHR;};
Functions
function installTimerFunctions
installTimerFunctions: (obj: any, opts: any) => void;
function nextTick
nextTick: (callback: Function, ...args: any[]) => void;
function parse
parse: (str: string) => any;
Classes
class Fetch
class Fetch extends Polling {}
HTTP long-polling based on the built-in
fetch()
method.Usage: browser, Node.js (since v18), Deno, Bun
See Also
https://developer.mozilla.org/en-US/docs/Web/API/fetch
https://caniuse.com/fetch
https://nodejs.org/api/globals.html#fetch
class NodeWebSocket
class WS extends BaseWS {}
WebSocket transport based on the
WebSocket
object provided by thews
package.Usage: Node.js, Deno (compat), Bun (compat)
See Also
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
https://caniuse.com/mdn-api_websocket
method createSocket
createSocket: ( uri: string, protocols: string | string[] | undefined, opts: Record<string, any>) => any;
method doWrite
doWrite: (packet: Packet, data: RawData) => void;
class NodeXHR
class XHR extends BaseXHR {}
HTTP long-polling based on the
XMLHttpRequest
object provided by thexmlhttprequest-ssl
package.Usage: Node.js, Deno (compat), Bun (compat)
See Also
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
method request
request: (opts?: Record<string, any>) => Request;
class Socket
class Socket extends SocketWithUpgrade {}
This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
This class comes with an upgrade mechanism, which means that once the connection is established with the first low-level transport, it will try to upgrade to a better transport.
Example 1
import { Socket } from "engine.io-client";
const socket = new Socket();
socket.on("open", () => { socket.send("hello"); });
See Also
SocketWithoutUpgrade
SocketWithUpgrade
constructor
constructor(uri?: string, opts?: SocketOptions);
constructor
constructor(opts: SocketOptions);
class SocketWithoutUpgrade
class SocketWithoutUpgrade extends Emitter< Record<never, never>, Record<never, never>, SocketReservedEvents> {}
This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
This class comes without upgrade mechanism, which means that it will keep the first low-level transport that successfully establishes the connection.
In order to allow tree-shaking, there are no transports included, that's why the
transports
option is mandatory.Example 1
import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
const socket = new SocketWithoutUpgrade({ transports: [WebSocket] });
socket.on("open", () => { socket.send("hello"); });
See Also
SocketWithUpgrade
Socket
constructor
constructor(uri: string | BaseSocketOptions, opts: BaseSocketOptions);
Socket constructor.
Parameter uri
uri or options
Parameter opts
options
property binaryType
binaryType: BinaryType;
property id
id: string;
property opts
protected readonly opts: BaseSocketOptions;
property priorWebsocketSuccess
static priorWebsocketSuccess: boolean;
property protocol
static protocol: number;
property readyState
readyState: SocketState;
property setTimeoutFn
protected setTimeoutFn: ( handler: TimerHandler, timeout?: number, ...arguments: any[]) => number;
property transport
transport: Transport;
property transports
protected readonly transports: string[];
property upgrading
protected upgrading: boolean;
property writeBuffer
writeBuffer: Packet[];
method close
close: () => this;
Closes the connection.
method createTransport
protected createTransport: (name: string) => Transport;
Creates transport of the given type.
Parameter name
transport name {Transport}
method flush
protected flush: () => void;
Flush write buffers.
method onHandshake
protected onHandshake: (data: HandshakeData) => void;
Called upon handshake completion.
Parameter data
handshake obj
method onOpen
protected onOpen: () => void;
Called when connection is deemed open.
method send
send: (msg: RawData, options?: WriteOptions, fn?: () => void) => this;
Sends a message. Alias of Socket#write.
Parameter msg
message.
Parameter
{Object} options.
Parameter fn
callback function. {Socket} for chaining.
method setTransport
protected setTransport: (transport: Transport) => void;
Sets the current transport. Disables the existing one (if any).
method write
write: (msg: RawData, options?: WriteOptions, fn?: () => void) => this;
Sends a message.
Parameter msg
message.
Parameter
{Object} options.
Parameter fn
callback function. {Socket} for chaining.
class SocketWithUpgrade
class SocketWithUpgrade extends SocketWithoutUpgrade {}
This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
This class comes with an upgrade mechanism, which means that once the connection is established with the first low-level transport, it will try to upgrade to a better transport.
In order to allow tree-shaking, there are no transports included, that's why the
transports
option is mandatory.Example 1
import { SocketWithUpgrade, WebSocket } from "engine.io-client";
const socket = new SocketWithUpgrade({ transports: [WebSocket] });
socket.on("open", () => { socket.send("hello"); });
See Also
SocketWithoutUpgrade
Socket
method onHandshake
onHandshake: (data: HandshakeData) => void;
method onOpen
onOpen: () => void;
class Transport
abstract class Transport extends Emitter< Record<never, never>, Record<never, never>, TransportReservedEvents> {}
constructor
constructor(opts: any);
Transport abstract constructor.
Parameter opts
options
property name
readonly name: string;
The name of the transport
property opts
protected opts: SocketOptions;
property query
query: Record<string, string>;
property readyState
protected readyState: TransportState;
property setTimeoutFn
protected setTimeoutFn: ( handler: TimerHandler, timeout?: number, ...arguments: any[]) => number;
property socket
protected socket: Socket;
property supportsBinary
protected supportsBinary: boolean;
property writable
writable: boolean;
method close
close: () => this;
Closes the transport.
method createUri
protected createUri: (schema: string, query?: Record<string, unknown>) => string;
method doClose
protected abstract doClose: () => any;
method doOpen
protected abstract doOpen: () => any;
method onClose
protected onClose: (details?: CloseDetails) => void;
Called upon close.
method onData
protected onData: (data: RawData) => void;
Called with data.
Parameter data
method onError
protected onError: (reason: string, description: any, context?: any) => this;
Emits an error.
Parameter reason
Parameter description
Parameter context
the error context {Transport} for chaining
method onOpen
protected onOpen: () => void;
Called upon open
method onPacket
protected onPacket: (packet: Packet) => void;
Called with a decoded packet.
method open
open: () => this;
Opens the transport.
method pause
pause: (onPause: () => void) => void;
Pauses the transport, in order not to lose packets during an upgrade.
Parameter onPause
method send
send: (packets: any) => void;
Sends multiple packets.
Parameter packets
method write
protected abstract write: (packets: Packet[]) => any;
class TransportError
class TransportError extends Error {}
constructor
constructor(reason: string, description: any, context: any);
property context
readonly context: any;
property description
readonly description: any;
property type
readonly type: string;
class WebSocket
class WS extends BaseWS {}
WebSocket transport based on the built-in
WebSocket
object.Usage: browser, Node.js (since v21), Deno, Bun
See Also
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
https://caniuse.com/mdn-api_websocket
https://nodejs.org/api/globals.html#websocket
method createSocket
createSocket: ( uri: string, protocols: string | string[] | undefined, opts: Record<string, any>) => any;
method doWrite
doWrite: (_packet: Packet, data: RawData) => void;
class WebTransport
class WT extends Transport {}
WebTransport transport based on the built-in
WebTransport
object.Usage: browser, Node.js (with the
@fails-components/webtransport
package)See Also
https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
https://caniuse.com/webtransport
class XHR
class XHR extends BaseXHR {}
HTTP long-polling based on the built-in
XMLHttpRequest
object.Usage: browser
See Also
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
constructor
constructor(opts: any);
method request
request: (opts?: Record<string, any>) => Request;
Interfaces
interface SocketOptions
interface SocketOptions {}
property addTrailingSlash
addTrailingSlash?: boolean;
Whether we should add a trailing slash to the request path. true
property agent
agent?: string | boolean;
http.Agent
to use, defaults tofalse
(NodeJS only)Note: the type should be "undefined | http.Agent | https.Agent | false", but this would break browser-only clients.
See Also
https://nodejs.org/api/http.html#httprequestoptions-callback
property autoUnref
autoUnref?: boolean;
Whether the heartbeat timer should be unref'ed, in order not to keep the Node.js event loop active.
See Also
https://nodejs.org/api/timers.html#timeoutunref false
property ca
ca?: string | string[];
(SSL) An authority certificate or array of authority certificates to check the remote host against.. Can be used in Node.js client environment to manually specify certificate information.
property cert
cert?: string;
(SSL) Public x509 certificate to use. Can be used in Node.js client environment to manually specify certificate information.
property ciphers
ciphers?: string;
(SSL) A string describing the ciphers to use or exclude. Consult the [cipher format list] (http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT) for details on the format.. Can be used in Node.js client environment to manually specify certificate information.
property closeOnBeforeunload
closeOnBeforeunload?: boolean;
Whether to automatically close the connection whenever the beforeunload event is received. false
property extraHeaders
extraHeaders?: { [header: string]: string;};
Headers that will be passed for each request to the server (via xhr-polling and via websockets). These values then can be used during handshake or for special proxies.
property forceBase64
forceBase64?: boolean;
Forces base 64 encoding for polling transport even when XHR2 responseType is available and WebSocket even if the used standard supports binary.
property host
host?: string;
The host that we're connecting to. Set from the URI passed when connecting
property hostname
hostname?: string;
The hostname for our connection. Set from the URI passed when connecting
property key
key?: string;
(SSL) Private key to use for SSL. Can be used in Node.js client environment to manually specify certificate information.
property passphrase
passphrase?: string;
(SSL) A string or passphrase for the private key or pfx. Can be used in Node.js client environment to manually specify certificate information.
property path
path?: string;
The path to get our client file from, in the case of the server serving it '/engine.io'
property perMessageDeflate
perMessageDeflate?: { threshold: number;};
parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable. false
property pfx
pfx?: string;
(SSL) Certificate, Private key and CA certificates to use for SSL. Can be used in Node.js client environment to manually specify certificate information.
property port
port?: string | number;
The port for our connection. Set from the URI passed when connecting
property protocols
protocols?: string | string[];
Either a single protocol string or an array of protocol strings. These strings are used to indicate sub-protocols, so that a single server can implement multiple WebSocket sub-protocols (for example, you might want one server to be able to handle different types of interactions depending on the specified protocol) []
property query
query?: { [key: string]: any;};
Any query parameters in our uri. Set from the URI passed when connecting
property rejectUnauthorized
rejectUnauthorized?: boolean;
(SSL) If true, the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails. Verification happens at the connection level, before the HTTP request is sent. Can be used in Node.js client environment to manually specify certificate information.
property rememberUpgrade
rememberUpgrade?: boolean;
If true and if the previous websocket connection to the server succeeded, the connection attempt will bypass the normal upgrade process and will initially try websocket. A connection attempt following a transport error will use the normal upgrade process. It is recommended you turn this on only when using SSL/TLS connections, or if you know that your network does not block websockets. false
property requestTimeout
requestTimeout?: number;
Timeout for xhr-polling requests in milliseconds (0) (only for polling transport)
property secure
secure?: boolean;
If this is a secure connection. Set from the URI passed when connecting
property timestampParam
timestampParam?: string;
The param name to use as our timestamp key 't'
property timestampRequests
timestampRequests?: boolean;
Whether to add the timestamp with each transport request. Note: this is ignored if the browser is IE or Android, in which case requests are always stamped false
property transportOptions
transportOptions?: Object;
Transport options for Node.js client (headers etc)
property transports
transports?: | ('polling' | 'websocket' | 'webtransport' | string)[] | TransportCtor[];
A list of transports to try (in order). Engine.io always attempts to connect directly with the first one, provided the feature detection test for it passes.
['polling','websocket', 'webtransport']
property tryAllTransports
tryAllTransports?: boolean;
Whether all the transports should be tested, instead of just the first one.
If set to
true
, the client will first try to connect with HTTP long-polling, and then with WebSocket in case of failure, and finally with WebTransport if the previous attempts have failed.If set to
false
(default), if the connection with HTTP long-polling fails, then the client will not test the other transports and will abort the connection.false
property upgrade
upgrade?: boolean;
Whether the client should try to upgrade the transport from long-polling to something better. true
property useNativeTimers
useNativeTimers?: boolean;
Whether to always use the native timeouts. This allows the client to reconnect when the native timeout functions are overridden, such as when mock clocks are installed. false
property withCredentials
withCredentials?: boolean;
Whether to include credentials (cookies, authorization headers, TLS client certificates, etc.) with cross-origin XHR polling requests false
Package Files (13)
- build/esm/contrib/parseuri.d.ts
- build/esm/globals.node.d.ts
- build/esm/index.d.ts
- build/esm/socket.d.ts
- build/esm/transport.d.ts
- build/esm/transports/index.d.ts
- build/esm/transports/polling-fetch.d.ts
- build/esm/transports/polling-xhr.d.ts
- build/esm/transports/polling-xhr.node.d.ts
- build/esm/transports/websocket.d.ts
- build/esm/transports/websocket.node.d.ts
- build/esm/transports/webtransport.d.ts
- build/esm/util.d.ts
Dependencies (5)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/engine.io-client
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/engine.io-client)
- HTML<a href="https://www.jsdocs.io/package/engine.io-client"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4041 ms. - Missing or incorrect documentation? Open an issue for this package.