Our new developer documentation is now available. Please check it out!
OdinMediaActivityChangedEvent
On this page
type OdinMediaActivityChangedEvent = (event: IOdinEvent<IOdinMediaActivityChangedEventPayload>)
Discussion
The OdinMediaActivityChangedEvent
event is emitted on OdinRoom
, OdinPeer
and OdinMedia
instances when a media is sending/receiving data. This can be used to determine when a user starts/stops speaking.
Events are inheriting from IOdinEvent
and provide an object described by IOdinMediaActivityChangedEventPayload
in the payload
property of the event.
Event Scopes
Example
OdinMediaActivityChangedEvent Example
import { OdinClient } from '@4players/odin';
const startOdin = async function (token: string) {
// Authenticate using a token obtained externally and spawn a room instance
const odinRoom = await OdinClient.initRoom(token);
// Listen to media started events in the room and start decoding its voice packets
odinRoom.addEventListener('MediaStarted', (event) => {
event.payload.media.start();
});
// Listen to media stopped events in the room and stop decoding its voice packets
odinRoom.addEventListener('MediaStopped', (event) => {
event.payload.media.stop();
});
// Listen to activity events of started medias in the room (e.g. someone is talking)
odinRoom.addEventListener('MediaActivity', (event) => {
console.log(`Media ${event.payload.media.id} activity updated:`, event.payload.media.active);
});
// Join the room
odinRoom.join();
// Create a new audio stream for our default capture device and append it to the room
navigator.mediaDevices.getUserMedia({ audio: true }).then((mediaStream) => {
odinRoom.createMedia(mediaStream);
});
};
startOdin('__YOUR TOKEN__').then(() => {
console.log('Started ODIN');
});
Parameters
Name | Type | Description |
---|---|---|
event | IOdinEvent<IOdinMediaActivityChangedEventPayload> |