Overview
Events enable your application to react dynamically to changes within user Context.
These events are triggered automatically when a relevant change occurs. You can subscribe to them by registering event listeners. This allows you to respond to changes as they happen in real-time.
Limitations
Please note the following:
- Events will only trigger for active subscriptions.
- Events will not be captured unless the event loop is running.
To start the event loop, use the following command:
await Endpoint.startEventLoop();
Caveats
- Unsubscribing from a given channel deletes all event listeners related to it.
- Calling
Endpoint.stopEventLoop()
deletes all event listeners. - Disconnecting deletes all event subscriptions and event listeners.
Quick start
- Start the event loop:
await Endpoint.startEventLoop();
- Subscribe to Tool (e.g. Thread) events:
const channel = await Endpoint.connection().threads.subscribeToThreadEvents();
- Add event listener for 'threadCreated': Remember to deserialize data from binary.
const eventHandle = channel.on('threadCreated', (data) => console.log(data)).removeEventListener
- Remove the event listener when no longer needed:
eventHandle.removeEventListener();
or unsubscribe from all events related to channel
await Endpoint.connection().threads.unsubscribeFromThreadEvents();