Event Dispatching Class
Event dispatching class(EventDispatcher)
- The event subscription and dispatch mechanism is the core mechanism for the operation of the room, and most of the communication between room functions is completed through this mechanism. EventDispatcher is the core implementation of this mechanism.
EventDispatcher
- This method instantiates an EventDispatcher object, which controls the listening and dispatching of various events within the room.
- Method Example
1 |
|
dispatchEvent
- This method dispatches a specific event to all listeners
Parameter Name | Required | Type | Description |
---|---|---|---|
eventData | Yes | Object | Event description object. Detailed object properties are described below |
log | No | Boolean | Whether to print logs (at debug level), defaults to true |
- eventData
Parameter Name | Type | Description |
---|---|---|
type | String | Event type, corresponding to the eventType passed when registering the event listener |
... | any | Other attributes can be defined and added as needed. Listeners will receive the entire event object. By unpacking it according to the encapsulation format, the data carried by the event can be obtained |
- Method Example
1 2 3 |
|
addEventListener
- This method adds a listener (callback function) for a specific type of event to the event dispatcher. When the event is triggered, the event dispatcher will notify (invoke) this listener
Parameter Name | Required | Type | Description |
---|---|---|---|
eventType | Yes | String | Event type. Corresponds to the type property of the event dispatched by the dispatchEvent method |
listener | Yes | Function | Event listener callback function. This function will be triggered after the event is dispatched |
- Method Example
1 2 |
|
removeEventListener
- This method removes a listener for a specific type of event. After removal, the event dispatcher will no longer notify this listener when the event is dispatched
Parameter Name | Required | Type | Description |
---|---|---|---|
eventType | Yes | String | Event type. Corresponds to the type property of the event dispatched by the dispatchEvent method |
listener | Yes | Function | Event listener. After removal, this function will no longer be triggered |
- Method Example
1 |
|
removeAllEventListener
- This method removes all listeners for the specified event
Parameter Name | Required | Type | Description |
---|---|---|---|
eventTypeArray | Yes | Array | Array of event types |
- Method Example
1 |
|