# Events

With events you can subscribe to various things which are happening inside the room.

For example you may want to hide the iframe when user leaves the meeting -> then you will subscribe to the [userLeft](https://docs.digitalsamba.com/reference/sdk/events/userleft) event. For the full list of events please have a look at the navigation bar on the left.

You will subscribe to an event with the [on()](https://docs.digitalsamba.com/reference/sdk/methods/on) method and unsubscribe with the [off()](https://docs.digitalsamba.com/reference/sdk/methods/off) method.\
There is also the [once()](https://docs.digitalsamba.com/reference/sdk/methods/once) method for subscription, but it's only a one-time subscription and is used rarely in general. The events architecture is built upon the commonly used [EventEmitter](https://nodejs.org/api/events.html#class-eventemitter) interface.

#### Templates for subscription/unsubscription:

```javascript
sambaFrame.on('eventNameHere', (event) => {
   //Execute your own custom logic here
});

sambaFrame.once('eventNameHere', (event) => {
   //This will execute ONLY ONCE, even if the event happens a hundred times
});

const myCallback = (event) => {
   //Execute your own custom logic here
});
sambaFrame.on('eventNameHere', myCallback);
//........................................

//Unsubscribe if you want at some point later
sambaFrame.off('eventNameHere', myCallback);
```

{% hint style="info" %}
There is a special event named '**\***', which can be useful for debugging purposes to see all incoming events and their data.\
\
`sambaFrame.on('*', (event) => {`&#x20;

&#x20;  `console.log(event);`

`});`
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digitalsamba.com/reference/sdk/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
