@turnly/realtime-client
v0.2.29
Published
A socket.io-client wrapper to facilitate connecting to our RTM & Streaming API.
Downloads
11
Readme
RTM Client
A socket.io-client wrapper to facilitate connecting to our RTM & Streaming API.
Installation
pnpm add @turnly/realtime-client
Streaming API
import { Realtime } from '@turnly/realtime-client'
const stream = new Realtime.Stream({ url: 'https://{organization}.turnly.app' })
/**
* Sets your secret token.
*/
stream.setAuthToken(process.env.TURNLY_STREAM_API_TOKEN) // '<your-token>'
/**
* Subscribes to single event.
*/
stream.subscribe('ticket.announced', event => console.log(event))
/**
* Unsubscribes
*/
const unsub = stream.subscribe('ticket.discarded', event => console.log(event))
/**
* Closes the subscription.
*/
unsub()
/**
* Subscribes to multiple events.
*/
stream.subscribe(['ticket.created', 'customer.created'], event => console.log(event))
/**
* Subscribes to all events.
*/
stream.subscribe(event => console.log(event))
Platform Realtime API
import { Realtime } from '@turnly/realtime-client'
const rtm = new Realtime.Platform({
url: 'https://{organization}.turnly.app',
channel: 'helpdesk',
})
/**
* Subscribes to single event.
*/
rtm.subscribe('service.tickets.ahead', event => console.log(event))
Realtime API
import { Realtime } from '@turnly/realtime-client'
const rtm = new Realtime.Widgets({
url: 'https://{organization}.turnly.app',
channel: 'queuing',
})
/**
* Subscribes to single event.
*/
rtm.subscribe('service.tickets.ahead', event => console.log(event))
Event Response
The event from the subscription will contain following properties:
| Name | Type | Description | | ------------ | --------- | ------------------------------------------------------- | | id | String | Unique identifier for this event. | | name | String | A human-readable name for the event. | | type | String | The operation of the event, commonly update or create. | | payload | Object | Contains data related to the event. | | timestamp | number | The UNIX timestamp from the server. |