node-opcua-transport
Version:
pure nodejs OPCUA SDK - module transport
65 lines (64 loc) • 3.15 kB
TypeScript
/**
* @module node-opcua-transport
*
* Transport-agnostic base class for client-side OPC UA transports.
*
* Owns the UACP HEL/ACK handshake, the negotiated transport settings, and the
* post-connect connection-break detector. Concrete subclasses (`ClientTCP_transport`,
* `ClientWS_transport`, ...) implement only the socket-creation step in `connect()`.
*
* Browser-safe: does not import `node:net`, `node:os`, `node:util`, or any other
* Node-only built-in beyond what `TCP_transport` already inherits from `node:events`.
*/
import type { ErrorCallback } from "node-opcua-status-code";
import { AcknowledgeMessage } from "./AcknowledgeMessage";
import type { TransportSettingsOptions } from "./i_client_transport";
import { TCP_transport } from "./tcp_transport";
export interface ClientTransportBase {
on(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
on(eventName: "close", eventHandler: (err: Error | null) => void): this;
on(eventName: "connection_break", eventHandler: (err: Error | null) => void): this;
on(eventName: "connect", eventHandler: () => void): this;
once(eventName: "chunk", eventHandler: (messageChunk: Buffer) => void): this;
once(eventName: "close", eventHandler: (err: Error | null) => void): this;
once(eventName: "connection_break", eventHandler: (err: Error | null) => void): this;
once(eventName: "connect", eventHandler: () => void): this;
emit(eventName: "chunk", messageChunk: Buffer): boolean;
emit(eventName: "close", err?: Error | null): boolean;
emit(eventName: "connection_break", err?: Error | null): boolean;
emit(eventName: "connect"): boolean;
}
export declare abstract class ClientTransportBase extends TCP_transport {
static defaultMaxChunk: number;
static defaultMaxMessageSize: number;
static defaultReceiveBufferSize: number;
static defaultSendBufferSize: number;
endpointUrl: string;
serverUri: string;
numberOfRetry: number;
parameters?: AcknowledgeMessage;
private _counter;
private _helloSettings;
constructor(transportSettings?: TransportSettingsOptions);
getTransportSettings(): TransportSettingsOptions;
dispose(): void;
/**
* Connect to `endpointUrl` and perform the UACP HEL/ACK handshake.
* Concrete subclasses are responsible for opening the underlying socket
* (TCP, WebSocket, ...) and then driving the inherited HEL/ACK machinery.
*/
abstract connect(endpointUrl: string, callback: ErrorCallback): void;
/**
* Install the post-connect "connection break" detector. Subclasses call this
* once the underlying socket is open and the HEL/ACK transaction has succeeded.
*
* Detects ECONNRESET / EPIPE / premature socket termination on the live socket
* and re-emits them as `connection_break` so reconnection logic upstream can
* react.
*/
protected _install_post_connect_error_handler(endpointUrl: string): void;
protected _perform_HEL_ACK_transaction(callback: ErrorCallback): void;
private _send_HELLO_request;
private _on_ACK_response;
private _handle_ACK_response;
}