View on GitHub

webOS TV

A promise-based package to control webOS based TVs with JavaScript.

webOS / Exports / webos-tv / TV

Class: TV

webos-tv.TV

A promise-based package to control webOS based TVs with JavaScript.

Author

Giorgio Garasto giorgio@garasto.me

Link

https://github.com/Dabolus/webos-tv

License

MIT

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

• new TV(hostname)

Connects to a webOS TV to the given hostname.

Parameters

Name Type Description
hostname string The hostname of the webOS TV to connect to

Defined in

src/webos-tv.ts:77

Properties

callbacks

• Private callbacks: Record<string, { reject: (err: Error) => void ; resolve: (val: any) => void }> = {}

Defined in

src/webos-tv.ts:62


config

• Private config: Config

Defined in

src/webos-tv.ts:58


connection

• Private Readonly connection: WebSocket

Defined in

src/webos-tv.ts:57


connectionOpened

• Private Readonly connectionOpened: Promise<Event>

Defined in

src/webos-tv.ts:59


currId

• Private currId: number = 0

Defined in

src/webos-tv.ts:61


specializedSockets

• Private specializedSockets: Record<string, SpecializedWebSocket> = {}

Defined in

src/webos-tv.ts:70

Accessors

nextId

• Private get nextId(): string

Returns

string

Defined in

src/webos-tv.ts:21

Methods

appList

▸ appList(): Promise<AppListResult>

Gets the list of the available apps.

Returns

Promise<AppListResult>

A promise that resolves to the list of the available apps

Defined in

src/webos-tv.ts:492


appState

▸ appState(id, sessionId): Promise<AppStateTVResponse>

Gets the app state.

Parameters

Name Type Description
id string The ID of the app
sessionId string The ID of the session

Returns

Promise<AppStateTVResponse>

A promise that resolves to the specified app state

Defined in

src/webos-tv.ts:465


authenticate

▸ authenticate(clientKey?): Promise<string>

Sends an authentication request to the webOS TV.

Parameters

Name Type Description
clientKey? string The client key to send to the webOS TV to authenticate your app. Leave empty if it is your first connection

Returns

Promise<string>

A promise that resolves to an auth key. Remember to store the auth key somewhere to use it again next time

Defined in

src/webos-tv.ts:133


channelDown

▸ channelDown(): Promise<GetCurrentChannelTVResponse>

Sends a channel down signal to the webOS TV.

Returns

Promise<GetCurrentChannelTVResponse>

A promise that resolves to the new channel of the webOS TV

Defined in

src/webos-tv.ts:231


channelUp

▸ channelUp(): Promise<GetCurrentChannelTVResponse>

Sends a channel up signal to the webOS TV.

Returns

Promise<GetCurrentChannelTVResponse>

A promise that resolves to the new channel of the webOS TV

Defined in

src/webos-tv.ts:222


check3DStatus

▸ check3DStatus(): Promise<TV3DStatus>

Returns the current 3D status of the webOS TV.

Returns

Promise<TV3DStatus>

A promise that resolves to the status of the 3D on the webOS TV

Defined in

src/webos-tv.ts:586


closeApp

▸ closeApp(id): Promise<void>

Closes the app with the specified ID.

Parameters

Name Type Description
id string The ID of the app to close

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:525


closeMediaViewer

▸ closeMediaViewer(): Promise<void>

Closes the media viewer.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:445


decreaseVolume

▸ decreaseVolume(deltaVolume?): Promise<GetVolumeTVResponse>

Decreases the webOS TV volume by the specified delta.

Parameters

Name Type Default value Description
deltaVolume number 1 The volume to remove from the webOS TV

Returns

Promise<GetVolumeTVResponse>

A promise that resolves to the new volume of the webOS TV

Defined in

src/webos-tv.ts:321


deleteText

▸ deleteText(count): Promise<void>

Deletes the given number of characters on the webOS TV.

Parameters

Name Type Description
count number The number of characters to delete

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:685


disable3D

▸ disable3D(): Promise<boolean>

Disables 3D on the webOS TV.

Returns

Promise<boolean>

A promise that resolves to the new status of the 3D of the webOS TV (always false)

Defined in

src/webos-tv.ts:566


disconnect

▸ disconnect(): Promise<CloseEvent>

Disconnects from the webOS TV.

Returns

Promise<CloseEvent>

