-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconnect_channels.js
executable file
·150 lines (131 loc) · 5.44 KB
/
connect_channels.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
142
143
144
145
146
147
148
149
150
#!/usr/bin/env node
var Smartglass = require('../src/smartglass');
var SystemInputChannel = require('../src/channels/systeminput');
var SystemMediaChannel = require('../src/channels/systemmedia');
var TvRemoteChannel = require('../src/channels/tvremote');
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.client.addManager('system_input', SystemInputChannel())
deviceStatus.client.addManager('system_media', SystemMediaChannel())
deviceStatus.client.addManager('tv_remote', TvRemoteChannel())
//
// Volume tests
//
setTimeout(function(){
deviceStatus.client.getManager('tv_remote').getConfiguration().then(function(configuration){
console.log('Configuration:', configuration)
}, function(error){
console.log('Failed to get configuration:', error)
});
setTimeout(function(){
deviceStatus.client.getManager('tv_remote').sendIrCommand('btn.vol_up').then(function(response){
console.log('send button:', response)
}, function(error){
console.log(error)
});
}.bind(deviceStatus), 1500)
setTimeout(function(){
deviceStatus.client.getManager('tv_remote').sendIrCommand('btn.vol_down').then(function(response){
console.log('send button:', response)
}, function(error){
console.log(error)
});
}.bind(deviceStatus), 2500)
}.bind(deviceStatus), 1000)
//
// Input tests
//
setTimeout(function(){
// deviceStatus.client.getManager('tv_remote').getConfiguration().then(function(configuration){
// console.log('Configuration:', configuration)
// }, function(error){
// console.log('Failed to get configuration:', error)
// });
setTimeout(function(){
deviceStatus.client.getManager('system_input').sendCommand('nexus').then(function(){
// Send button
}, function(error){
console.log(error)
});
}.bind(deviceStatus), 1000)
setTimeout(function(){
deviceStatus.client.getManager('system_input').sendCommand('nexus').then(function(){
// Send button
}, function(error){
console.log(error)
});
}.bind(deviceStatus), 2000)
}.bind(deviceStatus), 1000)
// deviceStatus.client.on('_on_console_status', function(message, xbox, remote){
// // console.log('CONSOLE STATE', message.packet_decoded.protected_payload)
// // console.log(message.packet_decoded.protected_payload)
// console.log(deviceStatus.client.getActiveApp())
// //deviceStatus.client.getManager('system_input').sendCommand('nexus');
// });
// setTimeout(function(){
// console.log('Send nexus button')
// deviceStatus.client.getManager('system_input').sendCommand('nexus');
//
// setTimeout(function(){
// deviceStatus.client.getManager('system_input').sendCommand('down');
// }.bind(deviceStatus), 1000)
//
// setTimeout(function(){
// deviceStatus.client.getManager('tv_remote').sendIrCommand('btn.vol_up');
// }.bind(deviceStatus), 1500)
//
// setTimeout(function(){
// deviceStatus.client.getManager('system_input').sendCommand('up');
// }.bind(deviceStatus), 2000)
//
// setTimeout(function(){
// deviceStatus.client.getManager('system_input').sendCommand('left');
// }.bind(deviceStatus), 3000)
//
// setTimeout(function(){
// deviceStatus.client.getManager('tv_remote').sendIrCommand('btn.vol_down');
// }.bind(deviceStatus), 3500)
//
// setTimeout(function(){
// deviceStatus.client.getManager('system_input').sendCommand('right');
// }.bind(deviceStatus), 4000)
//
// setTimeout(function(){
// deviceStatus.client.getManager('system_media').sendCommand('pause');
// }.bind(deviceStatus), 500)
//
// setTimeout(function(){
// deviceStatus.client.getManager('system_input').sendCommand('nexus');
//
// console.log(deviceStatus.client.getActiveApp())
// console.log(deviceStatus.client.getManager('system_media').getState())
// }.bind(deviceStatus), 5000)
//
// setTimeout(function(){
// deviceStatus.client.getManager('system_media').sendCommand('play');
// }.bind(deviceStatus), 2500)
//
// }.bind(deviceStatus), 5000)
}.bind(deviceStatus), function(error){
console.log('Failed to connect to xbox:', error);
});
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:', error);
});
}.bind(deviceStatus, interval));
var interval = setInterval(function(){
console.log('connection_status:', deviceStatus.client._connection_status)
}.bind(deviceStatus), 5000)