on()

on(event: string, callback: function)
Subscribes to an event using a callback function.

Event payload signature

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

Sample subscription code

sambaFrame.on('userJoined', (event) => {
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');
}
});
It is possible to subscribe multiple times to the same event with different callbacks.

Sample subscription code with multiple callbacks

sambaFrame.on('userJoined', (event) => {
console.log('First callback called');
});
//....................................
sambaFrame.on('userJoined', (event) => {
console.log('Second callback called');
});
Last modified 7mo ago