# on()

Subscribes to an [event](/reference/sdk/events.md) using a callback function.

#### Event payload signature

```
{
  "type": "eventNameHere",
  "data": {
    .....................
  }
}
```

#### Sample subscription code

<pre class="language-javascript"><code class="lang-javascript"><strong>sambaFrame.on('userJoined', (event) => {
</strong>  const data = event.data;
  if (data.type === 'local') {
     console.log('You have joined the room');
  } else {
     console.log(data.user.name, 'has joined the room');
  }
});
</code></pre>

{% hint style="info" %}
It is possible to subscribe multiple times to the same event with different callbacks.
{% endhint %}

#### Sample subscription code with multiple callbacks

```javascript
sambaFrame.on('userJoined', (event) => {
  console.log('First callback called');
});

//....................................

sambaFrame.on('userJoined', (event) => {
  console.log('Second callback called');  
});
```


---

# 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/methods/on.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.
