Skip to main content
NOTE: Refer type definitions for this guide here .

Initialise feed client

Using SuprSend client instance create Feed client instance.
tenantId defaults to the active tenant set in identify or changeTenant, else the default tenant. Passing it here overrides the active tenant for that feed instance. Already running feed instances keep the tenant they were initialized with when changeTenant is called — re-initialize the feed to reflect the new tenant. If you are passing tenant_id in feed, make sure to pass scope key while creating userToken else error will be thrown due to scope mismatching. reachability defaults to false. Set it to true to track whether the feed is working for this user. See Tracking reachability.

Feed client

Get feed data

This returns notification store which contains list of notifications and other meta data like page information etc. You can call this anytime to get updated store data.

Initialise socket for realtime update

Fetching notification data

This method will get first page of notifications from SuprSend server and set data in notification store.

Fetch more notifications

This method will get next page of notifications from SuprSend server and set data in notification store.

Listening for updates to store

Whenever there is update in notification store (ex: on new notification or existing notification state updated) this event is fired by library. You can listen to this event and update your local state so that UI of you application is refreshed.

Listening for new notification

In case you want to show toast notification on receiving new notification you can use this listener.

Tracking reachability

Reachability tells you whether the feed is working for this user right now. It combines three checks into one status: the browser is online, the feed socket is live, and the feed API is reachable. Use it to tell users when new notifications may be missing. It’s off by default. Turn it on when you create the feed client:
norun
Listen for changes with the feed.reachability_change event:
norun
You can also read the current value at any time with feedClient.reachability. It’s undefined when you didn’t pass reachability: true. The event fires only when the overall status, socket.status, api.status or api.authError changes. It doesn’t fire on every request or reconnect attempt.
Timestamps are epoch milliseconds. lastChangedAt updates only when the event fires. Each value is a frozen object, so read from it but don’t modify it. ReachabilityStatus and ChannelStatus are exported from @suprsend/web-sdk. Each channel (socket and api) is UNKNOWN, CONNECTING, UP or DOWN. A channel stays UNKNOWN until it’s used, and an UNKNOWN channel is ignored. The SDK picks the first status in this table that matches:

How each connection is tracked

  • Browser: read from navigator.onLine and the window online and offline events. With no window (for example, during server-side rendering), the browser counts as online.
  • Socket: CONNECTING when you call initializeSocketConnection(). It turns UP only after the server confirms the feed joined its room. If that confirmation doesn’t arrive within 5 seconds, it turns DOWN. It also turns DOWN after more than 10 reconnect attempts. Disconnects caused by feedClient.remove() are ignored.
  • API: measured on the first page fetch only. It’s CONNECTING when fetch() starts for an identified user, DOWN on a network error, and UP otherwise. A 401 or 403 on this initial load sets api.authError to true and the status to AUTH_ERROR. Later page fetches don’t change it.

Example: replicate the Inbox connection status

The React Inbox component renders a coloured dot on the bell and a banner in the panel for each status. Here’s how to render the same states in a custom UI with the JavaScript SDK.
Inbox with a green connected dot on the bell and beside the panel title
norun

Removing feed

This will remove feed client data and abort socket connection. Additionally calling suprSendClient.reset method during logout will also remove all feedClient instances attached SuprSend client instance.

Other methods

Example

For understanding purpose we have added current simple example in react. You could refer this headless example and design the feed in your Angular or Vue.js etc. If you want to implement in react please refer @suprsend/react-core or @suprsend/react