Developer Documentation
Our new developer documentation is now available. Please check it out!

OdinPeerJoinedLeftEvent

type OdinPeerJoinedLeftEvent = (event: IOdinEvent<IOdinPeerJoinedLeftEventPayload>)

Discussion

The OdinPeerJoinedLeftEvent event is emitted on OdinRoom instances when a remote peer joins or leaves the room.

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

Event Scopes

  • IOdinRoomEvents

Example

OdinPeerJoinedLeftEvent 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);

  // Adds an event listener to get notified when a new peer joined the room
  odinRoom.addEventListener('PeerJoined', (event) => {
    console.log('A peer joined the room:', event.payload.peer);
  });
  // Adds an event listener to get notified then a peer left the room
  odinRoom.addEventListener('PeerLeft', (event) => {
    console.log('A peer left the room:', event.payload.peer);
  });

  // Join the room
  odinRoom.join();
};

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

Parameters

NameTypeDescription
eventIOdinEvent<IOdinPeerJoinedLeftEventPayload>