Optional
authenticationOptional
getthe time of the latest response received by the client
the session name
the maximum number of reference that the server should return per browseResult Continuous points will be return by server to allow retrieving remaining references with browseNext
the server certificate as provided by the server
the session Id
Optional
[captureRest
...args: AnyResthelper to acknowledge a condition
from Spec 1.03 Part 9 : page 27
The Acknowledge Method is used to acknowledge an Event Notification for a Condition instance state where AckedState is false.
Normally, the NodeId of the object instance as the ObjectId is passed to the Call Service.
However, some Servers do not expose Condition instances in the AddressSpace.
Therefore all Servers shall also allow Clients to call the Acknowledge Method by specifying ConditionId as the ObjectId.
The Method cannot be called with an ObjectId of the AcknowledgeableConditionType Node.
A Condition instance may be an Object that appears in the Server Address Space. If this is the case the ConditionId is the NodeId for the Object.
The EventId identifies a specific Event Notification where a state to be acknowledged was reported.
Acknowledgement and the optional comment will be applied to the state identified with the EventId. If the comment field is NULL (both locale and text are empty) it will be ignored and any existing comments will remain unchanged. If the comment is to be reset, an empty text with a locale shall be provided.
A valid EventId will result in an Event Notification where AckedState/Id is set to TRUE and the Comment Property contains the text of the optional comment argument. If a previous state is acknowledged, the BranchId and all Condition values of this branch will be reported.
helper to add a comment to a condition
The addComment Method is used to apply a comment to a specific state of a Condition instance.
Normally, the NodeId of the object instance as the ObjectId is passed to the Call Service.
However, some Servers do not expose Condition instances in the AddressSpace. Therefore all Servers shall also allow Clients to call the AddComment Method by specifying ConditionId as the ObjectId.
The Method cannot be called with an ObjectId of the ConditionType Node.
Alias for emitter.on(eventName, listener)
.
Rest
...args: any[]a Boolean parameter with the following values:
* true
passed continuationPoints shall be reset to free resources in
the Server. The continuation points are released and the results
and diagnosticInfos arrays are empty.
* false
passed continuationPoints shall be used to get the next set of
browse information.
A Client shall always use the continuation point returned by a Browse or
BrowseNext response to free the resources for the continuation point in the
Server. If the Client does not want to get the next set of browse information,
BrowseNext shall be called with this parameter set to true
.
{CallMethodRequest} the call method request
const methodToCall = {
objectId: "ns=2;i=12",
methodId: "ns=2;i=13",
inputArguments: [
new Variant({...}),
new Variant({...}),
]
}
session.call(methodToCall,function(err,callResult) {
if (!err) {
console.log(" statusCode = ",callResult.statusCode);
console.log(" inputArgumentResults[0] = ",callResult.inputArgumentResults[0].toString());
console.log(" inputArgumentResults[1] = ",callResult.inputArgumentResults[1].toString());
console.log(" outputArgument[0] = ",callResult.outputArgument[0].toString()); // array of variant
}
});
const methodsToCall = [ {
objectId: "ns=2;i=12",
methodId: "ns=2;i=13",
inputArguments: [
new Variant({...}),
new Variant({...}),
]
}];
session.call(methodsToCall,function(err,callResults) {
if (!err) {
const callResult = callResults[0];
console.log(" statusCode = ",rep.statusCode);
console.log(" inputArgumentResults[0] = ",callResult.inputArgumentResults[0].toString());
console.log(" inputArgumentResults[1] = ",callResult.inputArgumentResults[1].toString());
console.log(" outputArgument[0] = ",callResult.outputArgument[0].toString()); // array of variant
}
});
Optional
result: CallMethodResultOptional
results: CallMethodResult[]Optional
deleteSubscription: booleanhelper to confirm a condition
from Spec 1.03 Part 9 : page 27 The Confirm Method is used to confirm an Event Notifications for a Condition instance state where ConfirmedState is FALSE.
Normally, the NodeId of the object instance as the ObjectId is passed to the Call Service.
However, some Servers do not expose Condition instances in the AddressSpace.
Therefore all Servers shall also allow Clients to call the Confirm Method by specifying ConditionId as the ObjectId.
The Method cannot be called with an ObjectId of the AcknowledgeableConditionType Node.
Synchronously calls each of the listeners registered for the event named eventName
, in the order they were registered, passing the supplied arguments
to each.
Returns true
if the event had listeners, false
otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener
Rest
...args: AnyRestReturns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbol
s.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
the nodeId of the parent Object
the method name
note:
Optional
args: ArgumentDefinitionretrieve the built-in DataType of a Variable, from its DataType attribute.
this method is useful to determine which DataType to use when constructing a Variant
the node id of the variable to query
const session = ...; // ClientSession
const nodeId = opcua.VariableIds.Server_ServerStatus_CurrentTime;
session.getBuiltInDataType(nodeId,function(err,dataType) {
assert(dataType === opcua.DataType.DateTime);
});
// or
nodeId = opcua.coerceNodeId("ns=2;s=Static_Scalar_ImagePNG");
const dataType: await session.getBuiltInDataType(nodeId);
assert(dataType === opcua.DataType.ByteString);
Returns the number of listeners listening for the event named eventName
.
If listener
is provided, it will return how many times the listener is found
in the list of the listeners of the event.
The name of the event being listened for
Optional
listener: FunctionThe event handler function
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
Alias for emitter.removeListener()
.
Rest
...args: any[]Adds the listener
function to the end of the listeners array for the event
named eventName
. No checks are made to see if the listener
has already
been added. Multiple calls passing the same combination of eventName
and
listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Adds the listener
function to the end of the listeners array for the event
named eventName
. No checks are made to see if the listener
has already
been added. Multiple calls passing the same combination of eventName
and
listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
Adds the listener
function to the end of the listeners array for the event
named eventName
. No checks are made to see if the listener
has already
been added. Multiple calls passing the same combination of eventName
and
listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
session_restored is raised when the session and related subscription have been fully repaired after a reconnection.
Adds the listener
function to the end of the listeners array for the event
named eventName
. No checks are made to see if the listener
has already
been added. Multiple calls passing the same combination of eventName
and
listener
will result in the listener
being added, and called, multiple times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The callback function
Rest
...args: any[]Adds a one-time listener
function for the event named eventName
. The
next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
Rest
...args: any[]Adds the listener
function to the beginning of the listeners array for the
event named eventName
. No checks are made to see if the listener
has
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
The callback function
Rest
...args: any[]Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter
, so that calls can be chained.
The name of the event.
The callback function
Rest
...args: any[]Returns a copy of the array of listeners for the event named eventName
,
including any wrappers (such as those created by .once()
).
import { EventEmitter } from 'node:events';
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
Optional
maxAge: numberOptional
maxAge: numberthe read value id
the start time in UTC format
the end time in UTC format
in milliseconds
aggregateConfiguration contains additional parameters
The TreatUncertainAsBad Variable indicates how the Server treats data returned with a StatusCode severity Uncertain with respect to Aggregate calculations. A value of True indicates the Server considers the severity equivalent to Bad, a value of False indicates the Server considers the severity equivalent to Good, unless the Aggregate definition says otherwise. The default value is True. Note that the value is still treated as Uncertain when the StatusCode for the result is calculated.
The PercentDataBad Variable indicates the minimum percentage of Bad data in a given interval required for the StatusCode for the given interval for processed data request to be set to Bad. (Uncertain is treated as defined above.) Refer to 5.4.3 for details on using this Variable when assigning StatusCodes. For details on which Aggregates use the PercentDataBad Variable, see the definition of each Aggregate. The default value is 100.
The PercentDataGood Variable indicates the minimum percentage of Good data in a given interval required for the StatusCode for the given interval for the processed data requests to be set to Good. Refer to 5.4.3 for details on using this Variable when assigning StatusCodes. For details on which Aggregates use the PercentDataGood Variable, see the definition of each Aggregate. The default value is 100.
The PercentDataGood and PercentDataBad shall follow the following relationship PercentDataGood ≥ (100 – PercentDataBad). If they are equal the result of the PercentDataGood calculation is used. If the values entered for PercentDataGood and PercentDataBad do not result in a valid calculation (e.g. Bad = 80; Good = 0) the result will have a StatusCode of Bad_AggregateInvalidInputs The StatusCode Bad_AggregateInvalidInputs will be returned if the value of PercentDataGood or PercentDataBad exceed 100.
The UseSlopedExtrapolation Variable indicates how the Server interpolates data when no boundary value exists (i.e. extrapolating into the future from the last known value). A value of False indicates that the Server will use a SteppedExtrapolation format, and hold the last known value constant. A value of True indicates the Server will project the value using UseSlopedExtrapolation mode. The default value is False. For SimpleBounds this value is ignored.
// es5
session.readAggregateValue(
{nodeId: "ns=5;s=Simulation Examples.Functions.Sine1" },
new Date("2015-06-10T09:00:00.000Z"),
new Date("2015-06-10T09:01:00.000Z"),
AggregateFunction.Average, 3600000, (err,dataValues) => {
});
// es6
const dataValues = await session.readAggregateValue(
{ nodeId: "ns=5;s=Simulation Examples.Functions.Sine1" },
new Date("2015-06-10T09:00:00.000Z"),
new Date("2015-06-10T09:01:00.000Z"),
AggregateFunction.Average, 3600000);
Optional
results: HistoryReadResult[]Optional
results: HistoryReadResult[]Optional
options: ExtraReadHistoryValueParametersOptional
result: HistoryReadResultOptional
result: HistoryReadResultOptional
options: ExtraReadHistoryValueParametersOptional
registeredNodeIds: NodeId[]Removes all listeners, or those of the specified eventName
.
It is bad practice to remove listeners added elsewhere in the code,
particularly when the EventEmitter
instance was created by some other
component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
eventName: string | symbolRemoves the specified listener
from the listener array for the event named eventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
removeListener()
will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified eventName
, then removeListener()
must be
called multiple times to remove each instance.
Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
will not remove them fromemit()
in progress. Subsequent events behave as expected.
import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
Because listeners are managed using an internal array, calling this will
change the position indices of any listener registered after the listener
being removed. This will not impact the order in which listeners are called,
but it means that any copies of the listener array as returned by
the emitter.listeners()
method will need to be recreated.
When a single function has been added as a handler multiple times for a single
event (as in the example below), removeListener()
will remove the most
recently added instance. In the example the once('ping')
listener is removed:
import { EventEmitter } from 'node:events';
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
Returns a reference to the EventEmitter
, so that calls can be chained.
Rest
...args: any[]By default EventEmitter
s will print a warning if more than 10
listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The emitter.setMaxListeners()
method allows the limit to be
modified for this specific EventEmitter
instance. The value can be set to Infinity
(or 0
) to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter
, so that calls can be chained.
Optional
err: Error
the time of the latest request sent by the client to the server