A promise that resolves to the connection close event when the connection is closed

Defined in

src/webos-tv.ts:94


enable3D

▸ enable3D(): Promise<boolean>

Enables 3D on the webOS TV.

Returns

Promise<boolean>

A promise that resolves to the new status of the 3D of the webOS TV (always true)

Defined in

src/webos-tv.ts:555


fastForward

▸ fastForward(): Promise<void>

Sends the fast forward command to the webOS TV.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:435


foregroundAppInfo

▸ foregroundAppInfo(): Promise<ForegroundAppInfoTVResponse>

Gets info about the foreground app.

Returns

Promise<ForegroundAppInfoTVResponse>

A promise that resolves to the info of the foreground app

Defined in

src/webos-tv.ts:453


getAudioStatus

▸ getAudioStatus(): Promise<GetAudioStatusTVResponse>

Checks the current status of the audio of the webOS TV.

Returns

Promise<GetAudioStatusTVResponse>

A promise that resolves to the current audio status of the webOS TV

Defined in

src/webos-tv.ts:350


getChannelList

▸ getChannelList(): Promise<GetChannelListTVResponse>

Gets the list of the channels on the webOS TV.

Returns

Promise<GetChannelListTVResponse>

The list of the channels on the webOS TV

Defined in

src/webos-tv.ts:204


getCurrentChannel

▸ getCurrentChannel(): Promise<GetCurrentChannelTVResponse>

Gets the current channel from the webOS TV.

Returns

Promise<GetCurrentChannelTVResponse>

A promise that resolves to the currently active channel on the webOS TV

Defined in

src/webos-tv.ts:212


getCurrentSWInformation

▸ getCurrentSWInformation(): Promise<GetCurrentSWInformationTVResponse>

Gets the current SW information

Returns

Promise<GetCurrentSWInformationTVResponse>

A promise that resolves to the current software information

Defined in

src/webos-tv.ts:482


getPointerInputSocket

▸ getPointerInputSocket(): Promise<PointerInputSocket>

Requests a pointer input socket to the webOS TV.

Returns

Promise<PointerInputSocket>

A promise that resolves to a specialized pointer input socket

Defined in

src/webos-tv.ts:643


getRemoteKeyboardSocket

▸ getRemoteKeyboardSocket(): Promise<RemoteKeyboardSocket>

Requests a remote keyboard socket to the webOS TV.

Returns

Promise<RemoteKeyboardSocket>

A promise that resolves to a specialized remote keyboard socket

Defined in

src/webos-tv.ts:654


getServiceList

▸ getServiceList(): Promise<GetServiceListResult>

Gets the service list from the webOS TV.

Returns

Promise<GetServiceListResult>

A promise that resolves to the list of services of the webOS TV

Defined in

src/webos-tv.ts:194


getSocket

▸ getSocket<T>(uri, SocketClass): Promise<T>

Requests a specialized socket to the webOS TV.

Type parameters

Name Type
T extends SpecializedWebSocket

Parameters

Name Type Description
uri string The URI of the action to ask the specialized socket for
SocketClass Constructor<T> The class of the specialized socket to instantiate. It should be a SpecializedWebSocket or a class that extends it.

Returns

Promise<T>

Defined in

src/webos-tv.ts:623


getVolume

▸ getVolume(): Promise<GetVolumeTVResponse>

Gets the current volume information from the webOS TV.

Returns

Promise<GetVolumeTVResponse>

A promise that resolves to the current volume information of the webOS TV

Defined in

src/webos-tv.ts:280


handleMessage

▸ Private handleMessage(message): void

Parameters

Name Type
message Data

Returns

void

Defined in

src/webos-tv.ts:704


increaseVolume

▸ increaseVolume(deltaVolume?): Promise<GetVolumeTVResponse>

Increases the webOS TV volume by the specified delta.

Parameters

Name Type Default value Description
deltaVolume number 1 The volume to add to the webOS TV

Returns

Promise<GetVolumeTVResponse>

A promise that resolves to the new volume of the webOS TV

Defined in

src/webos-tv.ts:309


is3DEnabled

▸ is3DEnabled(): Promise<boolean>

Checks whether the 3D on the webOS TV is currently enabled or not.

Returns

Promise<boolean>

A promise that resolves to a boolean indicating whether the 3D is enabled or not

Defined in

src/webos-tv.ts:546


