serverless-websocket
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Serverless Websocket

Serverless websocket support using AWS IOT & Cognito. Similar to other services like Pusher & ably.

This was designed primarily for the browser, but will also work in Node.js

The implementation is low-level and just covers getting the websocket URL. You'll probably want to use an MQTT client to connect to it.

Install

npm install serverless-websocket

Usage

const websocketURL = await Create({
  accountID: accountID,     // your 9+ digit AWS account ID (not access key)
  identityPoolID: poolID,   // Cognito Pool ID. See below for setup
  endpoint: endpoint        // Endpoint provided by Cognito, see below.
  region: 'us-west-2',
})
 
// usage: you'll probably want to use a MQTT client
const ws = new WebSocket(websocketURL, ['mqttv3.1'])

How to

More coming soon, but for now you can refer to:

TODO

  • Eliminate aws-signature-v4 dependency. This will allow us to use less of the crypto library.
  • Simple MQTT client using https://github.com/mqttjs/mqtt-packet. Unfortunately, the MQTT clients are quite bloated in the browser, but the protocol is straightforward, so it wouldn't be hard to write a slim one on top of the standard websockets API.

Test

npm test

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i serverless-websocket

Weekly Downloads

0

Version

1.0.1

License

none

Last publish

Collaborators

  • mattmueller