forked from OpenXbox/xbox-smartglass-core-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.js
executable file
·43 lines (36 loc) · 1.47 KB
/
connect.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
#!/usr/bin/env node
var Smartglass = require('../src/smartglass');
var deviceStatus = {
current_app: false,
connection_status: false,
client: false
}
deviceStatus.client = Smartglass()
deviceStatus.client.connect('192.168.2.5').then(function(){
console.log('Xbox succesfully connected!');
deviceStatus.connection_status = true
}, function(error){
console.log('Failed to connect to xbox:', error);
});
deviceStatus.client.on('_on_console_status', function(message, xbox, remote, smartglass){
if(message.packet_decoded.protected_payload.apps[0] != undefined){
if(deviceStatus.current_app != message.packet_decoded.protected_payload.apps[0].aum_id){
deviceStatus.current_app = message.packet_decoded.protected_payload.apps[0].aum_id
console.log('xbox: Current active app:', deviceStatus)
}
}
}.bind(deviceStatus));
deviceStatus.client.on('_on_timeout', function(message, xbox, remote, smartglass){
deviceStatus.connection_status = false
console.log('Connection timed out.')
clearInterval(interval)
deviceStatus.client = Smartglass()
deviceStatus.client.connect('192.168.2.5').then(function(){
console.log('Xbox succesfully connected!');
}, function(error){
console.log('Failed to connect to xbox:', result);
});
}.bind(deviceStatus, interval));
var interval = setInterval(function(){
console.log('connection_status:', deviceStatus.client._connection_status)
}.bind(deviceStatus), 5000)