/** * @module node-opcua-client-private */ import { EventEmitter } from "events"; import type { DateTime } from "node-opcua-basic-types"; import { type ExtraDataTypeManager } from "node-opcua-client-dynamic-extension-object"; import type { AggregateFunction } from "node-opcua-constants"; import type { Certificate, Nonce } from "node-opcua-crypto/web"; import { type LocalizedTextLike } from "node-opcua-data-model"; import { DataValue } from "node-opcua-data-value"; import type { ExtensionObject } from "node-opcua-extension-object"; import { NodeId, type NodeIdLike } from "node-opcua-nodeid"; import { type BrowseDescriptionLike, type IBasicTransportSettings, type NodeAttributes, type ResponseCallback } from "node-opcua-pseudo-session"; import type { AnyConstructorFunc } from "node-opcua-schemas"; import { type SignatureData } from "node-opcua-secure-channel"; import { BrowseResult } from "node-opcua-service-browse"; import { type CallMethodResult } from "node-opcua-service-call"; import type { EndpointDescription } from "node-opcua-service-endpoints"; import { HistoryReadRequest, HistoryReadResponse, type HistoryReadResult } from "node-opcua-service-history"; import { QueryFirstResponse } from "node-opcua-service-query"; import { type ReadValueIdOptions } from "node-opcua-service-read"; import { CreateMonitoredItemsResponse, CreateSubscriptionResponse, DeleteMonitoredItemsResponse, DeleteSubscriptionsResponse, ModifyMonitoredItemsResponse, ModifySubscriptionResponse, PublishRequest, PublishResponse, RepublishRequest, RepublishResponse, SetMonitoringModeResponse, type SetTriggeringRequestOptions, SetTriggeringResponse, TransferSubscriptionsResponse } from "node-opcua-service-subscription"; import { type BrowsePath, type BrowsePathResult } from "node-opcua-service-translate-browse-path"; import { type Callback, type CallbackT, type ErrorCallback, type StatusCode } from "node-opcua-status-code"; import { type AggregateConfigurationOptions, type HistoryReadValueIdOptions, type WriteValueOptions } from "node-opcua-types"; import { type VariantLike } from "node-opcua-variant"; import type { ArgumentDefinition, CallMethodRequestLike, ClientSession, CreateMonitoredItemsRequestLike, CreateSubscriptionRequestLike, DeleteMonitoredItemsRequestLike, DeleteSubscriptionsRequestLike, ExtraReadHistoryValueParameters, HistoryReadValueIdOptions2, MethodId, ModifyMonitoredItemsRequestLike, ModifySubscriptionRequestLike, MonitoredItemData, QueryFirstRequestLike, SetMonitoringModeRequestLike, SubscriptionId, TransferSubscriptionsRequestLike } from "../client_session"; import type { ClientSubscription } from "../client_subscription"; import type { Request, Response } from "../common"; import type { UserIdentityInfo } from "../user_identity_info"; import { ClientSidePublishEngine } from "./client_publish_engine"; import type { IClientBase } from "./i_private_client"; type EmptyCallback = (err?: Error) => void; export interface Reconnectable { _reconnecting: { reconnecting: boolean; pendingCallbacks: EmptyCallback[]; pendingTransactions: { request: Request; callback: (err: Error | null, response?: Response) => void; }[]; }; } /** * @class ClientSession */ export declare class ClientSessionImpl extends EventEmitter implements ClientSession, Reconnectable { #private; static reconnectingElement: WeakMap; timeout: number; authenticationToken?: NodeId; requestedMaxReferencesPerNode: number; sessionId: NodeId; lastRequestSentTime: Date; lastResponseReceivedTime: Date; serverCertificate: Certificate; userIdentityInfo?: UserIdentityInfo; name: string; serverNonce?: Nonce; serverSignature?: SignatureData; serverEndpoints: EndpointDescription[]; _client: IClientBase | null; _closed: boolean; _reconnecting: { reconnecting: boolean; pendingCallbacks: EmptyCallback[]; pendingTransactions: any[]; }; /** * @internal */ _closeEventHasBeenEmitted: boolean; private _publishEngine; private _keepAliveManager?; private $$namespaceArray?; private recursive_repair_detector; constructor(client: IClientBase); getTransportSettings(): IBasicTransportSettings; /** * the endpoint on which this session is operating * @property endpoint * @type {EndpointDescription} */ get endpoint(): EndpointDescription; get subscriptionCount(): number; get isReconnecting(): boolean; toJSON(): Record; protected resolveNodeId(nodeId: NodeIdLike): NodeIdLike; getPublishEngine(): ClientSidePublishEngine; changeUser(userIdentityInfo: UserIdentityInfo): Promise; changeUser(userIdentityInfo: UserIdentityInfo, callback: CallbackT): void; /** * * @example * * ```javascript * session.browse("RootFolder",function(err,browseResult) { * if(err) return callback(err); * console.log(browseResult.toString()); * callback(); * } ); * ``` * * * @example * * ``` javascript * const browseDescription = { * nodeId: "ObjectsFolder", * referenceTypeId: "Organizes", * browseDirection: BrowseDirection.Inverse, * includeSubtypes: true, * nodeClassMask: 0, * resultMask: 63 * } * session.browse(browseDescription,function(err, browseResult) { * if(err) return callback(err); * console.log(browseResult.toString()); * callback(); * }); * ``` * @example * * ``` javascript * session.browse([ "RootFolder", "ObjectsFolder"],function(err, browseResults) { * assert(browseResults.length === 2); * }); * ``` * * @example * ``` javascript * const browseDescriptions = [ * { * nodeId: "ObjectsFolder", * referenceTypeId: "Organizes", * browseDirection: BrowseDirection.Inverse, * includeSubtypes: true, * nodeClassMask: 0, * resultMask: 63 * }, * // {...} * ] * session.browse(browseDescriptions,function(err, browseResults) { * * }); * ``` * * */ browse(nodeToBrowse: BrowseDescriptionLike, callback: ResponseCallback): void; browse(nodesToBrowse: BrowseDescriptionLike[], callback: ResponseCallback): void; browse(nodeToBrowse: BrowseDescriptionLike): Promise; browse(nodesToBrowse: BrowseDescriptionLike[]): Promise; browseNext(continuationPoint: Buffer, releaseContinuationPoints: boolean, callback: ResponseCallback): void; browseNext(continuationPoints: Buffer[], releaseContinuationPoints: boolean, callback: ResponseCallback): void; browseNext(continuationPoint: Buffer, releaseContinuationPoints: boolean): Promise; browseNext(continuationPoints: Buffer[], releaseContinuationPoints: boolean): Promise; /** * * @example * * ```javascript * session.readVariableValue("ns=2;s=Furnace_1.Temperature",function(err,dataValue) { * if(err) { return callback(err); } * if (dataValue.isGood()) { * } * console.log(dataValue.toString()); * callback(); * }); * ``` * * @example * * ```javascript * session.readVariableValue(["ns=0;i=2257","ns=0;i=2258"],function(err,dataValues) { * if (!err) { * console.log(dataValues[0].toString()); * console.log(dataValues[1].toString()); * } * }); * ``` * * @example * ```javascript * const dataValues = await session.readVariableValue(["ns=1;s=Temperature","ns=1;s=Pressure"]); * ``` * * @deprecated */ readVariableValue(nodeId: NodeIdLike, callback: ResponseCallback): void; readVariableValue(nodeIds: NodeIdLike[], callback: ResponseCallback): void; readVariableValue(nodeId: NodeIdLike): Promise; readVariableValue(nodeIds: NodeIdLike[]): Promise; /** * * @example * * ```javascript * // es5 * session.readHistoryValue( * "ns=5;s=Simulation Examples.Functions.Sine1", * "2015-06-10T09:00:00.000Z", * "2015-06-10T09:01:00.000Z", function(err,dataValues) { * * }); * ``` * * ```javascript * // es6 * const dataValues = await session.readHistoryValue( * "ns=5;s=Simulation Examples.Functions.Sine1", * "2015-06-10T09:00:00.000Z", * "2015-06-10T09:01:00.000Z"); * ``` * @param nodeToRead the read value id * @param start the start time in UTC format * @param end the end time in UTC format * @param callback */ readHistoryValue(nodesToRead: NodeIdLike[] | HistoryReadValueIdOptions2[], start: DateTime, end: DateTime, callback: (err: Error | null, results?: HistoryReadResult[]) => void): void; readHistoryValue(nodesToRead: NodeIdLike[] | HistoryReadValueIdOptions2[], start: DateTime, end: DateTime, options: ExtraReadHistoryValueParameters | undefined, callback: (err: Error | null, results?: HistoryReadResult[]) => void): void; readHistoryValue(nodesToRead: NodeIdLike[] | HistoryReadValueIdOptions2[], start: DateTime, end: DateTime, options?: ExtraReadHistoryValueParameters): Promise; readHistoryValue(nodeToRead: NodeIdLike | HistoryReadValueIdOptions2, start: DateTime, end: DateTime, callback: (err: Error | null, results?: HistoryReadResult) => void): void; readHistoryValue(nodeToRead: NodeIdLike | HistoryReadValueIdOptions2, start: DateTime, end: DateTime, options: ExtraReadHistoryValueParameters | undefined, callback: (err: Error | null, results?: HistoryReadResult) => void): void; readHistoryValue(nodeToRead: NodeIdLike | HistoryReadValueIdOptions2, start: DateTime, end: DateTime, parameters: ExtraReadHistoryValueParameters): Promise; historyRead(request: HistoryReadRequest, callback: Callback): void; historyRead(request: HistoryReadRequest): Promise; readAggregateValue(nodesToRead: HistoryReadValueIdOptions[], startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction[], processingInterval: number, callback: Callback): void; readAggregateValue(nodesToRead: HistoryReadValueIdOptions[], startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction[], processingInterval: number): Promise; readAggregateValue(nodeToRead: HistoryReadValueIdOptions, startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction, processingInterval: number, callback: Callback): void; readAggregateValue(nodeToRead: HistoryReadValueIdOptions, startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction, processingInterval: number): Promise; readAggregateValue(nodesToRead: HistoryReadValueIdOptions[], startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction[], processingInterval: number, aggregateConfiguration: AggregateConfigurationOptions, callback: Callback): void; readAggregateValue(nodesToRead: HistoryReadValueIdOptions[], startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction[], processingInterval: number, aggregateConfiguration: AggregateConfigurationOptions): Promise; readAggregateValue(nodeToRead: HistoryReadValueIdOptions, startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction, processingInterval: number, aggregateConfiguration: AggregateConfigurationOptions, callback: Callback): void; readAggregateValue(nodeToRead: HistoryReadValueIdOptions, startTime: DateTime, endTime: DateTime, aggregateFn: AggregateFunction, processingInterval: number, aggregateConfiguration: AggregateConfigurationOptions): Promise; /** * * @param nodesToWrite {WriteValue[]} - the array of value to write. One or more elements. * @param {Function} callback - the callback function * @param callback.err {object|null} the error if write has failed or null if OK * @param callback.statusCodes {StatusCode[]} - an array of status code of each write * * @example * * const nodesToWrite = [ * { * nodeId: "ns=1;s=SetPoint1", * attributeId: opcua.AttributeIds.Value, * value: { * statusCode: Good, * value: { * dataType: opcua.DataType.Double, * value: 100.0 * } * } * }, * { * nodeId: "ns=1;s=SetPoint2", * attributeIds opcua.AttributeIds.Value, * value: { * statusCode: Good, * value: { * dataType: opcua.DataType.Double, * value: 45.0 * } * } * } * ]; * session.write(nodesToWrite,function (err,statusCodes) { * if(err) { return callback(err);} * // * }); * * @param nodeToWrite {WriteValue} - the value to write * @param callback - the callback function * @param callback.err {object|null} the error if write has failed or null if OK * @param callback.statusCode {StatusCodes} - the status code of the write * * @example * * const nodeToWrite = { * nodeId: "ns=1;s=SetPoint", * attributeId: opcua.AttributeIds.Value, * value: { * statusCode: Good, * value: { * dataType: opcua.DataType.Double, * value: 100.0 * } * } * }; * session.write(nodeToWrite,function (err,statusCode) { * if(err) { return callback(err);} * // * }); * * * @param nodeToWrite {WriteValue} - the value to write * @return {Promise} * * @example * * ```javascript * session.write(nodeToWrite).then(function(statusCode) { }); * ``` * * @example * * ```javascript * const statusCode = await session.write(nodeToWrite); * ``` * * @param nodesToWrite {Array} - the value to write * @return {Promise>} * * @example * ```javascript * session.write(nodesToWrite).then(function(statusCodes) { }); * ``` * * @example * ```javascript * const statusCodes = await session.write(nodesToWrite); * ``` */ write(nodeToWrite: WriteValueOptions, callback: ResponseCallback): void; write(nodesToWrite: WriteValueOptions[], callback: ResponseCallback): void; write(nodesToWrite: WriteValueOptions[]): Promise; write(nodeToWrite: WriteValueOptions): Promise; /** * @deprecated use session.write instead * * @param nodeId {NodeId} - the node id of the node to write * @param value {Variant} - the value to write * @param callback {Function} * @param callback.err {object|null} the error if write has failed or null if OK * @param callback.statusCode {StatusCode} - the status code of the write * * @param nodeId {NodeId} - the node id of the node to write * @param value {Variant} - the value to write * @return {Promise} - the status code of the write * * * @example * // please use session.write instead of session.writeSingleNode * // as follow * const statusCode = await session.write({ * nodeId, * attributeId: AttributeIds.Value, * value: { * statusCode: Good, * sourceTimestamp: new Date(), // optional, some server may not accept this * value: { * dataType: opcua.DataType.Double, * value: 100.0 * } * } * }); * * */ writeSingleNode(nodeId: NodeIdLike, value: VariantLike, callback: ResponseCallback): void; writeSingleNode(nodeId: NodeIdLike, value: VariantLike): Promise; /** * * @example * * * ``` javascript * session.readAllAttributes("ns=2;s=Furnace_1.Temperature",function(err,data) { * if(data.statusCode.isGood()) { * console.log(" nodeId = ",data.nodeId.toString()); * console.log(" browseName = ",data.browseName.toString()); * console.log(" description = ",data.description.toString()); * console.log(" value = ",data.value.toString())); * } * }); * ``` * * @param nodes array of nodeId to read * @param node nodeId to read * @param callback */ readAllAttributes(node: NodeIdLike, callback: (err: Error | null, data?: NodeAttributes) => void): void; readAllAttributes(nodes: NodeIdLike[], callback: (err: Error | null, data?: NodeAttributes[]) => void): void; /** * * * @example * * ```javascript * ``` * * form1: reading a single node * * ``` javascript * const nodeToRead = { * nodeId: "ns=2;s=Furnace_1.Temperature", * attributeId: AttributeIds.BrowseName * }; * * session.read(nodeToRead,function(err,dataValue) { * if (!err) { * console.log(dataValue.toString()); * } * }); * ``` * * * @param nodesToRead {Array} - an array of nodeId to read or a ReadValueId * @param [maxAge] {Number} * @param callback {Function} - the callback function * @param callback.err {Error|null} - the error or null if the transaction was OK} * @param callback.dataValues {Array} * * @example * * ``` javascript * const nodesToRead = [ * { * nodeId: "ns=2;s=Furnace_1.Temperature", * attributeId: AttributeIds.BrowseName * } * ]; * session.read(nodesToRead,function(err,dataValues) { * if (!err) { * dataValues.forEach(dataValue=>console.log(dataValue.toString())); * } * }); * ``` * */ read(nodeToRead: ReadValueIdOptions, maxAge: number, callback: ResponseCallback): void; read(nodesToRead: ReadValueIdOptions[], maxAge: number, callback: ResponseCallback): void; read(nodeToRead: ReadValueIdOptions, callback: ResponseCallback): void; read(nodesToRead: ReadValueIdOptions[], callback: ResponseCallback): void; read(nodeToRead: ReadValueIdOptions, maxAge?: number): Promise; read(nodeToRead: ReadValueIdOptions[], maxAge?: number): Promise; emitCloseEvent(statusCode: StatusCode): void; createSubscription(options: CreateSubscriptionRequestLike, callback?: ResponseCallback): any; /** * @param createSubscriptionRequest * @param callback * * * subscription.on("error', function(err){ ... }); * subscription.on("terminate',function(err){ ... }); * const monitoredItem = await subscription.monitor(itemToMonitor,monitoringParameters,requestedParameters); * monitoredItem.on("changed",function( dataValue) {...}); * */ createSubscription2(createSubscriptionRequest: CreateSubscriptionRequestLike): Promise; createSubscription2(createSubscriptionRequest: CreateSubscriptionRequestLike, callback: (err: Error | null, subscription?: ClientSubscription) => void): void; deleteSubscriptions(options: DeleteSubscriptionsRequestLike, callback?: ResponseCallback): any; setTriggering(request: SetTriggeringRequestOptions, callback?: ResponseCallback): any; /** */ transferSubscriptions(options: TransferSubscriptionsRequestLike, callback?: ResponseCallback): any; createMonitoredItems(options: CreateMonitoredItemsRequestLike, callback?: ResponseCallback): any; modifyMonitoredItems(options: ModifyMonitoredItemsRequestLike, callback?: ResponseCallback): any; /** * */ modifySubscription(options: ModifySubscriptionRequestLike, callback?: ResponseCallback): any; setMonitoringMode(options: SetMonitoringModeRequestLike, callback?: ResponseCallback): any; /** */ publish(options: PublishRequest, callback: (err: Error | null, response?: PublishResponse) => void): void; /** * */ republish(options: RepublishRequest, callback: (err: Error | null, response?: RepublishResponse) => void): void; /** * */ deleteMonitoredItems(options: DeleteMonitoredItemsRequestLike, callback: (err: Error | null, response?: DeleteMonitoredItemsResponse) => void): void; /** * */ setPublishingMode(publishingEnabled: boolean, subscriptionId: SubscriptionId): Promise; setPublishingMode(publishingEnabled: boolean, subscriptionIds: SubscriptionId[]): Promise; setPublishingMode(publishingEnabled: boolean, subscriptionId: SubscriptionId, callback: (err: Error | null, statusCode?: StatusCode) => void): void; setPublishingMode(publishingEnabled: boolean, subscriptionIds: SubscriptionId[], callback: (err: Error | null, statusCodes?: StatusCode[]) => void): void; /** * */ translateBrowsePath(browsePath: BrowsePath, callback: ResponseCallback): void; translateBrowsePath(browsesPath: BrowsePath[], callback: ResponseCallback): void; translateBrowsePath(browsePath: BrowsePath): Promise; translateBrowsePath(browsePaths: BrowsePath[]): Promise; channelId(): number; isChannelValid(): boolean; performMessageTransaction(request: Request, callback: (err: Error | null, response?: Response) => void): void; _performMessageTransaction(request: Request, callback: (err: Error | null, response?: Response) => void): void; /** * evaluate the remaining time for the session * * * evaluate the time in milliseconds that the session will live * on the server end from now. * The remaining live time is calculated based on when the last message was sent to the server * and the session timeout. * * * In normal operation , when server and client communicates on a regular * basis, evaluateRemainingLifetime will return a number slightly below * session.timeout * * * when the client and server cannot communicate due to a network issue * (or a server crash), evaluateRemainingLifetime returns the estimated number * of milliseconds before the server (if not crash) will keep the session alive * on its end to allow a automatic reconnection with session. * * * When evaluateRemainingLifetime returns zero , this mean that * the session has probably ended on the server side and will have to be recreated * from scratch in case of a reconnection. * * @return the number of milliseconds before session expires */ evaluateRemainingLifetime(): number; _terminatePublishEngine(): void; /** * */ close(callback: ErrorCallback): void; close(deleteSubscription: boolean, callback: ErrorCallback): void; close(deleteSubscription?: boolean): Promise; /** * @return {Boolean} */ hasBeenClosed(): boolean; call(methodToCall: CallMethodRequestLike): Promise; call(methodToCall: CallMethodRequestLike[]): Promise; call(methodToCall: CallMethodRequestLike, callback: ResponseCallback): void; call(methodsToCall: CallMethodRequestLike[], callback: ResponseCallback): void; /** * @param subscriptionId {UInt32} the subscription Id to return * @param callback {Function} * @param callback.err {Error} * @param callback.monitoredItems the monitored Items * @param callback.monitoredItems the monitored Items */ getMonitoredItems(subscriptionId: SubscriptionId): Promise; getMonitoredItems(subscriptionId: SubscriptionId, callback: ResponseCallback): void; /** * */ getArgumentDefinition(methodId: MethodId): Promise; getArgumentDefinition(methodId: MethodId, callback: ResponseCallback): void; registerNodes(nodesToRegister: NodeIdLike[]): Promise; registerNodes(nodesToRegister: NodeIdLike[], callback: (err: Error | null, registeredNodeIds?: NodeId[]) => void): void; unregisterNodes(nodesToUnregister: NodeIdLike[]): Promise; unregisterNodes(nodesToUnregister: NodeIdLike[], callback: (err?: Error) => void): void; queryFirst(queryFirstRequest: QueryFirstRequestLike): Promise; queryFirst(queryFirstRequest: QueryFirstRequestLike, callback: ResponseCallback): void; startKeepAliveManager(keepAliveInterval?: number): void; stopKeepAliveManager(): void; dispose(): void; toString(): string; getBuiltInDataType(...args: any[]): any; readNamespaceArray(): Promise; readNamespaceArray(callback: (err: Error | null, namespaceArray?: string[]) => void): void; getNamespaceIndex(namespaceUri: string): number; disableCondition(): void; enableCondition(): void; addCommentCondition(_conditionId: NodeIdLike, _eventId: Buffer, _comment: LocalizedTextLike, _callback?: Callback): any; confirmCondition(_conditionId: NodeIdLike, _eventId: Buffer, _comment: LocalizedTextLike, _callback?: Callback): any; acknowledgeCondition(_conditionId: NodeId, _eventId: Buffer, _comment: LocalizedTextLike, _callback?: Callback): any; /** * @deprecated * @private */ findMethodId(_nodeId: NodeIdLike, _methodName: string, _callback?: ResponseCallback): any; _callMethodCondition(_methodName: string, _conditionId: NodeIdLike, _eventId: Buffer, _comment: LocalizedTextLike, _callback: Callback): void; extractNamespaceDataType(): Promise; getExtensionObjectConstructor(dataTypeNodeId: NodeId): Promise; /** * construct a Extension object from a DataType and a pojo * @param dataType * @param pojo */ constructExtensionObject(dataType: NodeId, pojo: Record): Promise; private _defaultRequest; } export {};