@mhlabs/aws-iot-ws-broker

A broker for client side websocket pub/sub using AWS IoT

Stats

StarsIssuesVersionUpdatedCreatedSize
@mhlabs/aws-iot-ws-broker
124.0.22 years ago4 years agoMinified + gzip package size for @mhlabs/aws-iot-ws-broker in KB

Readme

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));

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.