00 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Black Friday / Cyber Monday
30% OFF all plugins
Including renewals
Nov 27–30, 2026
The HappyVR player exposes a programmatic API through the VirtualTourApi interface. It gives you full control over the virtual tour: scenes, viewport (camera), audio, UI widgets, styling, and events.
There are three ways to get a VirtualTourApi instance:
1. Custom JS. If the tour config enables customJs, the script is executed with the API instance injected as the virtualtourApi parameter:
// Runs in strict mode
virtualtourApi.sceneApi.show("scene-2");2. Run Script action. When a layer’s action is set to Run Script (ActionType.RunScript), the script runs on layer click with sceneId, layerId, and virtualtourApi injected as parameters:
// Runs in strict mode; fires when the layer is clicked
console.log(sceneId, layerId); // IDs of the clicked layer and its scene
virtualtourApi.sceneApi.show("scene-2");Inside the script, this also refers to the VirtualTourApi instance. Errors are caught and logged to the console, they never break the player.
3. DOM events bridge. Every player event is re-dispatched as a bubbling CustomEvent on the player container element. The detail object contains the event payload plus an api reference to the instance (see Events):
document.querySelector(".happyvr-player").addEventListener("virtualtour:ready", (e) => {
const api = e.detail.api;
});The root facade for a single player instance.
| Method | Description |
|---|---|
on(event, handler) | Subscribes to a virtual tour event (see Events). Returns an unsubscribe function, call it to remove the listener. |
getResourceUrl(resourceType) | Returns the base URL for tour assets ("assets") or control icons ("icons"). |
getId() | Returns the unique ID of the player instance. |
generateId() | Generates a new unique ID (useful for custom entities). |
getContainer() | Returns the original host element the player is mounted in. |
getControlContainer() | Returns the Shadow DOM container where UI widgets are mounted. |
getShadowRoot() | Returns the player’s open Shadow DOM root. |
isLoading() | Returns true while tour resources are being loaded. |
start() | Starts the tour: renders the initial scene, starts audio and auto-rotate. |
destroy() | Destroys the instance and releases all resources. |
styleApi | Read-only property. Returns the StyleApi instance. |
audioApi | Read-only property. Returns the AudioApi instance. |
viewportApi | Read-only property. Returns the ViewportApi instance. |
sceneApi | Read-only property. Returns the SceneApi instance. |
uiApi | Read-only property. Returns the UIApi instance. |
Sub-APIs are exposed directly as getters. You can always access them as core properties on the root instance:
| Method | Description |
|---|---|
applyStyle(style) | Applies a style object or CSS template inside the player’s Shadow DOM; returns the generated class name. |
removeStyle(className) | Removes a previously applied style by its class name. |
| Method | Description |
|---|---|
playTourAudio(audio?) | Plays the tour-level background audio. |
playSceneAudio(audio?) | Plays the current scene’s audio. |
playAudioFromAction(action, context?) | Plays audio defined by a layer’s Play sound action; context carries sceneId/layerId. |
stop(channel?) | Stops a specific sound/channel, or all audio if omitted. |
setMuted(muted) | Sets the global mute state. |
isMuted() | Returns the global mute state. |
setMasterVolume(volume) | Sets the master volume (0–1). |
dispose() | Stops all audio and releases audio resources. |
All angles (yaw, pitch, fov) are in degrees.
| Method | Description |
|---|---|
setOptions(options) | Updates viewport options (background, autoRotate, viewLimits, pan, zoom, sceneTransition). |
getOptions() | Returns the current viewport options. |
getViewer() | Returns the underlying Marzipano viewer instance (low-level escape hatch). |
getViewpoint() | Returns the current camera position (yaw/pitch/fov) or null. |
setViewpoint(viewpoint) | Instantly sets the camera position. |
lookAt(params) | Animates the camera to a viewpoint; returns a promise. |
zoom(params) | Animates to a target fov; smaller value = closer. Returns a promise. |
zoomBy(params) | Zooms by a factor: 2 = twice closer, 0.5 = twice farther. Returns a promise. |
coordToScreen(yaw, pitch) | Converts spherical coordinates to screen pixels; returns null if outside the viewport. |
screenToCoord(x, y) | Converts screen pixels to spherical coordinates; returns null if outside the viewport. |
toggleFullscreen() | Toggles fullscreen mode. |
isFullscreen() | Returns whether fullscreen mode is active. |
updateSize() | Recalculates the viewport size after a container resize. |
| Method | Description |
|---|---|
size() | Returns the number of scenes. |
has(sceneId) | Returns whether a scene exists. |
get(sceneId) | Returns a scene by ID, or null if not found. |
getIndex(sceneId) | Returns the scene’s position in the list, or null. |
getLayer(sceneId, layerId) | Returns a layer of a scene, or null if not found. |
getActive() | Returns the currently visible scene, or null. |
getList() | Returns all scenes in order. |
getNext(loop?) | Returns the next scene; wraps around if loop is true. |
getPrev(loop?) | Returns the previous scene; wraps around if loop is true. |
setDefault(sceneId) | Sets the default (fallback) scene; null clears it. |
getDefault() | Returns the default scene ID, or null. |
add(scene) | Adds a scene. Returns true on success. |
remove(sceneId) | Removes a scene. Returns true on success. |
move(sceneIds, pos) | Moves the given scenes to the given position in the list. Returns true on success. |
show(sceneId, viewpoint?, transition?) | Shows a scene with an optional start viewpoint and transition; returns a promise resolving to true on success. |
hide() | Hides the current scene. Returns true on success. |
| Method | Description |
|---|---|
size() | Returns the number of registered widgets. |
has(controlId) | Returns whether a widget exists. |
get(controlId) | Returns a widget ({ control, component }), or null if not found. |
add(widget) | Registers and mounts a widget. Returns true on success. |
remove(controlId) | Unmounts and removes a widget. Returns true on success. |