Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'node-opcua-address-space' 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.
public _exposeSubscriptionDiagnostics(subscription: Subscription) {
debugLog("ServerSession#_exposeSubscriptionDiagnostics");
assert(subscription.$session === this);
const subscriptionDiagnosticsArray = this._getSubscriptionDiagnosticsArray();
const subscriptionDiagnostics = subscription.subscriptionDiagnostics;
assert(subscriptionDiagnostics.$subscription === subscription);
if (subscriptionDiagnostics && subscriptionDiagnosticsArray) {
// xx console.log("GG => ServerSession Exposing subscription diagnostics =>",
// subscription.id,"on session", session.nodeId.toString());
addElement(subscriptionDiagnostics, subscriptionDiagnosticsArray);
}
}
ServerEngine.prototype._unexposeSubscriptionDiagnostics = function (subscription) {
const engine = this;
const subscriptionDiagnosticsArray = engine._getServerSubscriptionDiagnosticsArray();
const subscriptionDiagnostics = subscription.subscriptionDiagnostics;
assert(subscriptionDiagnostics instanceof SubscriptionDiagnostics);
if (subscriptionDiagnostics && subscriptionDiagnosticsArray) {
const node = subscriptionDiagnosticsArray[subscription.id];
/// console.log("GGGGGGGGGGGGGGGG ServerEngine => **Unexposing** subscription diagnostics =>",subscription.id);
eoan.removeElement(subscriptionDiagnosticsArray, subscriptionDiagnostics);
assert(!subscriptionDiagnosticsArray[subscription.id]," subscription node must have been removed from subscriptionDiagnosticsArray");
}
debugLog("ServerEngine#_unexposeSubscriptionDiagnostics");
};
/**
public _unexposeSubscriptionDiagnostics(subscription: Subscription) {
const subscriptionDiagnosticsArray = this._getSubscriptionDiagnosticsArray();
const subscriptionDiagnostics = subscription.subscriptionDiagnostics;
assert(subscriptionDiagnostics instanceof SubscriptionDiagnosticsDataType);
if (subscriptionDiagnostics && subscriptionDiagnosticsArray) {
// console.log("GG => ServerSession **Unexposing** subscription diagnostics =>",
// subscription.id,"on session", session.nodeId.toString());
removeElement(subscriptionDiagnosticsArray, subscriptionDiagnostics);
}
debugLog("ServerSession#_unexposeSubscriptionDiagnostics");
}
/**
// A Server may not expose the SamplingIntervalDiagnosticsArray if it does not use fixed sampling rates.
// because we are not using fixed sampling rate, we need to remove the optional SamplingIntervalDiagnosticsArray
// component
const samplingIntervalDiagnosticsArray =
serverDiagnostics.getComponentByName("SamplingIntervalDiagnosticsArray");
if (samplingIntervalDiagnosticsArray) {
addressSpace.deleteNode(samplingIntervalDiagnosticsArray);
const s = serverDiagnostics.getComponents();
// xx console.log(s.map((x) => x.browseName.toString()).join(" "));
}
const subscriptionDiagnosticsArray =
serverDiagnostics.getComponentByName("SubscriptionDiagnosticsArray")! as
UADynamicVariableArray;
assert(subscriptionDiagnosticsArray.nodeClass === NodeClass.Variable);
bindExtObjArrayNode(subscriptionDiagnosticsArray,
"SubscriptionDiagnosticsType", "subscriptionId");
const sessionsDiagnosticsSummary = serverDiagnostics.getComponentByName("SessionsDiagnosticsSummary")!;
const sessionDiagnosticsArray =
sessionsDiagnosticsSummary.getComponentByName("SessionDiagnosticsArray")! as
UADynamicVariableArray;
assert(sessionDiagnosticsArray.nodeClass === NodeClass.Variable);
bindExtObjArrayNode(sessionDiagnosticsArray, "SessionDiagnosticsVariableType", "sessionId");
const varType = addressSpace.findVariableType("SessionSecurityDiagnosticsType");
if (!varType) {
console.log("Warning cannot find SessionSecurityDiagnosticsType variable Type");
} else {
const sessionSecurityDiagnosticsArray =
private _start_sampling(recordInitialValue?: boolean) {
if (!this.node) {
throw new Error("Internal Error");
}
// make sure oldDataValue is scrapped so first data recording can happen
this.oldDataValue = new DataValue({ statusCode: StatusCodes.BadDataUnavailable }); // unset initially
this._stop_sampling();
const context = new SessionContext({
// xx server: this.server,
session: this._getSession()
});
if (this.itemToMonitor.attributeId === AttributeIds.EventNotifier) {
// istanbul ignore next
if (doDebug) {
debugLog("xxxxxx monitoring EventNotifier on",
this.node.nodeId.toString(), this.node.browseName.toString());
}
// we are monitoring OPCUA Event
this._on_opcua_event_received_callback = this._on_opcua_event.bind(this);
this.node.on("event", this._on_opcua_event_received_callback);
return;
return callback(null, {statusCode: response.statusCode});
}
const methodDeclaration = response.methodDeclaration;
// verify input Parameters
const methodInputArguments = methodDeclaration.getInputArguments();
response = verifyArguments_ArgumentList(addressSpace, methodInputArguments, inputArguments);
if (response.statusCode !== StatusCodes.Good) {
return callback(null, response);
}
const methodObj = addressSpace.findNode(methodId);
// invoke method on object
const context = new SessionContext({
session: session,
object: addressSpace.findNode(objectId),
server: server
});
methodObj.execute(inputArguments, context, function (err, callMethodResponse) {
/* istanbul ignore next */
if (err) {
return callback(err);
}
callMethodResponse.inputArgumentResults = response.inputArgumentResults || [];
assert(callMethodResponse.statusCode);
return sendError(StatusCodes.BadTooManyOperations);
}
}
// todo : handle
if (server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadData > 0) {
if (request.nodesToRead.length > server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadData) {
return sendError(StatusCodes.BadTooManyOperations);
}
}
if (server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadEvents > 0) {
if (request.nodesToRead.length > server.engine.serverCapabilities.operationLimits.maxNodesPerHistoryReadEvents) {
return sendError(StatusCodes.BadTooManyOperations);
}
}
const context = new SessionContext({session, server});
// ask for a refresh of asynchronous variables
server.engine.refreshValues(request.nodesToRead, function (err) {
assert(!err, " error not handled here , fix me"); //TODO
server.engine.historyRead(context, request, function (err, results) {
assert(results[0]._schema.name === "HistoryReadResult");
assert(results.length === request.nodesToRead.length);
response = new HistoryReadResponse({
results: results,
diagnosticInfos: null
});
assert(response.diagnosticInfos.length === 0);
if (!request.nodesToWrite || request.nodesToWrite.length === 0) {
return sendError(StatusCodes.BadNothingToDo);
}
if (server.engine.serverCapabilities.operationLimits.maxNodesPerWrite > 0) {
if (request.nodesToWrite.length > server.engine.serverCapabilities.operationLimits.maxNodesPerWrite) {
return sendError(StatusCodes.BadTooManyOperations);
}
}
// proceed with registered nodes alias resolution
for (let i = 0; i < request.nodesToWrite.length; i++) {
request.nodesToWrite[i].nodeId = session.resolveRegisteredNode(request.nodesToWrite[i].nodeId);
}
const context = new SessionContext({session, server});
assert(request.nodesToWrite[0]._schema.name === "WriteValue");
server.engine.write(context, request.nodesToWrite, function (err, results) {
assert(!err);
assert(_.isArray(results));
assert(results.length === request.nodesToWrite.length);
response = new WriteResponse({
results: results,
diagnosticInfos: null
});
sendResponse(response);
});
});
};
this.sessionSecurityDiagnostics = sessionSecurityDiagnosticsType.instantiate({
browseName: new QualifiedName({ name: "SessionSecurityDiagnostics", namespaceIndex: 0 }),
componentOf: this.sessionObject,
extensionObject: this._sessionSecurityDiagnostics,
minimumSamplingInterval: 2000 // 2 seconds
}) as UASessionSecurityDiagnostics;
ensureObjectIsSecure(this.sessionSecurityDiagnostics);
this._sessionSecurityDiagnostics = this.sessionSecurityDiagnostics.$extensionObject as SessionSecurityDiagnosticsDataTypeEx;
assert(this._sessionSecurityDiagnostics.$session === this);
const sessionSecurityDiagnosticsArray = this.getSessionSecurityDiagnosticsArray();
// add sessionDiagnostics into sessionDiagnosticsArray
const node = addElement(this._sessionSecurityDiagnostics, sessionSecurityDiagnosticsArray);
ensureObjectIsSecure(node);
}
}
});
this.sessionDiagnostics = sessionDiagnosticsVariableType.instantiate({
browseName: new QualifiedName({ name: "SessionDiagnostics", namespaceIndex: 0 }),
componentOf: this.sessionObject,
extensionObject: this._sessionDiagnostics,
minimumSamplingInterval: 2000 // 2 seconds
}) as UASessionDiagnostics;
this._sessionDiagnostics = this.sessionDiagnostics.$extensionObject as SessionDiagnosticsDataTypeEx;
assert(this._sessionDiagnostics.$session === this);
const sessionDiagnosticsArray = this.getSessionDiagnosticsArray();
// add sessionDiagnostics into sessionDiagnosticsArray
addElement(this._sessionDiagnostics, sessionDiagnosticsArray);
}
}
function createSessionSecurityDiagnosticsStuff(this: ServerSession) {