Skip to main content

userDidStartWatchingEvent

Indicates that a user has started watching an event and initializes the event view model.

Overview

When a user starts watching an event, call this method to initialize the necessary components for the Maestro panel and interactive features. This method creates a new event view model and establishes the connection between the SDK and your application's event delegate.

Method Signature

userDidStartWatchingEvent(eventID: string, delegate: IMaestroEventDelegate): Promise<IMaestroEvent>

Parameters

ParameterTypeDescription
eventIDstringThe unique identifier for the event being watched
delegateIMaestroEventDelegateAn implementation of the event delegate interface that handles callbacks from the SDK and and communicate with the client app

See IMaestroEventDelegate

Return Value

A Promise that resolves to an IMaestroEvent instance, which provides methods for interacting with the current event.

Example

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

// Implement the event delegate interface
class MyEventDelegate implements IMaestroEventDelegate {
async userRequestedNewKeyPlaysData(): Promise<void> {
// Fetch new key plays data from your API
const keyPlaysData = await fetchKeyPlaysData();

// Update the SDK with the new data
const event = SDK.getMaestroEventViewModel();
await event.updateKeyPlaysData(keyPlaysData);
}

playClip(atIndex: number): void {
// Implement clip playback in your video player
const event = SDK.getMaestroEventViewModel();

// Start playing the clip
myVideoPlayer.play(atIndex);

// Notify SDK that playback has started
event.didStartPlayingClip(atIndex);

// Track playback progress and report to SDK
myVideoPlayer.onProgress((progress) => {
event.didUpdatePlaybackProgressOfClip(atIndex, progress);
});

// Notify SDK when playback completes
myVideoPlayer.onComplete(() => {
event.didStopPlayingClip(atIndex);
});
}

startFocusManagement(): Promise<void> {
// Set focus back to your application's UI
document.getElementById('my-app-control').focus();
return Promise.resolve();
}
}

// Start watching an event
async function startWatchingEvent(eventID: string) {
const delegate = new MyEventDelegate();

try {
// Initialize the event in the SDK
const event: IMaestroEvent = await SDK.userDidStartWatchingEvent(eventID, delegate);

// Render the panel if needed
await SDK.renderPanel('panel-container');

return event;
} catch (error) {
console.error('Failed to start watching event:', error);
throw error;
}
}

Notes

  • The SDK must be configured with configure() before calling this method.