-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·410 lines (362 loc) · 15.1 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content='maximum-scale=1.0, initial-scale=1.0, width=device-width' name='viewport'>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>multiREMOTE</title>
<!-- Bootstrap core CSS -->
<link href="dependencies/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="index.css" rel="stylesheet">
</head>
<body>
<div id="background"></div>
<div id="blockui"></div>
<!-- Fixed navbar -->
<nav id="zonebar" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<a class="navbar-brand" href="#">multiREMOTE</a>
<ul class="nav navbar-nav" id="zone-list">
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span id="time" class="navbar-brand"></span></li>
<li><a href="#"><span class="glyphicon glyphicon-cog"></span></a></li>
</ul>
</div>
</nav>
<div class="container" id="canvas">
</div> <!-- /container -->
<!-- Working indicator -->
<div style="width: 50%; height: 58px; overflow: hidden; padding: 2px; margin: auto; background: #ffffff; border: 2px outset" class="modal" id="busyIndicator" data-backdrop="static" data-keyboard="false">
<div class="modal-body">
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="font-size: 18px; width:100%">...Please wait...</div>
</div>
</div>
</div>
<div style="width: 50%; height: 80%; overflow: hidden; padding: 2px; margin: auto; background: #ffffff; border: 2px outset" class="modal" id="conflictResolution" data-backdrop="static" data-keyboard="false">
<div class="modal-body">
<span id="resolve-question">X conflicts with Y, how would you like to resolve this?</span>
<hr>
Resolve by...
<button id="resolve-cancel" type="button" style="margin-top: 10px; width: 100%" class="btn btn-default btn-lg">Cancel selection</button>
<button id="resolve-clone" type="button" style="margin-top: 10px; width: 100%" class="btn btn-primary btn-lg">Play on both</button>
<button id="resolve-unassign" type="button" style="margin-top: 10px; width: 100%" class="btn btn-warning btn-lg">Transfer here</button>
</div>
</div>
<div style="width: 50%; overflow-x: hidden; overflow-y: auto; max-height: 80%; padding: 2px; margin: auto; background: #ffffff; border: 2px outset" class="modal" id="configDialog" data-backdrop="static" data-keyboard="false">
<div class="modal-body">
Please configure this remote
<hr>
<div class="input-group" style="width: 100%">
<label for="config-name">Name</label>
<input id="config-name" type="text" class="form-control" placeholder="Short and nice" aria-describedby="basic-addon1">
</div>
<div class="input-group" style="width: 100%">
<label for="config-desc">Description</label>
<input id="config-desc" type="text" class="form-control" placeholder="For example: location, device, owner" aria-describedby="basic-addon1">
</div>
<div class="input-group" style="width: 100%">
<label for="config-zone">Default location</label>
<select id="config-zone" class="form-control" aria-describedby="basic-addon1"></select>
</div>
<div class="input-group" style="width: 100%">
<label for="config-pin">System PIN</label>
<input id="config-pin" type="password" class="form-control" placeholder="Provided by the installer" aria-describedby="basic-addon1">
</div>
<button id="config-add" type="button" style="margin-top: 10px; width: 100%" class="btn btn-primary btn-lg">Add remote</button>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="dependencies/jquery2.min.js"></script>
<script src="dependencies/bootstrap/js/bootstrap.min.js"></script>
<script src="dependencies/json2.js"></script>
<script src="dependencies/jstorage.js"></script>
<script src="multiremoteclient.js"></script>
<script src="multiremote_eventservice.js"></script>
<script src="multiremotetypes.js"></script>
<script src="buttonrepeater.js"></script> <!-- Repeater messes up WebView UI ? -->
<script src="resultwrapper.js"></script>
<script src="ux-objects.js"></script>
<script type="text/javascript">
var zoneVolume = 0;
var ux = new UXObjects();
var result = new ResultWrapper(ux, 500);
var app = new MultiRemoteClient(function(a,b,c){result.handler(a,b,c);});
// Forwarding function for the client
function onApplicationEvent(evt, data) {
app.onApplicationEvent(evt, data);
}
app.setSceneListener(function(data) {
if (data.scene == null)
showScenes();
else
showCommands();
});
app.setZoneListener(function(data) {
setZoneInUse(data.zone, data.inuse);
});
app.setVolumeListener(function(data) {
zoneVolume = data;
refreshVolume(data)
});
ux.optimize();
function refreshVolume() {
$("#volcur").text( (zoneVolume / 100.0).toFixed(1) + "%");
obj = document.querySelector('button#volset');
if (obj)
obj.style.setProperty('--volume-indicator', (zoneVolume / 100.0).toFixed(0) + "%");
else
console.log("No volume set button found");
}
function setZoneInUse(zone, inuse) {
console.log("Zone " + zone + " is now " + inuse);
ux.inuseZone(zone, inuse);
}
function sceneHandler(command, done) {
ux.vibrate(ux.VIBRATE_BTN);
result.wrap(function(){return app.issueCommand("scene", command);}, function(success, data) {
if (done != undefined)
done();
}, true);
}
function zoneHandler(command, done) {
ux.vibrate(ux.VIBRATE_BTN);
var blockUI = true;
// Blocking some of these is bad since repeat won't function properly (button loses focus)
if (done != undefined)
{
blockUI = false;
}
result.wrap(function(){return app.issueCommand("zone", command);}, function(success, data) {
if (done != undefined)
done();
outofbandHandler(data);
}, blockUI);
}
function outofbandHandler(data) {
return;
}
function appHandler(packagename) {
console.log("Launching: " + packagename);
ux.vibrate(ux.VIBRATE_BTN);
ux.launchPackage(packagename);
}
function conflictHandler(scene, choice) {
// In most cases, you can just send the choice back...
ux.vibrate(ux.VIBRATE_BTN);
if (choice == "clone") {
selectScene(scene, "clone");
} else if (choice == "unassign") {
selectScene(scene, "unassign");
} else {
}
}
function configHandler(pin, name, desc, zone) {
ux.vibrate(ux.VIBRATE_BTN);
result.wrap(function() {return app.registerRemote(pin, name, desc, zone);}, function(success, data) {
if (!success) {
ux.showConfiguration(app.getZones(), configHandler, true);
} else {
// Woohoo! Load default zone
selectZone(app.getDefaultZone());
}
});
}
function selectScene(scene, override) {
// Override is never set when called directly
if (undefined == override)
ux.vibrate(ux.VIBRATE_BTN);
result.wrap(function(){return app.selectScene(scene, override);}, function(success, data) {
// Alright! Now we need represent this somehow... this is what we've all been waiting for!
if (success) {
if (scene != null) {
showCommands();
} else {
showScenes();
}
} else {
// Something went wrong...
if (data.hasOwnProperty("conflict")) {
// It's a conflict, show some reasonable error...
var want = app.getScene(scene).name;
var question = "Choosing " + want + " could conflict with ";
var count = data.conflict.length;
for(var z in data.conflict) {
question += app.getZone(data.conflict[z]).name
if (count == 2) {
question += " and ";
} else if (count > 2) {
question += ", ";
}
count--;
}
ux.showConflict(scene, question, data.conflict.length, conflictHandler);
}
}
}, true);
}
function gotoStandby() {
selectScene(null);
}
function showCommands() {
result.wrap(function(){return app.getCommands();}, function(success, data) {
ux.inuseZone(app.getCachedZone(), true);
// Lets see what we got
ux.clearCanvas();
ux.renderSceneInfo(app.getScene(app.getCachedScene()), gotoStandby, function() {ux.vibrate(ux.VIBRATE_BTN); showScenes();});
ux.createVolumeControls(data.zone, volumeHandler);
ux.showMessage(app.getScene(app.getCachedScene()), appHandler);
ux.createPlaybackControls(data.scene, sceneHandler);
ux.createNavigationControls(data.scene, sceneHandler);
ux.createStreamControls(data.scene, sceneHandler);
ux.createApplicationLink(app.getScene(app.getCachedScene()), appHandler);
ux.renderSceneIcon(app.getScene(app.getCachedScene()));
app.updateZoneState(app.getCachedZone());
}, true);
}
function selectSubzone(subzone) {
ux.vibrate(ux.VIBRATE_BTN);
console.log("subzone: " + subzone);
result.wrap(function(){return app.selectSubZone(subzone);}, function(success, data) {
result.wrap(function(){return app.getActiveScene();}, function(success, data) {
if (data == null) {
showScenes();
} else {
showCommands();
}
}, true);
}, true);
}
var volumeSliding = null;
function setVolume(newvolume) {
result.wrap(
function() {
return app.issueCommand("zone", "volume-set/" + newvolume);
},
function(success, data) {
outofbandHandler(data);
},
false
);
}
// TODO: CLEAN THIS MESS UP!
function volumeHandler(command, action, data) {
var x = data['x'];
var y = data['y'];
var ts = data['ts'];
var source = data['source'];
if (volumeSliding && action == "end") {
if (volumeSliding['lastvolume'] == zoneVolume) {
if (!volumeSliding['movement']) {
// User most likely tapped, since we didn't see movement (yes, this is not 100% accurate)
ux.vibrate(ux.VIBRATE_BTN);
var r = source.getBoundingClientRect();
var middle = (r.bottom - r.top)/2;
result.wrap(
function() {
return app.issueCommand("zone", volumeSliding['initial-y'] > middle ? "volume-down" : "volume-up");
},
function(success, data) {
outofbandHandler(data);
},
false
);
}
} else {
// We must now issue the change to the backend since user isn't moving anymore
setVolume(zoneVolume);
}
volumeSliding = null
} else if (action == "start") {
volumeSliding = {'lastvolume' : volume, 'movement':false, 'initial-y':y};
} else if (volumeSliding != null) {
if (!volumeSliding.hasOwnProperty('y')) {
volumeSliding['y'] = y;
volumeSliding['py'] = y;
volumeSliding['ts'] = ts;
volumeSliding['processing'] = false;
return;
}
volumeSliding['movement'] = true;
var dY = Math.abs(volumeSliding['py'] - y);
volumeSliding['py'] = y;
var dTS = Math.abs(volumeSliding['ts'] - ts);
if ( dY > 1 ) {
var dY = volumeSliding['y'] - y;
volumeSliding["y"] = y;
var change = Math.floor(dY);
if (change) {
// Record the change and show a representation
zoneVolume = Math.min(10000, Math.max(0, zoneVolume + change*10));
refreshVolume();
if (dTS > 50) {
volumeSliding["ts"] = ts;
ux.tick();
}
}
}
}
}
function showScenes() {
scenes = app.getScenesForZone(app.getCachedZone());
ux.clearCanvas();
var z = app.getCachedZone();
ux.inuseZone(z, false);
if (app.hasSubZones(z))
ux.createSceneSelector(scenes, app.getCachedScene(), selectScene, app.getSubZones(z), app.getActiveSubZone(), selectSubzone);
else
ux.createSceneSelector(scenes, app.getCachedScene(), selectScene);
}
function selectZone(zone, subzone) {
ux.vibrate(ux.VIBRATE_BTN);
result.wrap(function(){return app.selectZone(zone);}, function(success, data) {
// Find out which scene we're using for this zone
ux.highlightZone(zone);
ux.showGuestMode(zone != app.getDefaultZone());
result.wrap(function(){return app.getActiveScene();}, function(success, data) {
if (data == null) {
showScenes();
} else {
showCommands();
}
}, true);
}, true);
}
function updateClock() {
var t = new Date();
if (t.getHours() > 12)
$("#time").text((t.getHours() - 12) + ":" + (t.getMinutes() < 10 ? "0" : "") + t.getMinutes() + "pm");
else if (t.getHours() == 0)
$("#time").text("12:" + (t.getMinutes() < 10 ? "0" : "") + t.getMinutes() + "am");
else
$("#time").text(t.getHours() + ":" + (t.getMinutes() < 10 ? "0" : "") + t.getMinutes() + "am");
}
// Start clock function
setInterval(updateClock, 900);
// init the client and remove the modal once done
result.wrap(function(){return app.init();}, function() {
z = app.getZones();
for (var e in z) {
if (z.hasOwnProperty(e)) {
ux.addZone(z[e], e, selectZone);
if (app.isZoneInUse(e))
ux.inuseZone(e, true);
}
}
// Do we have a remote?
if (!app.isRegistered()) {
ux.showConfiguration(app.getZones(), configHandler, false);
} else {
selectZone(app.getDefaultZone());
}
}, true);
</script>
</body>
</html>