Avatar
getAvatars
getAvatars(callback: Function)
Gets a list of all avatars currently present in the space.
api.getAvatars(function (avatars) {
const avatar = avatars[0];
console.log(avatar.name); // "Paul"
console.log(avatar.id); // "123456789"
console.log(avatar.isSelf); // true/false
})
getAvatarPosition
getAvatarPosition(avatarId: string, callback: Function)
Gets the current position of an avatar. avatarId
can be retrieved using getAvatars
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.
api.setAvatarPosition([1, 1, 1], function () {
console.log('Position updated');
});
getAvatarRotation
getAvatarRotation(avatarId: string, callback: Function)
Gets the current rotationY of an avatar (in Radians). avatarId
can be retrieved using getAvatars
api.getAvatarRotation(avatarId, function (rotationY) {
console.log(rotationY); // 3.14
});
setAvatarRotation
setAvatarRotation(rotationY: number, [callback: Function])
Set the rotationY of an avatar.
api.setAvatarRotation(rotationY, function () {
console.log('Rotation updated');
});
isMicrophoneMuted
isMicrophoneMuted[callback: Function])
Returns true if the microphone is muted, false if it is not.
api.isMicrophoneMuted(function (isMicrophoneMuted) {
console.log('Is microphone muted:', isMicrophoneMuted);
});
setMicrophoneMuteState
setMicrophoneMuteState(isMuted: boolean, [callback: Function])
Sets the microphone mute state. (muted/unmuted)
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.
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.
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 (""
)
api.setVerifiedIcon("avatarId", true, function () {
console.log('identToken was set');
});
complete example
// 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);