Skip to main content

Using the EventTarget Web API

If you want to handle the Eyeson events via the EventTarget API you can use the following snippet.

eyeson.onEvent(event => {
window.dispatchEvent(new CustomEvent('eyeson', { detail: event }));
window.dispatchEvent(new CustomEvent('eyeson.' + event.type, { detail: event }));
});
eyeson.start(token);
/* then listen for events */
window.addEventListener('eyeson', handleEvent);
window.addEventListener('eyeson.chat', handleIncomingChatMessage);