IQEvents JS SDK
![Node.js Package](https://github.com/markoplace/iqevents-js-sdk/actions/workflows/npm-publish-github-packages.yml/badge.svg)
This package acts as a wrapper that provides easy access to the MarkoIQ pusher-driven realtime events system.
Installation
You can install this package using Yarn:
yarn --dev markoiq/iqevents-js
Setting Up
IQEvents is a simple library that is meant to work with the MarkoIQ RTM token API.
Before you can set up this client on your application you're going to want to issue a scoped RTM
token to initialize your client with.
Once you have the RTM token, simply invoke the iqevents
function anywhere in your application.
getRtmToken(['myscope']).then((token: string) => iqevents(token));
Getting an RTM Token
You can use the MarkoIQ API to issue a token you can then expose to a user of your
application, here is a PHP example:
<?php
$api = new MarkoAPI();
return $api->store($storeId)->getRtmToken(array $scopes);
Subscribing to an event
Once you've initialized the library using the iqevents
helper, you can then simply use the
library's subscribe
method:
subscribe('store-1.broadcasts', payload => {
console.log('My event!');
});
Using promises
This library also provides a set of methods for writing promise-based routines. You
would really only use this for expecting single messages on async functions and things
of the sort:
import { iqPromise } from "iqevents-js-sdk";
iqPromise.listen('store-1.broadcasts').then(payload => {
});