Handling Events
How to subscribe to events, assuming you are already subscribed to the correct channel.
Info
Keep in mind that data received inside event are also sent as Uin8Array
. You still have to deserialize it before using in your app.
Connection
You can subscribe for events related to connection status.
const eventHandle = Endpoint.connection().on('libConnected', data => {
console.log('connected');
});
eventHandle.removeEventListener();
Threads
When working with Threads you have access to events:
- threadCreated
- threadDeleted
- threadStatsUpdated
- threadUpdated
const channel = await Endpoint.connection().threads.subscribeToThreadEvents();
channel.on('threadCreated', (data) => console.log(data))
.on('threadDeleted', (data => console.log(data)))
.on('threadStatsChanged', (data) => console.log(data));
// Unsubscribing from channel
await Endpoint.connection().threads.unsubscribeFromThreadEvents();
Read more about Thread events.
Stores
Subscribing to:
- storeCreated
- storeDeleted
- storeStats
- storeUpdated
const channel = await Endpoint.connection().stores.subscribeToStores();
channel.on('storeCreated', (data) => console.log(data))
.on('storeDeleted', (data) => console.log(data))
.on('storeStatsChanged', (data) => console.log(data));
// Unsubscribing from channel
await Endpoint.connection().stores.unsubscribeFromStoreEvents();
Read more about Store events.
Inboxes
Subscribing to:
- inboxCreated
- inboxDeleted
- inboxUpdated
const channel = await Endpoint.connection().inboxes.subscribeForInboxEvents();
channel.on('inboxCreated', (data) => console.log(data))
.on('inboxDeleted', (data) => console.log(data));
// Unsubscribing from channel
await Endpoint.connection().inboxes.unsubscribeFromInboxEvents();