-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
index.js
75 lines (64 loc) · 1.75 KB
/
index.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
69
70
71
72
73
74
75
const { Samsung, APPS, KEYS } = require('../lib/index')
/*
Typescript Example for Dinamic Keys
import { $enum } from 'ts-enum-util'
*/
const config = {
debug: true, // Default: false
ip: '192.168.1.2',
mac: '123456789ABC',
nameApp: 'NodeJS-Test', // Default: NodeJS
port: 8002, // Default: 8002
token: '12345678',
}
const control = new Samsung(config)
control.turnOn()
control
.isAvailable()
.then(() => {
// Get token for API
control.getToken((token) => {
console.info('# Response getToken:', token)
})
/*
Typescript Example for Dinamic Keys
const KeyTypes = $enum(KEYS).getValues()
const getEnumValue = (key: any) => {
return KeyTypes[key]
}
*/
// Send key to TV
control.sendKey(KEYS.KEY_HOME, function (err, res) {
if (!err) {
console.log('# Response sendKey', res)
}
})
// Send text to focused input on TV
control.sendText('Text to be inserted in some focused input', function (err, res) {
if (!err) {
console.log('# Response sendText', res)
}
})
// Get all installed apps from TV
control.getAppsFromTV((err, res) => {
if (!err) {
console.log('# Response getAppsFromTV', res)
}
})
// Get app icon by iconPath which you can get from getAppsFromTV
control.getAppIcon(
`/opt/share/webappservice/apps_icon/FirstScreen/${APPS.YouTube}/250x250.png`,
(err, res) => {
if (!err) {
console.log('# Response getAppIcon', res)
}
},
)
// Open app by appId which you can get from getAppsFromTV
control.openApp(APPS.YouTube, (err, res) => {
if (!err) {
console.log('# Response openApp', res)
}
})
})
.catch((e) => console.error(e))