Developer Documentation

OdinPeerDataChangedEvent

type OdinPeerDataChangedEvent = (event: IOdinEvent<IOdinPeerDataChangedEventPayload>)

Discussion

The OdinPeerDataChangedEvent event is emitted on OdinRoom and OdinPeer instances when the user data of a remote peer changed.

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

Event Scopes

  • IOdinRoomEvents
  • IOdinPeerEvents

Example

OdinPeerDataChangedEvent 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 whenever a remote peer updated its user data
  odinRoom.addEventListener('PeerUserDataChanged', (event) => {
    console.log('Updated remote peer user data received:', event.payload.peer.data);
  });

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

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

Parameters

NameTypeDescription
eventIOdinEvent<IOdinPeerDataChangedEventPayload>