Class LGTVHandler

The LGTVHandler class manages the connection and interactions with an LG TV. It handles WebSocket communication, registration, and provides methods to control various TV functionalities.

Constructors

  • Initializes a new instance of the LGTVHandler class.

    Parameters

    • protocol: string

      The WebSocket protocol ('ws' or 'wss').

    • ip: string

      The IP address of the LG TV.

    • port: number

      The port number for the WebSocket connection.

    • macAddress: string

      The MAC address of the LG TV for WOL.

    • OptionalkeyPath: string

      (Optional) Custom path for storing client keys. Defaults to './keys'.

    Returns LGTVHandler

Properties

ip: string
isConnected: boolean
isRegistered: boolean
keyPath: string
macAddress: string
port: number
protocol: string
uri: string
ws: ReconnectingWebSocket

Methods

  • Periodically checks and ensures the sound output matches the desired setting.

    Parameters

    • soundOutput: SoundOutput

      The desired sound output setting.

    Returns Promise<undefined | string>

    A message if the sound output value is invalid.

  • Closes a specific alert dialog on the TV.

    Parameters

    • alertId: string

      The ID of the alert to close.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Closes a specific toast notification on the TV.

    Parameters

    • toastId: string

      The ID of the toast to close.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Retrieves information about a specific TV channel.

    Parameters

    • channelId: string

      The ID of the channel.

    Returns Promise<LGWebSocketResponse>

    A promise with the channel information.

  • Inserts text into the currently focused input field on the TV.

    Parameters

    • text: string

      The text to insert.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Launches a specific app on the TV.

    Parameters

    • appId: string

      The ID of the app to launch.

    Returns Promise<LaunchAppResponse>

    A promise with the launch app response.

  • Sends a message through the WebSocket connection.

    Parameters

    • type: string

      The type of the message ('register', 'request', etc.).

    • Optionaluri: string

      The specific endpoint URI.

    • Optionalpayload: any

      The payload data to send.

    • prefix: string = ...

      The prefix for the URI (default is 'ssap://').

    Returns Promise<LGWebSocketResponse>

    A promise that resolves with the server's response.

  • Sets new calibration settings.

    Parameters

    • calibration: any

      The calibration data to set.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Sets the TV to a specific channel.

    Parameters

    • channelId: string

      The ID of the channel to set.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Sets the active input source.

    Parameters

    • inputId: string

      The ID of the input source to activate.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Sets the TV volume to a specified level.

    Parameters

    • volume: number

      The desired volume level.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Displays an alert dialog on the TV.

    Parameters

    • message: string

      The message to display in the alert.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Displays a toast notification on the TV.

    Parameters

    • message: string

      The message to display in the toast.

    Returns Promise<LGWebSocketResponse>

    A promise indicating the result of the operation.

  • Stops the audio checker interval if it's running.

    Returns void

  • Toggles the power state of the TV. If the TV is off, sends a Wake-on-LAN packet.

    Returns Promise<unknown>

    A promise indicating the result of the operation.