Skip to content
dysolix edited this page Apr 8, 2024 · 4 revisions

Subscribing to LCU Events

The addLCUEventListener method allows you to add a listener for LCU events. You can subscribe to events based on various criteria like event path, types, or name. If you subscribe to a path without an event name, then Hasagi subscribes to OnJsonApiEvent.

Syntax

public addLCUEventListener<EventName extends keyof LCUWebSocketEvents = "OnJsonApiEvent">(listener: LCUEventListener): void

Parameters

  • listener: An object specifying the criteria for filtering events and defining the callback function.
    • path (optional): A string or regular expression representing the event's path. If provided, the callback will only be invoked for events with matching paths.
    • types (optional): An array of event types ("Create", "Update", "Delete"). If provided, the callback will only be invoked for events of these types.
    • name (optional): The name of the event. If provided, the callback will only be invoked for events with matching names.
    • callback: The function to be called when an event matching the specified criteria occurs.

Removing LCU event listeners

The removeLCUEventListener method removes a previously added listener for LCU events. It identifies the listener to remove based on the provided parameters such as the callback function, event name, event path, or the entire listener object.

Syntax

public removeLCUEventListener(listener: LCUEventListener | LCUEventListener["callback"] | string): boolean

Parameters

  • listener: The listener to remove, which can be:
    • The entire LCUEventListener object.
    • The callback function.
    • The event name.
    • The event path.

Returns

  • true: If the listener was found and successfully removed.
  • false: If the listener was not found.