Request by sending an email to developer@vatom.com
Allows access to user information.
When extending BasePlugin, these functions can be accessed via this.user.*
When extending BaseComponent, these functions can be accessed via this.plugin.user.*
getID() : Promise<string>
Returns the identifier of the user.
const id = await this.user.getID()
console.log(id) // => 'user-id'
getDisplayName() : Promise<string>
Returns the display name of the user.
const name = await this.user.getDisplayName()
console.log(name) // => 'John Doe'
isAdmin() : Promise<boolean>
Returns true
if the user is an admin in this space and false
otherwise. Admins are able to edit objects.
const isAdmin = await this.user.isAdmin()
console.log(isAdmin) // => true
isMuted() : Promise<boolean>
Returns true
if the user is muted and false
if their microphone is 'on air'.
const isMuted = await this.user.isMuted()
console.log(isMuted) // => true
Also see the core.user.audio.mute-change hook to receive a callback when the microphone mute state changes.
getInitialPosition() : Promise<Vector3>
Returns the position that the user will be in when they enter the space, in the form: { x: number, y: number, z: number }
.
const position = await this.user.getInitialPosition()
console.log(position) // => { x: 1, y: 0, z: 2 }
getPosition() : Promise<Vector3>
Returns the position of the user, in the form: { x: number, y: number, z: number }
.
const position = await this.user.getPosition()
console.log(position) // => { x: 2, y: 0, z: 3 }
setPosition(x: number, y: number, z: number, instant = false, keepFollow = true) : Promise<void>
Sets the position of the user.
Field | Type | Description | Example |
---|---|---|---|
x | number | New x position | 2 |
y | number | New y position (height) | 0 |
z | number | New z position (depth) | 3 |
instant | boolean | true to immediately move avatar, false to glide to position. Default is false | false |
keepFollow | boolean | true to keep following the object that the user is currently following, false to stop following. Default is true | true |
await this.user.setPosition(2, 0, 3)
getOrientation(deg = false) : Promise<number>
Returns the orientation of the user in degrees, if deg === true
, or
radians, if deg === false
. Default is in radians.
Field | Type | Description | Example |
---|---|---|---|
deg | boolean | true to use degrees, false to use radians | false |
const orientation = await this.user.getOrientation()
console.log(orientation) // => 1.5708
setOrientation(orient: number, deg = false) : void
Sets the orientation of the user in degrees, if deg === true
, or radians,
if deg === false
. Default is in radians.
Field | Type | Description | Example |
---|---|---|---|
orient | number | New orientation | 1.5708 (if deg === false ) |
deg | boolean | true to use degrees, false to use radians | false |
this.user.setOrientation(1.5708)
getTilt(deg = false): Promise<number>
Returns the tilt value of the user in degrees, if deg === true
, or
radians, if deg === false
. Default is in radians.
Field | Type | Description | Example |
---|---|---|---|
deg | boolean | true to use degrees, false to use radians | false |
const tilt = await this.user.getTilt()
console.log(tilt) // => 0.0115
setTilt(tilt: number, deg = false) : void
Sets the tilt value of the user in degrees, if deg === true
, or radians,
if deg === false
. Default is in radians.
Field | Type | Description | Example |
---|---|---|---|
tilt | number | New tilt | 0.0115 (if deg === false ) |
deg | boolean | true to use degrees, false to use radians | false |
this.user.setTilt(0.0115)
getZoom() : Promise<number>
Returns the zoom level of the user.
const zoom = await this.user.getZoom()
console.log(zoom) // => 12
setZoom(zoom: number) : Promise<boolean>
Sets the zoom level of the user.
Final zoom value is clamped between the "Minimum Zoom Distance" and "Maximum Zoom Distance" settings found in the Editor > World tab.
Field | Type | Description | Example |
---|---|---|---|
zoom | number | New zoom level | 12 |
const success = await this.user.setZoom(12)
console.log(success) // => true
getViewMode() : Promise<string>
Returns the view mode of the user, which will be one of: "swivel"
, "advanced"
or "first-person"
.
const viewMode = await this.user.getViewMode()
console.log(viewMode) // => "advanced"
setViewMode(mode: string, options?: ViewModeOptions) : Promise<boolean>
Sets the view mode of the user, which should be one of: "swivel"
, "advanced"
or "first-person"
, as well as configuration options if provided.
Field | Type | Description | Example |
---|---|---|---|
mode | string | New view mode | "advanced" |
options | object | Options relating to the view mode | { fullscreen: true, pointerLock: true } |
Properties available for the options
parameter
Property | Type | Description | Example |
---|---|---|---|
config | object | Configuration options for the given view mode. Available fields are dependent on the given view mode | {} |
fullscreen | boolean | true to enable fullscreen mode, false to exit fullscreen mode | true |
pointerLock | boolean | true to request pointer lock (only supported in "first-person" view mode), false to exit pointer lock | true |
const success = await this.user.setViewMode("advanced")
console.log(success) // => true
// OR
const success = await this.user.setViewMode(
"first-person",
{
pointerLock: true,
fullscreen: true
}
)
console.log(success) // => true
getFollow() : Promise<boolean>
Returns true
if the user is following another user or object, false
otherwise.
const isFollowing = await this.user.getFollow()
console.log(isFollowing) // => false
setFollow(id: string) : void
Sets the user to follow the object with a matching identifier. Can be an object or another user.
Field | Type | Description | Example |
---|---|---|---|
id | string | Identifier of the user, or object, to follow | '042ed071-649c-4601-9a30-669a59c9e1ee' |
this.user.setFollow('042ed071-649c-4601-9a30-669a59c9e1ee')
releaseFollow() : void
Stops the user from following the user or object that they are currently following, if any.
this.user.releaseFollow()
getProperty(userID: string, property: string) : Promise<any>
Returns a property that had been assigned to the specified user by calling
user.setProperties()
from this plugin.
Leave userID
blank to get the property on the current user.
Field | Type | Description | Example |
---|---|---|---|
userID | string | Identifier of the user to get a property value for | '' |
property | string | Name of the property to retrieve | 'color' |
const color = await this.user.getProperty('', 'color')
console.log(color) // => '#2DCA8C'
getProperties(userID: string) : Promise<UserProps>
Returns all properties that had been assigned to the specified user by calling
user.setProperties()
from this plugin.
Leave userID
blank to get the property on the current user.
Field | Type | Description | Example |
---|---|---|---|
userID | string | Identifier of the user to get all property values for | '' |
const props = await this.user.getProperties('')
console.log(props) // => { id: 'long-form-id:user-id', name: 'John Doe', user_id: 'user-id', role: 'presenter', color: '#2DCA8C' }
setProperties(newProps: UserProps) : Promise<void>
Sets properties for this user within the context of this plugin.
Properties will be merged in. Fields not specified will be left unchanged.
Prefix property names with space:
if you want the value to be specific to
an individual space and not carry over into multiple spaces.
Field | Type | Description | Example |
---|---|---|---|
newProps | object | New property values to assign | { color: '#2DCA8C' } |
await this.user.setProperties({ color: '#2DCA8C' })
getNearbyUsers() : Promise<UserProps[]>
Returns a list of users who are within rendering range.
Each user has the form: { id: string, name: string, userID: string, role: string, distance: number }
const nearbyUsers = await this.user.getNearbyUsers()
console.log(nearbyUsers) // => [{ id: 'long-form-id:user-id', name: 'John Doe', userID: 'user-id', role: 'presenter', distance: 0.5 }]
registerAvatar(props: AvatarProps) : Promise<void>
Registers a custom avatar that users can select in the Profile > Select Avatar menu. See Custom Avatars for more information. The props
object can contain these fields:
Field | Type | Example | Description |
---|---|---|---|
id | string | 'com.myplugin.myavatar' | A unique ID representing this avatar. |
name | string | 'My Avatar' | The name of this avatar. This is displayed to the user in the Select Avatar popup. |
type | string | 'humanoid' | The type of skeleton. If "static" the avatar model will not be dynamically animated except for a simple rotation to face the direction the user is moving. Otherwise, this field represents the skeleton type of the avatar model. The app includes built-in animations for "humanoid" skeleton types, but you can also use your own skeleton type along with your own animations. See Custom Avatars for more info. |
imageURL | string | './preview.jpg' | A URL pointing to the preview image for this avatar. The preview image is displayed to the user in the Select Avatar popup. |
properties | object | { url: '...' } | Object properties for the avatar model. You can specify any object property fields. The object type defaults to 'model' . |
height | number | 1.8 | The avatar's height. Default is 1.8 meters. |
walkingSpeed | number | 2 | The avatar's movement speed while walking. Defaults to 2. |
runningSpeed | number | 4 | The avatar's movement speed while running. Defaults to 4. |
hookOnSetup | string | 'myplugin.onSetup' | If specified, this hook will be called when the user selects the avatar. This gives your plugin the opportunity to modify avatar data, for example you could display an avatar customizer UI to the user and return updated data from the hook once the user completes the setup. You can also return null from the hook to cancel the avatar switch. |
await this.user.registerAvatar({
id: 'com.myplugin.myavatar',
name: 'My Avatar',
type: 'humanoid',
imageURL: this.paths.absolute('./preview.jpg'),
properties: { url: '...' },
height: 1.8,
walkingSpeed: 2,
runningSpeed: 4,
hookOnSetup: 'myplugin.onSetup'
})
unregisterAvatar(id: string) : void
Removes an avatar that was registered.
Field | Type | Description | Example |
---|---|---|---|
id | string | Identifier of the avatar to remove | 'com.myplugin.myavatar' |
this.user.unregisterAvatar('com.myplugin.myavatar')
getAvatarData() : Promise<AvatarProps | null>
Returns the user's avatar data, or null
if the user does not have a custom avatar selected.
See user.registerAvatar(props) for details of the fields returned. It also includes
the extra fields pluginID
and pluginName
which represents the plugin which was used to register the avatar.
const avatarData = await this.user.getAvatarData()
console.log(avatarData) // => { id: 'com.myplugin.myavatar', name: 'My Avatar', type: 'humanoid', imageURL: 'https://example.com/preview.jpg', properties: { url: '...' }, height: 1.8, walkingSpeed: 2, runningSpeed: 4, hookOnSetup: 'myplugin.onSetup', pluginID: 'com.myplugin', pluginName: 'My Plugin' }
setAvatarData(props: AvatarProps) : Promise<void>
Switches the user to the specified avatar data, which may prompt the user to confirm if they want to switch avatars.
See user.registerAvatar(props) for details of the fields that can be specified.
await this.user.setAvatarData({
id: 'com.myplugin.myavatar',
name: 'My Avatar',
type: 'humanoid',
imageURL: 'https://example.com/preview.jpg', // or this.paths.absolute('./preview.jpg')
properties: { url: '...' },
height: 1.8,
walkingSpeed: 2,
runningSpeed: 4,
hookOnSetup: 'myplugin.onSetup'
})
overrideAvatarAnimation(props: AnimationProps | null) : Promise<boolean>
Performs a custom animation override on the current avatar. All users will see the animation. This can be used to play once-off animations or to perform looping animations that are stopped only when the user tries to move around. You can also pass in null
to this function to cancel any existing animation overrides.
Returns true
if the animation was played until the end, or false
if it was cancelled.
Note that all animation names must exclude the type prefix. For example, if you want to play a sit
animation on the humanoid
skeleton, just specify sit
and the app will look for and play a humanoid.sit
animation if the user's avatar is a humanoid
type.
Also see objects.registerAnimations(url) for loading custom animations, or custom avatars for creating your own avatar and attaching custom animations to it.
Field | Type | Example | Description |
---|---|---|---|
animation_start | string | 'sit_start' | An optional animation to play once at the start of the override. |
animation | string | 'sit_loop' | The animation to play during the override. |
animation_end | string | 'sit_end' | An optional animation to play once at the end of the override. |
loop | number | 1 | Can be either a number representing the number of times to loop the animation, or true to loop continuously. Default = 1. |
fixed_movement | object | { x: 0, y: 0, z: 0 } | If specified, this prevents the user from moving, instead moving at a fixed rate of meters per second in the specified direction. Specify 0 for x , y and z to prevent the user from moving at all. |
cancel_mode | string | 'smooth' | Specifies how the animation acts when cancelled by user movement. Specify 'smooth' (the default) to interrupt the loop but continue to play until the end, specify 'immediate' to immediately cancel the animation, or specify 'none' to never cancel. Warning: If you specify 'none' you must cancel the animation yourself by passing in null to this function, or else the user will never be able to move again. |
merge | boolean | true | If true , the animation will not replace the avatar's animation, it will instead be blended together with the default idle, walk, run etc animations. This can be used to play animations that only affect certain parts of the avatar's body, for example waving an arm while still letting the user walk around at the same time, etc. Default = false. |
const success = await this.user.overrideAvatarAnimation({
animation_start: 'sit_start',
animation: 'sit_loop',
animation_end: 'sit_end',
loop: true,
fixed_movement: { x: 0, y: 0, z: 0 },
cancel_mode: 'smooth',
merge: true
})
console.log(success) // => true
showShutdownScreen(msg: string, title: string, btnText: string) : void
Shows an orange overlay indicating that the app has been shutdown.
Field | Type | Description | Example |
---|---|---|---|
msg | string | Message to show | "You have been removed from this space." |
title | string | Title of the screen | "Kicked Out" |
btnText | string | Text to show on the button | "Reload" |
this.user.showShutdownScreen("You have been removed from this space.", "Kicked Out", "Reload")
showAvatarSelectPopup() : void
Shows the screen that allows a user to select their avatar.
this.user.showAvatarSelectPopup()
sendAnalytics(key, value) : void
Send custom analytics data to the backend. Enterprise customers may use this to submit data for custom reports that they request from their Vatom representative.
Parameter | Type | Description | Example |
---|---|---|---|
key | string | single word name for data to be collected | "IdOfUserEnteringThirdRoom" |
value | string, number, or object | data to be collected | "userEvan123" |
this.user.sendAnalytics("IdOfUserEnteringThirdRoom", "userEvan123")