Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-opcua-service-subscription' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
it("server should create a monitored item (CreateMonitoredItems)", function (done) {
// CreateMonitoredItemsRequest
var request = new subscription_service.CreateMonitoredItemsRequest({
subscriptionId: subscriptionId,
timestampsToReturn: read_service.TimestampsToReturn.Both,
itemsToCreate: [
{
itemToMonitor: {
nodeId: ec.makeNodeId(VariableIds.Server_ServerStatus_CurrentTime)
},
monitoringMode: subscription_service.MonitoringMode.Sampling,
requestedParameters: {
clientHandle: 26,
samplingInterval: 100,
filter: null,
queueSize: 100,
discardOldest: true
}
}
]
});
g_session.createMonitoredItems(request, function (err, response) {
if (!err) {
response.should.be.instanceof(subscription_service.CreateMonitoredItemsResponse);
}
done(err);
});
it("server should create a monitored item (CreateMonitoredItems)", function (done) {
// CreateMonitoredItemsRequest
var request = new subscription_service.CreateMonitoredItemsRequest({
subscriptionId: subscriptionId,
timestampsToReturn: read_service.TimestampsToReturn.Both,
itemsToCreate: [
{
itemToMonitor: {
nodeId: ec.makeNodeId(VariableIds.Server_ServerStatus_CurrentTime)
},
monitoringMode: subscription_service.MonitoringMode.Sampling,
requestedParameters: {
clientHandle: 26,
samplingInterval: 100,
filter: null,
queueSize: 100,
discardOldest: true
}
}
it("server should handle Publish request", function (done) {
// publish request now requires a subscriptions
var request = new subscription_service.PublishRequest({
subscriptionAcknowledgements: []
});
g_session.publish(request, function (err, response) {
if (!err) {
response.should.be.instanceof(subscription_service.PublishResponse);
response.should.have.ownProperty("subscriptionId"); // IntegerId
response.should.have.ownProperty("availableSequenceNumbers");// Array,Counter,
response.should.have.ownProperty("moreNotifications"); // Boolean
response.should.have.ownProperty("notificationMessage");
response.should.have.ownProperty("results");
response.should.have.ownProperty("diagnosticInfos");
}
done(err);
});
it("server should create a subscription (CreateSubscriptionRequest)", function (done) {
// CreateSubscriptionRequest
var request = new subscription_service.CreateSubscriptionRequest({
requestedPublishingInterval: 100,
requestedLifetimeCount: 100 * 60 * 10,
requestedMaxKeepAliveCount: 2,
maxNotificationsPerPublish: 2,
publishingEnabled: true,
priority: 6
});
g_session.createSubscription(request, function (err, response) {
if (!err) {
response.should.be.instanceof(subscription_service.CreateSubscriptionResponse);
subscriptionId = response.subscriptionId;
}
done(err);
});
});
subscription.session.createMonitoredItems(createMonitorItemsRequest, function (err, response) {
/* istanbul ignore next */
if (err) {
//xx console.log("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems ".red, err.message);
//xx console.log("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems ".red, err);
//xx console.log(createMonitorItemsRequest.toString());
} else {
assert(response instanceof subscription_service.CreateMonitoredItemsResponse);
for (let i = 0; i < response.results.length; i++) {
const monitoredItemResult = response.results[i];
const monitoredItem = monitoredItems[i];
monitoredItem._after_create(monitoredItemResult);
}
}
done(err);
});
ClientMonitoredItemBase._toolbox_monitor = function (subscription, timestampsToReturn, monitoredItems, done) {
assert(_.isFunction(done));
const itemsToCreate = [];
for (let i = 0; i < monitoredItems.length; i++) {
const monitoredItem = monitoredItems[i];
const itemToCreate = monitoredItem._prepare_for_monitoring(done);
if (_.isString(itemToCreate.error)) {
return done(new Error(itemToCreate.error));
}
itemsToCreate.push(itemToCreate);
}
const createMonitorItemsRequest = new subscription_service.CreateMonitoredItemsRequest({
subscriptionId: subscription.subscriptionId,
timestampsToReturn: timestampsToReturn,
itemsToCreate: itemsToCreate
});
assert(subscription.session);
subscription.session.createMonitoredItems(createMonitorItemsRequest, function (err, response) {
/* istanbul ignore next */
if (err) {
//xx console.log("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems ".red, err.message);
//xx console.log("ClientMonitoredItemBase#_toolbox_monitor: ERROR in createMonitoredItems ".red, err);
//xx console.log(createMonitorItemsRequest.toString());
} else {
assert(response instanceof subscription_service.CreateMonitoredItemsResponse);
ClientSubscription.prototype.__create_subscription = function (callback) {
assert(_.isFunction(callback));
const self = this;
const session = self.publish_engine.session;
debugLog("ClientSubscription created ".yellow.bold);
const request = new subscription_service.CreateSubscriptionRequest({
requestedPublishingInterval: self.publishingInterval,
requestedLifetimeCount: self.lifetimeCount,
requestedMaxKeepAliveCount: self.maxKeepAliveCount,
maxNotificationsPerPublish: self.maxNotificationsPerPublish,
publishingEnabled: self.publishingEnabled,
priority: self.priority
});
session.createSubscription(request, function (err, response) {
if (err) {
/* istanbul ignore next */
self.emit("internal_error", err);
if (callback) {
return callback(err);
}
public transferSubscription(
session: ServerSession,
subscriptionId: number,
sendInitialValues: boolean): TransferResult {
assert(session instanceof ServerSession);
assert(_.isNumber(subscriptionId));
assert(_.isBoolean(sendInitialValues));
if (subscriptionId <= 0) {
return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
}
const subscription = this.findSubscription(subscriptionId);
if (!subscription) {
return new TransferResult({ statusCode: StatusCodes.BadSubscriptionIdInvalid });
}
if (!subscription.$session) {
return new TransferResult({ statusCode: StatusCodes.BadInternalError });
}
// update diagnostics
subscription.subscriptionDiagnostics.transferRequestCount++;
// now check that new session has sufficient right
// if (session.authenticationToken.toString() !== subscription.authenticationToken.toString()) {
// console.log("ServerEngine#transferSubscription => BadUserAccessDenied");
// DataChange if (absolute value of (last cached value - current value) >
// (deadbandValue/100.0) * ((high-low) of EURange)))
//
// Specifying a deadbandValue outside of this range will be rejected and reported with the
// StatusCode Bad_DeadbandFilterInvalid (see Table 27).
// If the Value of the MonitoredItem is an array, then the deadband calculation logic shall be applied to
// each element of the array. If an element that requires a DataChange is found, then no further
// deadband checking is necessary and the entire array shall be returned.
assert(self.node !== null, "expecting a valid address_space object here to get access the the EURange");
if (self.node.euRange) {
// double,double
const rangeVariant = self.node.euRange.readValue().value;
const range = rangeVariant.value.high - rangeVariant.value.high;
assert(_.isFinite(range));
return checkDeadBand(oldDataValue.value, newDataValue.value, DeadbandType.Percent, deadbandValue, range);
}
return true;
}
}
function valueHasChanged(self, newDataValue, oldDataValue, deadbandType, deadbandValue) {
assert(newDataValue instanceof DataValue);
assert(oldDataValue instanceof DataValue);
switch (deadbandType) {
case DeadbandType.None:
assert(newDataValue.value instanceof Variant);
assert(newDataValue.value instanceof Variant);
// No Deadband calculation should be applied.
return checkDeadBand(oldDataValue.value, newDataValue.value, DeadbandType.None);
case DeadbandType.Absolute:
// AbsoluteDeadband
return checkDeadBand(oldDataValue.value, newDataValue.value, DeadbandType.Absolute, deadbandValue);
default:
// Percent_2 PercentDeadband (This type is specified in Part 8).
assert(deadbandType === DeadbandType.Percent);
// The range of the deadbandValue is from 0.0 to 100.0 Percent.
assert(deadbandValue >= 0 && deadbandValue <= 100);
// DeadbandType = PercentDeadband
// For this type of deadband the deadbandValue is defined as the percentage of the EURange. That is,
// it applies only to AnalogItems with an EURange Property that defines the typical value range for the
// item. This range shall be multiplied with the deadbandValue and then compared to the actual value change
// to determine the need for a data change notification. The following pseudo code shows how the deadband
// is calculated: