Class: MessageBus

OO. MessageBus

Represents the Ooyala V4 Player Message Bus. Use message bus events to subscribe to or publish player events from video to ad playback.

When you create an OO.Player object (for example, myplayer = OO.Player.create(...) ), that object contains a Message Bus object named mb. For example, you would access the publish() method by calling myplayer.mb.publish(...).

MessageBus()

Initialize an instance of the current class using the new keyword along with this constructor.

Methods

addDependent(eventName, dependentEvent, subscriber, onMergeParams)

Enables you to send a publish or subscribe message that is dependent on a condition or event. For example, you might want to change the UI based on the location or time of day. This method blocks the event (eventName) until the dependent event (dependentEvent) fires. For more information and examples of usage, see Listening to a Message Bus Event.
Parameters:
Name Type Description
eventName String The name of the event.
dependentEvent String The name of the event that triggers the specified event name.
subscriber String The name of the subscriber to which the message bus will publish the event.
onMergeParams function (Optional) A function used to pass data to the handler for the dependent event. This function is only necessary if need to complete a computation before passing data to the dependent event handler. This function can take up to four arguments and returns an array of arguments to be passed into the dependent event listener.
Example
//  This blocks the PAUSED event from firing until
       // the 'user_allowed_pause' event has fired
       player.mb.addDependent(
         OO.EVENTS.PAUSED,
         'user_allowed_pause',
         'example',
         function(){}
       );

removeDependent(source, target)

Removes all dependencies on event 'source' by event 'target'
Parameters:
Name Type Description
source string The depending event that is blocked
target string The dependent event that is blocking

publish(eventName)

Enables you to publish events to the message bus.
Parameters:
Name Type Description
eventName String The name of the event. Comma-separated arguments for the event may follow the event name as needed.
Examples
myplayer.mb.publish(OO.EVENTS.PLAY);
myplayer.mb.publish(OO.EVENTS.WILL_CHANGE_FULLSCREEN,true);

subscribe(eventName, subscriber, callback)

Subscribe to an event published to the message bus.
Parameters:
Name Type Description
eventName String The name of the event.
subscriber String The name of the subscriber to which the message bus will publish the event.
callback function The function that will execute when the subscriber receives the event notification.
Examples
myplayer.mb.subscribe(OO.EVENTS.METADATA_FETCHED, 'example', function(eventName) {});
// Subscribes to all events published by the Message Bus
messageBus.subscribe("*", 'example', function(eventName) {});

unsubscribe(eventName, subscriber, callback)

Unsubscribes from an event published to the message bus.
Parameters:
Name Type Description
eventName String The name of the event.
subscriber String The name of the subscriber to which the message bus will unsubscribe from the event.
callback function The function that normally executes when the subscriber receives the event notification.
Examples
messageBus.unsubscribe(OO.EVENTS.METADATA_FETCHED, 'example', function(eventName) {});
// Unsubscribes from all events published by the Message Bus
messageBus.unsubscribe("*", 'example', function(eventName) {});