@mhlabs/aws-iot-ws-broker
TypeScript icon, indicating that this package has built-in type declarations

4.0.2 • Public • Published

aws-iot-mqtt-broker

Usage:

Installation

npm i @mhlabs/aws-iot-ws-broker

Connecting (TypeScript)

import AwsIot, { IotEvent } from '@mhlabs/aws-iot-ws-broker';

// credentials could be e.g. from Cognito Identity Pool
const creds: CognitoIdentityCredentials = createCredentials();
this.websocket = new AwsIot(creds, !environment.production);

Subscribe to topic:

New in this version is that subscribe() returns an Observable and therefor needs to be subscribed to. The Observable with emit and complete when the topic has been subscribed to.

this.websocket.subscribe('your/topic').subscribe(topic => console.log(`${topic} has been subscribed to`));

Send message

this.websocket.send('your/topic', message);

Handle message:

this.websocket.events.pipe(filter(event => event.type === IotEventType.Message)).subscribe(event => console.log(`Message on topic ${event.topic}:`, event.message));

Readme

Keywords

none

Package Sidebar

Install

npm i @mhlabs/aws-iot-ws-broker

Weekly Downloads

1

Version

4.0.2

License

ISC

Unpacked Size

19.6 kB

Total Files

10

Last publish

Collaborators

  • mhlabs