npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

opcua

v1.0.0

Published

TypeScript / JavaScript OPC UA client for the browser

Downloads

117

Readme

opcua

TypeScript / JavaScript OPC UA client for the browser.

github actions seriesci coverage

... work in progress ...

Features

Usage

npm i opcua
import Client from 'opcua'

const client = new Client()

// wait for an active session
client.addEventListener('session:activate', async event => {

  // browse the root folder
  const req = new BrowseRequest({
    NodesToBrowse: [
      new BrowseDescription({
        NodeId: NewTwoByteNodeId(IdRootFolder)
      })
    ]
  })

  // all requests use async / await
  const res = await client.browse(req)
  console.log(res)
})

Development

The source code is written in TypeScript. We use the TypeScript compiler to create the JavaScript files for the browser.

Some source code files are autogenerated.

  • src/ua/generated.ts by cmd/service/main.go
  • src/id/id.ts by cmd/id/main.go

Do not edit them by hand. You need Go on your machine to execute those generators. The schema definition files are located at ./schema.

We rely on reflection and decorators to get types (e.g. uint32, CreateSessionRequest or arrays of certain types string[]) during runtime. In JavaScript a number is always double-precision 64-bit. OPC UA has much more number types like int8, uint8, int16, uint16 and so on. In order to get the binary encoding / decoding right we must know exactly how many bits represent a number.

The client architecture consists of multiple layers. They closely follow the official OPC UA specification. Read the following diagram from bottom to top. On the right side you find the responsibilities for each layer.

layers

The OPC UA handshake is quite complex and several steps are necessary to get an active session. Those steps are

  1. Hello / Acknowledge
  2. Open Secure Channel
  3. Create Session
  4. Activate Session

The following diagram shows this sequence and highlights response parameters that the client has to store internally (e.g. channel id, token id, authentication token, sequence number, request id).

handshake

You need an OPC UA server implementation that supports WebSockets to test the client. Two options exist:

  1. Use open62541 with WebSockets enabled
  2. Use websockify for servers that do not support WebSockets (that only support TCP connections)