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
- appList
- appState
- authenticate
- channelDown
- channelUp
- check3DStatus
- closeApp
- closeMediaViewer
- decreaseVolume
- deleteText
- disable3D
- disconnect
- enable3D
- fastForward
- foregroundAppInfo
- getAudioStatus
- getChannelList
- getCurrentChannel
- getCurrentSWInformation
- getPointerInputSocket
- getRemoteKeyboardSocket
- getServiceList
- getSocket
- getVolume
- handleMessage
- increaseVolume
- is3DEnabled
- isMuted
- launchApp
- launchPoints
- loadIcon
- mute
- openChannel
- openChannelByName
- openChannelByNumber
- openURL
- pause
- play
- request
- rewind
- send
- sendEnter
- setMute
- setVolume
- showNotification
- stop
- subscribe
- toggle3D
- toggleMute
- turnOff
- unmute
- volumeDown
- volumeUp
- writeText
- getTVURL
- turnOn
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
Properties
callbacks
• Private
callbacks: Record
<string
, { reject
: (err
: Error
) => void
; resolve
: (val
: any
) => void
}> = {}
Defined in
config
• Private
config: Config
Defined in
connection
• Private
Readonly
connection: WebSocket
Defined in
connectionOpened
• Private
Readonly
connectionOpened: Promise
<Event
>
Defined in
currId
• Private
currId: number
= 0
Defined in
specializedSockets
• Private
specializedSockets: Record
<string
, SpecializedWebSocket
> = {}
Defined in
Accessors
nextId
• Private
get
nextId(): string
Returns
string
Defined in
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
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
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
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
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
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
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
closeMediaViewer
▸ closeMediaViewer(): Promise
<void
>
Closes the media viewer.
Returns
Promise
<void
>
A promise
Defined in
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
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
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
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
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
fastForward
▸ fastForward(): Promise
<void
>
Sends the fast forward command to the webOS TV.
Returns
Promise
<void
>
A promise
Defined in
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
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
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
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
getCurrentSWInformation
▸ getCurrentSWInformation(): Promise
<GetCurrentSWInformationTVResponse
>
Gets the current SW information
Returns
Promise
<GetCurrentSWInformationTVResponse
>
A promise that resolves to the current software information
Defined in
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
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
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
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
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
handleMessage
▸ Private
handleMessage(message
): void
Parameters
Name | Type |
---|---|
message |
Data |
Returns
void
Defined in
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
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
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
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
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
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
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
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
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
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
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
pause
▸ pause(): Promise
<void
>
Sends the pause command to the webOS TV.
Returns
Promise
<void
>
A promise
Defined in
play
▸ play(): Promise
<void
>
Sends the play command to the webOS TV.
Returns
Promise
<void
>
A promise
Defined in
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
rewind
▸ rewind(): Promise
<void
>
Sends the rewind command to the webOS TV.
Returns
Promise
<void
>
A promise
Defined in
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
sendEnter
▸ sendEnter(): Promise
<void
>
Sends an enter key to the webOS TV.
Returns
Promise
<void
>
A promise
Defined in
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
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
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
stop
▸ stop(): Promise
<void
>
Sends the stop command to the webOS TV.
Returns
Promise
<void
>
A promise
Defined in
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
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
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
turnOff
▸ turnOff(): Promise
<void
>
Turns off the webOS TV.
Returns
Promise
<void
>
A promise
Defined in
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
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
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
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
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
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