JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q62073F
  • License MIT

Client library for Includable Topics.

Package Exports

  • @includable/topics

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@includable/topics) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Topics

Super simple websocket message broadcasting.

Topis is a service built into the Includable Platform, making it easy for Includable app developers to use websocket functionality.

Note however that when using this library, the namespace shared by your topics is shared by all users of the library. So make sure to make your topic name something unique that won't collide with other users.

The best approach for this is to use a reverse-DNS style string, like com.thomasschoffelen.mytopic.

Installation

npm i @includable/topics

Usage

See example.js.

API

The Topics class exposes the following (static) functions. All of these functions return a Promise object.

Topics.sub

Subscribe to a topic.

Topics.sub('my-topic-name', (message) => {
    console.log('Received message on my-topic-name: ' + message)
})

Note that topics can be subscribed to only once, but you can use this method multiple times to attach multiple callbacks to the same topic.

Topics.unsub

Unsubscribe from a topic.

Topics.unsub('my-topic-name')

Topics.broadcast

Broadcast a message to a topic. These messages should always be plain (stringify-able) JS objects.

Topics.broadcast('my-topic-name', {'hello': 'world'})

Topics.start

Connect to the Topics server. It is usually not necessary to call this manually, since it will be called automatically on your first sub() call.

Topics.start()

Topics.stop

Disconnect from the Topics server and remove all subscriptions.

Topics.stop()

Options

Topics.setDebug

Boolean - set this to true to send logs to stdout. Default false.

// do this at the top of your script:

Topics.setDebug(true)

Topics.setTimeout

Number - set the connection timeout in ms. Default 10000.

// do this at the top of your script:

Topics.setTimeout(15000)