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 (see IMaestroEvent).
Throws
- Throws an error if no event view model has been set (i.e., if
userDidStartWatchingEvent
has not been called or ifuserDidStopWatchingEvent
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.');
}
}
}
Notes
- This method should be called only after
userDidStartWatchingEvent
has been successfully called. - The returned view model provides access to all event-related functionality.