-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
132 lines (123 loc) · 4.57 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Next remote</title>
</head>
<body>
<h1>Next remote</h1>
<br/>
<br/>
<div id="urls">
<a href="api/status">status</a>
<a href="api/uistatus">uistatus</a>
<a href="api/stations">stations</a>
<a href="api/currentchannel">currentchannel</a>
<a href="api/currentprogram">currentprogram</a>
<a href="api/session">session</a>
<a href="api/recordings">recordings</a>
</div>
<br/>
<p id="stbStatus"></p>
<p id="stbCurrentChannel"></p>
<button id="MediaTopMenu" onCLick="sendKey('MediaTopMenu')">MediaTopMenu</button>
<button id="ArrowUp" onCLick="sendKey('ArrowUp')">ArrowUp</button>
<button id="ArrowDown" onCLick="sendKey('ArrowDown')">ArrowDown</button>
<button id="ArrowLeft" onCLick="sendKey('ArrowLeft')">ArrowLeft</button>
<button id="ArrowRight" onCLick="sendKey('ArrowRight')">ArrowRight</button>
<button id="Enter" onCLick="sendKey('Enter')">Enter</button>
<button id="TV" onCLick="sendKey('TV')">TV</button>
<button id="Power" onCLick="sendKey('Power')">Power</button>
<button id="Escape" onCLick="sendKey('Escape')">Back/Escape</button>
<button id="Pause" onCLick="sendKey('MediaPause')">Pause</button>
<button id="Help" onCLick="sendKey('Help')">Help</button>
<button id="Info" onCLick="sendKey('Info')">Info</button>
<button id="Guide" onCLick="sendKey('Guide')">Guide</button>
<button id="ContextMenu" onCLick="sendKey('ContextMenu')">ContextMenu</button>
<button id="ChannelUp" onCLick="sendKey('ChannelUp')">ChannelUp</button>
<button id="ChannelDown" onCLick="sendKey('ChannelDown')">ChannelDown</button>
<button id="MediaRecord" onCLick="sendKey('MediaRecord')">MediaRecord</button>
<button id="MediaPlayPause" onCLick="sendKey('MediaPlayPause')">MediaPlayPause</button>
<button id="MediaStop" onCLick="sendKey('MediaStop')">MediaStop</button>
<button id="MediaRewind" onCLick="sendKey('MediaRewind')">MediaRewind</button>
<button id="MediaFastForward" onCLick="sendKey('MediaFastForward')">MediaFastForward</button>
<br/>
<br/>
<b>Click on channel button to switch to channel</b>
<br/>
<div id="stationsList" />
<script>
// Get channels
fetch('/api/stations')
.then(function(response) {
return response.json();
})
.then(function(stations) {
for (let s = 0; s < stations.length; s++) {
let stationBtn = document.createElement('button');
let streamImage = "";
let channelImage = "";
for (image in stations[s].images){
img = stations[s].images[image];
//console.log(img);
if (img["assetType"] == "imageStream"){
streamImage = img["url"]
}
if (img["assetType"] == "station-logo-large") {
channelImage = img["url"]
}
}
stationBtn.setAttribute('style', 'width: 100px; height: 100px; padding: 5px; background: url(' + channelImage + ') no-repeat; background-size: 100%;');
stationBtn.setAttribute("alt", stations[s].title);
stationBtn.setAttribute("title", stations[s].title);
stationBtn.id = stations[s].serviceId;
document.getElementById('stationsList').appendChild(stationBtn);
}
document.addEventListener('click', function(e) {
if(e.srcElement.nodeName == 'BUTTON' && e.srcElement.id.includes("_")){
setChannel(e.srcElement.id);
}
});
});
function setChannel(channel){
// Switch channel
fetch('/api', {
method: 'POST',
headers: {'Content-Type': 'application/json; charset=utf-8'},
body: JSON.stringify({
action: 'pushChannel',
channel: channel
}),
json: true
});
};
function sendKey(key){
// Pause key
fetch('/api', {
method: 'POST',
headers: {'Content-Type': 'application/json; charset=utf-8'},
body: JSON.stringify({
action: 'sendKey',
key: key
}),
json: true
});
};
function getStatus(){
fetch('/api/status')
.then(function(response) {
return response.json();
})
.then(function(status) {
if(status.setopboxState){
document.getElementById("stbStatus").innerHTML = 'Setopbox status: ' + status.setopboxState;
if(status.currentChannel){
document.getElementById("stbCurrentChannel").innerHTML = 'Current channel: ' + status.currentChannel;
}
}
});
};
setInterval(function(){ getStatus(); }, 1000);
</script>
</body>
</html>