Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function makeUserIdentity(argv: any): UserIdentityInfo {
let userIdentity: UserIdentityInfo = { type: UserTokenType.Anonymous }; // anonymous
if (argv.userName && argv.password) {
userIdentity = {
type: UserTokenType.UserName,
userName: argv.userName,
password: argv.password
};
} else if (argv.userCertificate && argv.userCertificatePrivateKey) {
userIdentity = {
type: UserTokenType.Certificate,
certificateData: argv.userCertificate,
privateKey: "todo"
};
}
return userIdentity;
}
(async () => {
try {
console.log(" about to connect");
await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
console.log("connected");
client.on("backoff", () => {
console.log("Backoff");
});
const session = await client.createSession({
password: "password1",
type: UserTokenType.UserName,
userName: "user1",
});
const a = await session.getArgumentDefinition("ns=0;i=12886");
console.log(a.inputArguments.map((x: Variant) => x.toString()).join(" "));
const result = await session.browse({
nodeId: "i=2558"
});
for (const reference of result.references!) {
console.log(reference.toString());
}
const registeredNodes = await session.registerNodes(["ns=1;s=FanSpeed", "ns=1;s=PumpSpeed"]);
async function test2() {
console.log("----------------------------------------------------");
try {
await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
const session: ClientSession = await client.createSession({
type: UserTokenType.UserName,
password: "password1",
userName: "user1"
});
const subscription = ClientSubscription.create(session, {
maxNotificationsPerPublish: 1000,
publishingEnabled: true,
requestedLifetimeCount: 100,
requestedMaxKeepAliveCount: 10,
requestedPublishingInterval: 500
});
subscription.on("error", (err) => {
console.log(" Error :", err);
});
async function test1() {
try {
await client.connect("opc.tcp://opcuademo.sterfive.com:26543");
const session: ClientSession = await client.createSession({
type: UserTokenType.UserName,
password: "password1",
userName: "user1"
});
const subscription = await session.createSubscription2({
maxNotificationsPerPublish: 1000,
publishingEnabled: true,
requestedLifetimeCount: 100,
requestedMaxKeepAliveCount: 10,
requestedPublishingInterval: 1000
});
subscription.on("raw_notification", (n) => {
console.log(n.toString());
});