Events
on
on(event: string, callback: Function)
Adds a listener function to an event. Parameters passed to the callback will depend on the event. See Events for more information.
api.on('viewer.ready', function() {
console.log('Viewer is ready');
});
once
once(event: string, callback: Function)
Adds a listener function to an event and is removed after one event. Parameters passed to the callback will depend on the event. See Events for more information.
api.once('viewer.ready', function() {
console.log('Viewer is ready');
});
off
off(event: string)
Remove a listener function from an event.
api.off('viewer.ready');
Events
Viewer
viewer.ready
This event is triggered when the viewer is ready.
viewer.start
This event is triggered when the viewer is started.
viewer.stop
This event is triggered when the viewer is stopped.
Mouse
click
This event is triggered when the user clicks or taps on an object that has a link associated with it, or is clickable. An object can be made clickable by setting the Enable click events(en)/Klick-Event aktivieren(de) property to true on the space-editor(v2).
The event listener callback receives a JSON object with the following attributes:
{
"screen_coordinates": [100, 100],
"world_coordinates": [1, 5, 2],
"nodeId": 1234,
"targetNodeId": "clickedNodeId",
"objectName": "This name can be set in the Space Editor"
}
Link
link.open
This event is triggered when the user opens a link from inside the viewer.
The event listener callback receives a JSON object with the following attributes:
{
"link": "https://link.url"
}
Camera
Work in Progress
This events are currently not available in the API, but will be available soon.
camera.start
This event is triggered when the camera begins to move.
camera.stop
This event is triggered when the camera stops moving.
camera.position
This event is triggered every second and contains the current position of the camera.
Avatars
avatar.click
This event is triggered when an avatar is clicked.
avatar.hover
This event is triggered when you hover over an avatar.
avatar.nearby
This event is triggered in intervals containing all nearby avatars.
avatar.enter
This event is triggered when an avatar is entering the space.
avatar.leave
This event is triggered when an avatar left space and is disposed.
avatar.identToken.change
This event is triggered when an avatar has a new identToken. You can use this event to verify the avatar and then call setVerified
avatar.* event data
For the above events the event listener callback receives a JSON object or an array with multiple objects with the following attributes:
{
"id": "a1234-b567-c890",
"externalId": "a1234-b567-c890",
"name": "AvatarsName",
"position": [
1,
2,
3
],
"rotation": [
1,
2,
3
],
"identToken": "1234567890",
"avatarType": "readyplayerme"
}
avatar.meshcode.changed
This event is triggered when the avatar configuration is finished or was changed.
For this event the event listener callback receives a JSON object with the following attributes:
{
"code": "a1234-b567-c890",
"id": "a1234-b567-c890",
"externalId": "a1234-b567-c890",
"name": "AvatarsName",
"position": [
1,
2,
3
],
"rotation": [
1,
2,
3
],
"identToken": "1234567890",
"avatarType": "readyplayerme"
}
Modals
modal.opened
This event is triggered when a modal is opened in the viewer.
modal.closed
This event is triggered when a modal is closed in the viewer.
modal.* event data
For the above events the event listener callback receives a JSON object with the following attribute:
{
"modalName": "Name of the modal",
}
The modal name can be used to close an opened modal with closeModal
Text Chat
text.chat.opened
This event is triggered when the space-viewer text chat box is opened.
text.chat.closed
This event is triggered when the space-viewer text chat box is closed.
Videos
video.progress
This event is triggered when the time indicated by a video's currentTime
attribute changes.
The event listener callback receives a JSON object with the following attributes:
{
"videoId": "1-video", // The id of the video which progressed
"progress": 5.4, // The current progress of the video, in seconds
"duration": 10, // The total duration of the video, in seconds
}
NOTE: The video.progress
event needs to be activated for each video with the getVideoProgressionEvents
api call. The events can be deactivated for each video with thestopVideoProgressionEvents
api calls.