dist/bundle/display.js
import { EventEmitter } from 'eventemitter3';
import { MemorizingSubject } from '../reactive';
/**
* Display modified the display of interactive controls.
*/
export class Display extends EventEmitter {
constructor(rpc) {
super();
this.rpc = rpc;
this.settingsSubj = new MemorizingSubject();
this.videoPositionSubj = new MemorizingSubject();
rpc.expose('updateVideoPosition', (pos) => {
this.videoPositionSubj.next(pos);
});
rpc.expose('updateSettings', (settings) => {
this.settingsSubj.next(settings);
this.emit('settings', settings);
});
}
/**
* Hides the controls and displays a loading spinner, optionally
* with a custom message. This is useful for transitioning. If called
* while the controls are already minimized, it will update the message.
* @param {string} [message]
*/
minimize(message) {
this.rpc.call('maximize', { maximized: false, message }, false);
}
/**
* Restores previously minimize()'d controls.
*/
maximize() {
this.rpc.call('maximize', { maximized: true }, false);
}
/**
* Moves the position of the video on the screen.
* @param {IVideoPositionOptions} options
*/
moveVideo(options) {
this.rpc.call('moveVideo', options, false);
}
/**
* Returns an observable of the video's current position, relative to
* the frame's screen. For example, you can use it to set the position
* of an overlaid div:
*
* ```
* mixer.display.position().subscribe(position => {
* videoOverlay.style.top = `${position.top}px`;
* videoOverlay.style.left = `${position.left}px`;
* videoOverlay.style.height = `${position.height}px`;
* videoOverlay.style.width = `${position.width}px`;
* });
* ```
* @return {Observable.<IVideoPositionList>}
*/
position() {
return this.videoPositionSubj;
}
/**
* Returns an observable of the current project settings.
* @return {Observable.<ISettings>}
*/
settings() {
return this.settingsSubj;
}
/**
* Returns the video position at this moment in time. Returns undefined if
* the video position hasn't been sent yet. If undefined, you should retry,
* or listen to the `display.position()` observable to be notified when
* it comes in.
* @return {IVideoPositionList | undefined}
*/
getPosition() {
return this.videoPositionSubj.hasValue() ? this.videoPositionSubj.getValue() : undefined;
}
/**
* Returns the current display settings at this instant in time. It will
* be `undefined` if the settings have not been sent yet. If undefined,
* you should retry, or listen to the `display.settings()` observable to
* be notified when it comes in.
* @return {ISettings | undefined}
*/
getSettings() {
return this.settingsSubj.hasValue() ? this.settingsSubj.getValue() : undefined;
}
on(event, handler) {
super.on(event, handler);
return this;
}
}