Developer Documentation


type OdinMediaStartedStoppedEvent = (event: IOdinEvent<IOdinMediaStartedStoppedEventPayload>)


The OdinMediaStartedStoppedEvent event is emitted on OdinRoom and OdinPeer instances whenever a remote peer started/stopped a media in the room. Usually, you would want to call the start or stop method on such media to start/stop the Opus decoder for audio playback.

Events are inheriting from IOdinEvent and provide an object described by IOdinMediaStartedStoppedEventPayload in the payload property of the event.

Event Scopes

  • IOdinRoomEvents
  • IOdinPeerEvents


OdinMediaStartedStoppedEvent 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) => {
    console.log(`Peer ${} added a new media stream to the room`);;

  // Listen to media stopped events in the room and stop decoding its voice packets
  odinRoom.addEventListener('MediaStopped', (event) => {
    console.log(`Peer ${} removed a media stream from the room`);;

  // Listen to activity events of started medias in the room (e.g. someone is talking)
  odinRoom.addEventListener('MediaActivity', (event) => {
    console.log(`Media ${} activity updated:`,;

  // Join the room

  // Create a new audio stream for our default capture device and append it to the room
  navigator.mediaDevices.getUserMedia({ audio: true }).then((mediaStream) => {

startOdin('__YOUR TOKEN__').then(() => {
  console.log('Started ODIN');