signalk-worker-angular
v1.1.4
Published
WebWorker wrapper for `signalk-worker-angular` STREAM communications in Angular.
Downloads
39
Maintainers
Readme
signalk-worker-angular: WebWorker library for signalk-client-angular
Note: This library was generated with Angular CLI version 12.0.0.
This library provides a wrapper for the stream
class within signalk-client-angular
library to facilitate communication with a Signal K server STREAM API via a WebWorker within an Angular application.
SignalKStreamWorker class exposes all attributes and methodsof the stream
class for interacting with Signal K STREAM API
Please refer to the signalk-client-angular documentation on GitHub.
Installation
signalk-worker-angular
has a dependency on signalk-client-angular
version 1.8.0 or greater so ensure both libraries are installed.
npm install signalk-client-angular signalk-worker-angular
Usage
To create the worker in your project:
ng g webWorker skstream
this will create the file skstream.worker.ts in your project.
skstream.worker.ts
- Include
SignalKStreamWorker
in your worker and instantate an instance.
import { SignalKStreamWorker } from 'signalk-worker-angular';
let skstream= new SignalKStreamWorker();
- You can use the instantitated
SignalKStreamWorker
instance to access allstream
class methods and attributes.
app.component.ts
- Create a WebWorker and handle messages from it.
this.worker = new Worker('./skstream.worker', {
type: 'module'
});
this.worker.onmessage = ({ data }) => {
console.log('From Web Worker:', data );
};
- Send messages to the worker using
postMessage()
this.worker.postMessage({ ... });