# on()

Subscribes to an [event](https://docs.digitalsamba.com/reference/sdk/events) 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');  
});
```
