@4players/odin
Version:
A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects
31 lines (30 loc) • 946 B
JavaScript
/**
* Custom Event providing Odin Event Payload of a provided type.
*/
export class OdinEvent extends Event {
constructor(type, payload) {
super(type);
this.payload = payload;
}
}
/**
* A generic event target class designed for strongly-typed event handling.
* OdinEventTarget extends the functionality of the standard EventTarget to allow
* interactions with predefined event types and handlers.
*
* @template Events The mapping of event type names to handler callback signatures.
*/
export class OdinEventTarget {
constructor() {
this._eventTarget = new EventTarget();
}
addEventListener(eventName, handler, options) {
this._eventTarget.addEventListener(eventName, handler, options);
}
dispatchEvent(event) {
this._eventTarget.dispatchEvent(event);
}
removeEventListener(type, callback) {
this._eventTarget.removeEventListener(type, callback);
}
}