msloth / lgtv.js Goto Github PK
View Code? Open in Web Editor NEWControl LG WebOS TV using node.js
License: MIT License
Control LG WebOS TV using node.js
License: MIT License
instead of using a hostname (eg lgsmarttv.lan), autodetect the TV IP-address through SSDP.
When solved, this makes #1 unnecessary.
I'm trying to use your package to automatically start the browser on a webpage but I can't get it to show it in fullscreen, do you know if there's a command I could run for that?
Thanks!
router.get('/:volume', function (req, res) {
var volume = Number(req.params.volume);
what would be the http adress:
my local host is : 192.168.0.163
so:
http://192.168.0.163:5555/volume=8
doesn to work
also http adresse for mute ?
Thanks :)
Marc.
if I run this I got this error
lgtv = require("lgtv");
var retry_timeout = 10; // seconds
lgtv.discover_ip(retry_timeout, function(err, ipaddr) {
if (err) {
console.log("Failed to find TV IP address on the LAN. Verify that TV is on, and that you are on the same LAN/Wifi.");
} else {
console.log("TV ip addr is: " + ipaddr);
}
});
error
dgram.js:88
throw new Error('Bad socket type specified. Valid types are: udp4, udp6');
^
Error: Bad socket type specified. Valid types are: udp4, udp6
at newHandle (dgram.js:88:9)
at new Socket (dgram.js:113:16)
at Object.exports.createSocket (dgram.js:130:10)
at Object.discover_ip (/Users/berkaey/Desktop/remote/node_modules/lgtv/index.js:208:22)
at Object.<anonymous> (/Users/berkaey/Desktop/remote/test.js:4:6)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
When you send a "ssap://com.webos.applicationManager/listApps" request to TV, it gives you an array of all apps which contains URLs of icons too. But what is very interesting to me is that none of these links work! They are all dead links.
I tried to sniff into my phone's LG TV Plus traffic to see how it gets app icons from TV, but no luck!
Can someone help me with this?
Thanks.
Edit: Sorry, the solution was to use "listLaunchPoints" instead of "listApps".
please add release for changes so we can just use "npm update"
There's too much output on the terminal, the information is in most cases useless unless debugging.
Use eg log4js to set output levels (info, debug, error, etc).
Line 236 in 4b64807
-1
is true
. So any device passes this condition.
This code works for me:
if (message.includes("Server: WebOS")) {
...
}
This isn't a question โ I thought I'd put the info here since I looked for it here myself.
It seems you can't turn on the TV using these commands, presumably because it doesn't listen for commands when it's turned off.
What you instead can do is configure the TV to "wake on LAN" (wake when a certain network packet is sent to it), and then have a script send that packet.
You need to enable it on the TV: Under "general" settings, turn on "Mobile TV On".
As for the script, look for a "wake on LAN" script in your language of choice. I patched together this Ruby script, for example: https://gist.github.com/henrik/2824551d69e8e7f35ae61bd35ca08456
I'm willing to help implement the mouse, but I can't find any API docs,
The app seems to be able to do it but I don't see any function in this code. Does a Wake-on-lan do it?
Hi,
I've just come across your repo and would like to use this for a home project but I was just wondering how did you find all the SSAP endpoints? I was wondering if there anymore endpoints that can be used which are not listed, e.g. I would like to get the profile name of the WiFi that the TV is connected to. I found on the LG docs this can be in Luna but was wondering how this would work with ws://
Thanks,
as you wrote here:
"Update, with the latest firmware as of today, the 1.4.0-2507(afro-ashley), the nmap looks like below. Also, I don't see it advertising itself over SSDP like before, nor answer to the ssdp query as it did before."
that's because in index.js
you have in the ssdp discovery this:
urn:dial-multiscreen-org:service:dial:1
it should be:
urn:lge-com:service:webos-second-screen:1
you can also send messages with a custom icon with a base64 encoded string of an image
{"id":"message","type":"request","uri":"ssap://system.notifications/createToast","payload":{"message": "%@", "iconData": "%@", "iconExtension": "png"}}
In many/most/some/a few at least of the functions, a callback is expected. The code looks like this: if (typeof fn === 'function') {
which makes it break if no callback is defined. Now one is forced to use empty callbacks which clutters up etc.
Replace the instances of the above code with if (fn && typeof(fn) === 'function') {
to allow invoking functions without defining callbacks.
Second, you should enable the TV to broadcast itself as lgsmarttv.lan in the local network. This setting is, IIRC, under Network/LG Connect Apps. This is necessary in order for this module to find the TV on the network.
Any thoughts on allowing users to pass in the hostname of the tv on init?
lgtv.connect('living-room', function(err, response){
if (!err) {
lgtv.show_float("It works!", function(err, response){
if (!err) {
lgtv.disconnect();
}
}); // show float
}
}); // connect
whats going on to set picture mode . , eco mode , possible to set screensaver disable and pointer off ?
like in the title, how can I manage to do that ? is there a function for this or I need to calculate from channel list?
Hey me again :)
I found three issue on this.
first, app names returns with "_default" at the end so before open one we need to remove "_default" from name.
second, some inputs could be listed as apps like "HDMI 1" but their ids is integer like "81273" and these won't open.
and last I got this but events works like I can open live tv or spotify but still get this.
Uncaught Exception:
TypeError: fn is not a function
at /Users/berkaey/Desktop/remote-app/node_modules/lgtv/index.js:698:9
at EventEmitter.<anonymous> (/Users/berkaey/Desktop/remote-app/node_modules/lgtv/index.js:269:9)
at EventEmitter.g (events.js:260:16)
at emitOne (events.js:77:13)
at EventEmitter.emit (events.js:169:7)
at WebSocketConnection.<anonymous> (/Users/berkaey/Desktop/remote-app/node_modules/lgtv/index.js:106:26)
at emitOne (events.js:77:13)
at WebSocketConnection.emit (events.js:169:7)
at WebSocketConnection.processFrame (/Users/berkaey/Desktop/remote-app/node_modules/lgtv/node_modules/websocket/lib/WebSocketConnection.js:547:26)
at /Users/berkaey/Desktop/remote-app/node_modules/lgtv/node_modules/websocket/lib/WebSocketConnection.js:321:40
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)
I get an error:
Connect Error: Error: getaddrinfo ENOTFOUND lgsmarttv.lan lgsmarttv.lan:3000
Does it matter if the TV is connected through lan or wifi? because my tv is connected trough wifi to my local network
Hello Marcus,
I published a rewrite of your lib here: https://github.com/hobbyquaker/lgtv2
I removed discovery and command wrappers and made a basic lib that just encapsulates the websocket connection handling, the pairing process and the callback handling. Further Improvements are:
My Intention for doing this rewrite was lgtv2mqtt, a tool I'm using in my MQTT based home automation and that depends on lgtv2.
If you like the changes I made I would suggest to rebuild your lib including your command wrappers that depends on lgtv2 and another lib that handles lg webos auto-discovery, so everything is modular.
Would be glad to hear your opinion on that,
all the best,
Sebastian
you mentioned other 'PR's? are these public repos? I cannot seem to find them.
hey with new version now I got this
/Users/berkaey/Desktop/remote/node_modules/lgtv/index.js:236
if (message.indexOf("LG Smart TV")) {
^
TypeError: Object HTTP/1.1 200 OK
Location: http://192.168.1.38:1221/
Cache-Control: max-age=1800
Server: WebOS/1.5 UPnP/1.0
EXT:
USN: uuid:495280ac-09a0-1dd8-518b-2927978aae03::urn:dial-multiscreen-org:service:dial:1
ST: urn:dial-multiscreen-org:service:dial:1
Date: Wed, 04 Nov 2015 08:39:23 GMT
has no method 'indexOf'
at Socket.<anonymous> (/Users/berkaey/Desktop/remote/node_modules/lgtv/index.js:236:17)
at Socket.emit (events.js:98:17)
at UDP.onMessage (dgram.js:441:8)
btw I have node 0.10.36 as global
See here: https://github.com/WeeJeWel/node-webos
Just can't get a direct YouTube video to play - any advice?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.