-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
141 lines (120 loc) · 3.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const ws = require('ws');
const fetch = require('node-fetch');
const ipAddress = process.argv[2];
let socketBase, socketArt;
if (!ipAddress) {
return console.error("\n\n" + 'IP address is missing! Example of running the script "node index.js 192.168.1.100"');
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms || 3000));
}
function separator() {
console.log("\n\n---------------------\n\n");
return Promise.resolve();
}
function getInfo() {
console.log('getInfo - start');
return fetch(`http://${ipAddress}:8001/api/v2/`, {
timeout: 2000
})
.then(body => body.json())
.then(response => {
response.isSupport = JSON.parse(response.isSupport);
console.log('getInfo - response', response);
}).catch(error => {
console.log('getInfo - error', error);
});
};
function testBaseWs() {
console.log('testBaseWs - start');
return new Promise(resolve => {
socketBase = new ws(`wss://${ipAddress}:8002/api/v2/channels/samsung.remote.control?name=VGVzdCBTYW1zdW5nIEFQSQ==`, {
servername: '',
handshakeTimeout: 2000,
rejectUnauthorized: false
})
.on('error', error => {
console.log('testBaseWs - error', error, "\n");
resolve();
})
.on('message', response => {
response = JSON.parse(response);
resolve();
console.log('testBaseWs - message', response, "\n");
});
}).then(() => {
console.log('testBaseWs - send command');
return socketBase.send(JSON.stringify({
method : 'ms.remote.control',
params : {
Cmd : 'Click',
DataOfCmd : 'KEY_VOLUP',
Option : false,
TypeOfRemote : 'SendRemoteKey'
}
}), error => {
console.log('testBaseWs - send command - error', error);
});
})
.then(delay)
.finally(() => setTimeout(() => {
console.log('testBaseWs - terminate');
if (socketBase) {
socketBase.terminate();
}
}, 1000));
}
function testArtWs() {
console.log('testArtWs - start');
return new Promise(resolve => {
socketArt = new ws(`ws://${ipAddress}:8001/api/v2/channels/com.samsung.art-app?name=VGVzdCBTYW1zdW5nIEFQSQ==`, {
servername: '',
handshakeTimeout: 2000,
rejectUnauthorized: false
})
.on('error', error => {
console.log('testArtWs - error', error, "\n");
resolve();
})
.on('message', response => {
response = JSON.parse(response);
resolve();
console.log('testArtWs - message', response, "\n");
});
}).then(() => {
console.log('testArtWs - send getStatus');
return socketArt.send(JSON.stringify({
method : 'ms.channel.emit',
params : {
data : JSON.stringify({
id: 'noop-id',
request: 'get_artmode_status'
}),
to : 'host',
event : 'art_app_request'
}
}), error => {
console.log('testArtWs - send getStatus - error', error);
});
})
.then(delay)
.finally(() => setTimeout(() => {
console.log('testArtWs - terminate');
if (socketArt) {
socketArt.terminate();
}
}, 1000));
}
separator()
.then(getInfo)
.then(separator)
.then(delay)
.then(testBaseWs)
.then(delay)
.then(separator)
.then(testArtWs)
.then(delay)
.then(separator)
.then(() => {
console.log("Please copy everything and share it on your Issue :)");
});