-
- All Implemented Interfaces:
-
com.brightcove.player.event.EventEmitter
public class EventEmitterImpl implements EventEmitter
The 'Main' implementation of EventEmitter. Most Components should use this, as should RegisteringEventEmitter.
-
-
Constructor Summary
Constructors Constructor Description EventEmitterImpl()
-
Method Summary
Modifier and Type Method Description int
on(String eventType, EventListener listener)
Adds the listener to the event queue, returns a token that thecaller can use to off itself. int
once(String eventType, EventListener listener)
Similar to on, except that the listener is removed afterprocessing one event. void
off()
Removes all listeners. void
off(String eventType, int token)
Removes a listener from an event queue, using the token as a reference void
emit(String eventType)
Emits an event. void
emit(String eventType, Map<String, Object> properties)
Emits an event, passing along the properties map void
emitNow(String eventType, Map<String, Object> properties)
Emits an event immediately instead of waiting for the handler. void
request(String eventType, EventListener listener)
Attaches a listener and fires off an event of eventType, with the hope that there's a corresponding listener setto 'respond' to the listener specified in the request. void
request(String eventType, Map<String, Object> properties, EventListener listener)
Similar to above, except the properties map is passed along void
respond(Map<String, Object> properties)
Meant to respond to a request event. void
respond(Event event)
Convenience method to save the user from typing event. void
enable()
Enables listener registration and event emitting. void
disable()
Disables listener registration and event emitting. -
-
Method Detail
-
on
int on(String eventType, EventListener listener)
Adds the listener to the event queue, returns a token that thecaller can use to off itself. Calls to on are stored in theorder they arrive, which means that during event propagation,the listeners will be executed in the order they were added.
- Parameters:
eventType
- A String representing the Event to be listened forlistener
- An abstract class of EventListener, that contains a method to process during an Event's firing
-
once
int once(String eventType, EventListener listener)
Similar to on, except that the listener is removed afterprocessing one event.
- Parameters:
eventType
- Same as for 'on'; a string representing the event to be listened forlistener
- Subclass of EventListener
-
off
void off()
Removes all listeners.
-
off
void off(String eventType, int token)
Removes a listener from an event queue, using the token as a reference
- Parameters:
eventType
- A string representing the Event typetoken
- Integer-valued token that was created during 'on'
-
emit
void emit(String eventType)
Emits an event. All listeners attached to this event will be processed
-
emit
void emit(String eventType, Map<String, Object> properties)
Emits an event, passing along the properties map
-
emitNow
@RestrictTo(value = RestrictTo.Scope.LIBRARY)@MainThread() void emitNow(String eventType, Map<String, Object> properties)
Emits an event immediately instead of waiting for the handler.
- Parameters:
eventType
- The event type.properties
- The properties to send when processing the event.
-
request
void request(String eventType, EventListener listener)
Attaches a listener and fires off an event of eventType, with the hope that there's a corresponding listener setto 'respond' to the listener specified in the request.
The flow looks something like:
request ->emit eventType -> eventType listener picks up event -> respond -> listener passed into request is called
After the listener is executed, it is removed
- Parameters:
eventType
- The type of Event to emit and expect a response fromlistener
- A listener to process the response.
-
request
void request(String eventType, Map<String, Object> properties, EventListener listener)
Similar to above, except the properties map is passed along
- Parameters:
eventType
- The type of Event to emit and expect a response fromproperties
- A Map of properties to pass along the event chainlistener
- A listener to process the response.
-
respond
void respond(Map<String, Object> properties)
Meant to respond to a request event. By way of using Event.REQUEST_TOKEN to identify the listener created duringthe request, the respond fires an event 'directly' at said listener. Note that if the properties map does not containEvent.REQUEST_TOKEN, this method is a no-op. The intent for this behavior is that if an EventListener contains acall to respond, but there was no actual request, nothing should break (e.g. several 'play' event listeners, butonly one is intended to respond to requests.
-
respond
void respond(Event event)
Convenience method to save the user from typing event.properties when responding
- Parameters:
event
- An Event containing properties to pass on to the Request listener
-
enable
void enable()
Enables listener registration and event emitting.
-
disable
void disable()
Disables listener registration and event emitting.
-
-
-
-