isMuted

▸ isMuted(): Promise<boolean>

Checks whether the webOS TV is currently muted or not.

Returns

Promise<boolean>

A promise that resolves to the current mute status of the webOS TV

Defined in

src/webos-tv.ts:358


launchApp

▸ launchApp(id): Promise<LaunchAppTVResponse>

Launches the app with the specified ID.

Parameters

Name Type Description
id string The ID of the app to launch

Returns

Promise<LaunchAppTVResponse>

A promise

Defined in

src/webos-tv.ts:514


launchPoints

▸ launchPoints(): Promise<LaunchPointsTVResponse>

Lists the launch points of the webOS TV.

Returns

Promise<LaunchPointsTVResponse>

A promise that resolves to the list of the available launch points

Defined in

src/webos-tv.ts:503


loadIcon

▸ Private loadIcon(url, extension?): Promise<{ iconData: string ; iconExtension: string }>

Parameters

Name Type
url string
extension? string

Returns

Promise<{ iconData: string ; iconExtension: string }>

Defined in

src/webos-tv.ts:716


mute

▸ mute(): Promise<boolean>

Mutes the webOS TV.

Returns

Promise<boolean>

A promise that resolves to the new mute state of the webOS TV (always true)

Defined in

src/webos-tv.ts:378


openChannel

▸ openChannel(channelId): Promise<GetCurrentChannelTVResponse>

Sends an open channel signal to the webOS TV.

Parameters

Name Type Description
channelId string The channel to open. It has to be a string representing the unique identifier of the channel

Returns

Promise<GetCurrentChannelTVResponse>

A promise that resolves to the new channel of the webOS TV

Defined in

src/webos-tv.ts:241


openChannelByName

▸ openChannelByName(channelName): Promise<GetCurrentChannelTVResponse>

Sends an open channel signal to the webOS TV for the specified channel name.

Parameters

Name Type Description
channelName string | number The channel name to open. If the TV has multiple channels with the same name, the first match will be opened.

Returns

Promise<GetCurrentChannelTVResponse>

A promise that resolves to the new channel of the webOS TV

Defined in

src/webos-tv.ts:267


openChannelByNumber

▸ openChannelByNumber(channelNumber): Promise<GetCurrentChannelTVResponse>

Sends an open channel signal to the webOS TV for the specified channel number.

Parameters

Name Type Description
channelNumber string | number The channel number to open. If the TV has multiple channels with the same number, the first match will be opened.

Returns

Promise<GetCurrentChannelTVResponse>

A promise that resolves to the new channel of the webOS TV

Defined in

src/webos-tv.ts:251


openURL

▸ openURL(target): Promise<OpenURLTVResponse>

Opens the webOS TV browser at the specified URL. Will open a new tab if the browser is already opened.

Parameters

Name Type Description
target string The target URL to open

Returns

Promise<OpenURLTVResponse>

A promise that resolves to the session ID of the tab opened in the browser

Defined in

src/webos-tv.ts:536


pause

▸ pause(): Promise<void>

Sends the pause command to the webOS TV.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:419


play

▸ play(): Promise<void>

Sends the play command to the webOS TV.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:403


request

▸ request<T>(uri, payload?): Promise<T>

Requests the specified URI with the specified payload to the webOS TV. Syntactic sugar of send('request', uri, payload)

Type parameters

Name Type
T unknown

Parameters

Name Type Description
uri string The URI of the action
payload? Record<string, unknown> The optional payload of the action

Returns

Promise<T>

A promise that resolves to the response from the webOS TV

Defined in

src/webos-tv.ts:151


rewind

▸ rewind(): Promise<void>

Sends the rewind command to the webOS TV.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:427


send

▸ send<T>(type, uri?, payload?): Promise<T>

Sends the action of the specified type and URI and with the specified payload to the webOS TV.

Type parameters

Name Type
T unknown

Parameters

Name Type Description
type string The type of the action
uri? string The URI of the action
payload Record<string, unknown> The optional payload of the action

Returns

Promise<T>

A promise that resolves to the response from the webOS TV

Defined in

src/webos-tv.ts:108


sendEnter

▸ sendEnter(): Promise<void>

Sends an enter key to the webOS TV.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:698


setMute

▸ setMute(mute): Promise<boolean>

Sets the mute status of the webOS TV.

Parameters

