-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetVolume.js
68 lines (54 loc) · 2.03 KB
/
getVolume.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
console.log('https://github.com/hobbyquaker/lgtv2');
console.log('https://github.com/ecgouvea/awesome-smart-tv');
//-----------------------------------------------------------------------------
// Declarations
//-----------------------------------------------------------------------------
var express = require('express');
var lgtv = require("lgtv2")({
url: 'ws://192.168.0.226:3000'
});
//-----------------------------------------------------------------------------
// LG TV
//-----------------------------------------------------------------------------
lgtv.on('error', function (err) {
console.log(err);
});
lgtv.on('connect', function () {
console.log('connected');
lgtv.subscribe('ssap://audio/getVolume', function (err, res) {
if (res.changed.indexOf('volume') !== -1) console.log('volume changed', res.volume);
if (res.changed.indexOf('muted') !== -1) console.log('mute changed', res.muted);
displayMessage('Dudu, o volume passou para nível ' + res.volume);
});
displayMessage('Hello, Dudu!');
console.log('message send');
});
function displayMessage(msg) {
lgtv.request('ssap://system.notifications/createToast', {message: msg});
}
//-----------------------------------------------------------------------------
// Express
//-----------------------------------------------------------------------------
const app = express();
const PORT = 5000;
app.get('/',(req,res)=>{
res.send({message: 'Welcome to the backend'})
})
app.get('/volumeUp',(req,res)=>{
lgtv.request('ssap://audio/volumeUp', (arg1) => {
console.log('this: ' + arg1);
});
res.send({message: 'volumeUp'})
})
app.get('/volumeDown',(req,res)=>{
lgtv.request('ssap://audio/volumeDown', (arg1) => {
console.log('this: ' + arg1);
});
res.send({message: 'volumeDown'})
})
app.get('/send', (req,res)=>{
displayMessage(req.query.msg);
res.send(req.query.msg);
})
app.listen(PORT, () => console.log(`Example app listening at http://localhost:${PORT}`));
console.log('end');