Skip to content

Avatar


getAvatars

getAvatars(callback: Function)

Gets a list of all avatars currently present in the space.

js
api.getAvatars(function (avatars) {
  const avatar = avatars[0];
  console.log(avatar.name); // "Paul"
  console.log(avatar.id); // "123456789"
})

getAvatarPosition

getAvatarPosition(avatarId: string, callback: Function)

Gets the current position of an avatar. avatarId can be retrieved using getAvatars

js
api.getAvatarPosition(avatarId, function (position) {
	console.log(position); // [ 0, 0, 0 ]
});

setAvatarPosition

setAvatarPosition(position: [x: number, y: number, z: number], [callback: Function])

Set the position of an avatar.

js
api.setAvatarPosition([1, 1, 1], function () {
    console.log('Position updated');
});

isMicrophoneMuted

isMicrophoneMuted[callback: Function])

Returns true if the microphone is muted, false if it is not.

js
api.isMicrophoneMuted(function (isMicrophoneMuted) {
  console.log('Is microphone muted:', isMicrophoneMuted);
});

setMicrophoneMuteState

setMicrophoneMuteState(isMuted: boolean, [callback: Function])

Sets the microphone mute state. (muted/unmuted)

js
api.setMicrophoneMuteState(true, function () {
  console.log('Microphone is muted');
});

setMeshCode

setMeshCode(meshCode: string, [callback: Function])

Set the meshCode for your current avatar. This will also be sent around to all other avatars. The meshCode describes the avatar configuration like the loaded mesh or material. If you are using ready player me: its the url of the glb.

js
api.setMeshCode("https://models.readyplayer.me/62ce5ee548960be56ec72c1a.glb", function () {
  console.log('meshCode was changed');
});

setIdentToken

setIdentToken(identToken: string, [callback: Function])

Set an identToken for the client avatar. This will be sent around to all other avatars and can be validated. You can listen to the avatar.identToken.change Avatar-Event and call your validation.

js
api.setIdentToken("abcdefghijklmnopqrstuvwxyz", function () {
  console.log('identToken was set');
});

setVerifiedIcon

setVerifiedIcon(avatarId: string, state: boolean, [callback: Function])

Set a verified icon for an avatar. You may want to use the identToken for validation. You can listen to the avatar.identToken.change Avatar-Event and call your validation. If you want to set it for your own avatar: avatarId can be empty ("")

js
api.setVerifiedIcon("avatarId", true, function () {
  console.log('identToken was set');
});

complete example

js
// this sends your identToken to all connected avatars
api.setIdentToken("your_ident_token");

const validateAvatar = (avatar) => {
  // use your custom validation here
  let valid = !!avatar.identToken;

  api.setVerifiedIcon(avatar.id, valid);
}

api.on('avatar.enter', validateAvatar);
api.on('avatar.identToken.change', validateAvatar);