Name Type
mute boolean

Returns

Promise<boolean>

A promise that resolves to the new mute status of the webOS TV

Defined in

src/webos-tv.ts:367


setVolume

▸ setVolume(volumeToSet): Promise<GetVolumeTVResponse>

Sets the volume on the webOS TV.

Parameters

Name Type Description
volumeToSet number | "max" | "min" The new volume. It can either be a number, or the literal strings ‘max’ or ‘min’

Returns

Promise<GetVolumeTVResponse>

A promise that resolves to the new volume of the webOS TV

Defined in

src/webos-tv.ts:289


showNotification

▸ showNotification(message, iconUrl?, iconExtension?): Promise<string>

Shows a toast notification on the webOS TV.

Parameters

Name Type Description
message string The message to show in the toast
iconUrl? string The optional URL of the icon to show in the toast. It must be a valid (fetchable) URL to an image file (either HTTP(S), data URI, or file URI)
iconExtension? string The extension of the icon, automatically detected from the icon URL by default. You can provide it explicitly in case automatic detection fails

Returns

Promise<string>

A promise that resolves to the ID of the shown toast notification.

Defined in

src/webos-tv.ts:600


stop

▸ stop(): Promise<void>

Sends the stop command to the webOS TV.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:411


subscribe

▸ subscribe<T>(uri, payload?): Promise<T>

Sends a subscription request to the specified URI and with the specified payload to the webOS TV. Syntactic sugar of send('subscribe', uri, payload)

Type parameters

Name Type
T unknown

Parameters

Name Type Description
uri string The URI of the action to subscribe to
payload? Record<string, unknown> The optional payload of the action

Returns

Promise<T>

A promise that resolves to the response from the webOS TV

Defined in

src/webos-tv.ts:175


toggle3D

▸ toggle3D(): Promise<boolean>

Toggles the 3D status of the webOS TV.

Returns

Promise<boolean>

A promise that resolves to the 3D status of the webOS TV (always the opposite of the previous status)

Defined in

src/webos-tv.ts:577


toggleMute

▸ toggleMute(): Promise<boolean>

Toggles the mute state of the webOS TV.

Returns

Promise<boolean>

A promise that resolves to the new mute state of the webOS TV (always the opposite of the previous state)

Defined in

src/webos-tv.ts:394


turnOff

▸ turnOff(): Promise<void>

Turns off the webOS TV.

Returns

Promise<void>

A promise

Defined in

src/webos-tv.ts:186


unmute

▸ unmute(): Promise<boolean>

Unmutes the webOS TV.

Returns

Promise<boolean>

A promise that resolves to the new mute state of the webOS TV (always false)

Defined in

src/webos-tv.ts:386


volumeDown

▸ volumeDown(): Promise<GetVolumeTVResponse>

Sends a volume down signal to the webOS TV.

Returns

Promise<GetVolumeTVResponse>

A promise that resolves to the new volume of the webOS TV

Defined in

src/webos-tv.ts:341


volumeUp

▸ volumeUp(): Promise<GetVolumeTVResponse>

Sends a volume up signal to the webOS TV.

Returns

Promise<GetVolumeTVResponse>

A promise that resolves to the new volume of the webOS TV

Defined in

src/webos-tv.ts:332


writeText

▸ writeText(text, replace?): Promise<void>

Writes the given text on the webOS TV.

Parameters

Name Type Default value Description
text string undefined The text to write on the webOS TV
replace boolean false Whether to replace the text or to append to it. Defaults to false

Returns

Promise<void>

A promise that resolves when the request is fulfilled

Defined in

src/webos-tv.ts:667


getTVURL

▸ Static getTVURL(hostname): URL

Returns a properly formatted TV URL for the given hostname.

Parameters

Name Type Description
hostname string The hostname to get the TV URL from

Returns

URL

The URL object corresponding to the TV hostname

Defined in

src/webos-tv.ts:30


turnOn

▸ Static turnOn(hostname, mac, password?): Promise<Buffer>

Turns on the specified webOS TV.

Parameters

Name Type Description
hostname string The hostname of the webOS TV to wake. It can also be a broadcast address
mac string The MAC address of the webOS TV to wake
password? string The SecureOn password of the device to wake

Returns

Promise<Buffer>

A promise that resolves with the magic packet sent to the webOS TV

Defined in

src/webos-tv.ts:48