Skip to main content

getMaestroEventViewModel

Retrieves the current event view model instance.

Overview

The getMaestroEventViewModel method provides access to the event view model, which contains methods and properties for interacting with the current event. This view model implements the IMaestroEvent interface and is created when userDidStartWatchingEvent is called.

Method Signature

getMaestroEventViewModel(): MaestroEventViewModel

Parameters

This method does not take any parameters.

Return Value

Returns the current MaestroEventViewModel instance, which implements the IMaestroEvent interface.

Throws

  • Throws an error if no event view model has been set (i.e., if userDidStartWatchingEvent has not been called or if userDidStopWatchingEvent has been called).

Example

import SDK, { IMaestroKeyPlaysResponse } from '@maestro_io/maestro-web-sdk';

// Function to update key plays data
async function updateKeyPlaysData(newData: IMaestroKeyPlaysResponse) {
try {
// Get the current event view model
const eventViewModel = SDK.getMaestroEventViewModel();

// Update the key plays data
await eventViewModel.updateKeyPlaysData(newData);

console.log('Key plays data updated successfully');
} catch (error) {
console.error('Failed to update key plays data:', error);

// Handle the case where no event view model is set
if (error.message.includes('No Maestro Event View Model set')) {
console.error('No event is currently being watched. Call userDidStartWatchingEvent first.');
}
}
}

IMaestroEvent Interface

The returned view model implements the following interface:

interface IMaestroEvent {
/**
* @description Tells the SDK that the user just started playing a new key play clip at the given index.
*/
didStartPlayingClip(index: number): void;

/**
* @description Tells the SDK that the user just stopped playing a key play clip at the given index.
*/
didStopPlayingClip(index: number): void;

/**
* @description Tells the SDK that the user tried to play the clip but it failed to play back.
*/
didFailToPlayClip(index: number): void;

/**
* @description Updates the SDK with the latest progress in the playback of the currently-played key play clip, from 0 to 1.
*/
didUpdatePlaybackProgressOfClip(index: number, to: number): void;

/**
* @description Tells the SDK that the app displayed the MaestroPanel.
*/
didShowPanel(): Promise<void>;

/**
* @description Tells the SDK that the app hid the MaestroPanel.
*/
didHidePanel(): Promise<void>;

/**
* @description Alerts the SDK that the current event does not support key plays.
*/
currentEventDoesNotSupportKeyPlays(): void;

/**
* @description Retrieves the event ID for the currently loaded event.
*/
getCurrentEventID(): string | null;

/**
* @description Retrieves the array index of the key play clip that is currently being played.
*/
getCurrentlyPlayingClipIndex(): number | null;

/**
* @description Retrieves the array index of the key plays clip that was most recently played.
*/
getLastPlayedClipIndex(): number | null;

/**
* @description Retrieves the progress (between 0 and 1) of the currently-played key play clip.
*/
getCurrentClipPlaybackProgress(): number | null;

/**
* @description Retrieves the number of key plays.
*/
getKeyPlaysCount(): number | null;

/**
* @description Tells the SDK to start managing focus.
*/
startFocusManagement(): Promise<void>;

/**
* @description Feeds the SDK new key plays data. A null value indicates a failure to retrieve the data.
*/
updateKeyPlaysData(data: IMaestroKeyPlaysResponse | null): Promise<void>;
}

Notes

  • This method should be called only after userDidStartWatchingEvent has been successfully called.
  • The returned view model provides access to all event-related functionality.