-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.js
101 lines (89 loc) · 2.89 KB
/
ui.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
configureLogging();
// Update all of the corresonding fields when switching protocol or playback mode
$('#protocol').change(function() {
updateFieldsCorrespondingToStreamingProtocol();
});
$('#playbackMode').change(function() {
updateFieldsCorrespondingToPlaybackMode();
});
// Read/Write all of the fields to/from localStorage so that fields are not lost on refresh.
[
'protocol',
'player',
'region',
'accessKeyId',
'secretAccessKey',
'sessionToken',
'endpoint',
'streamName',
'playbackMode',
'discontinuityMode',
'displayFragmentTimestamp',
'displayFragmentNumber',
'startTimestamp',
'endTimestamp',
'fragmentSelectorType',
'maxResults',
'expires'
].forEach(function(field) {
var id = "#" + field;
// Read field from localStorage
try {
var localStorageValue = localStorage.getItem(field);
if (localStorageValue) {
$(id).val(localStorageValue);
$(id).trigger('change');
}
} catch (e) { /* Don't use localStorage */ }
// Write field to localstorage on change event
$(id).change(function() {
try {
localStorage.setItem(field, $(id).val());
} catch (e) { /* Don't use localStorage */ }
});
});
// Initially hide the player elements
$('.player').hide();
function configureLogging() {
console._error = console.error;
console.error = function(messages) {
log('ERROR', Array.prototype.slice.call(arguments));
console._error.apply(this, arguments);
}
console._log = console.log;
console.log = function(messages) {
log('INFO', Array.prototype.slice.call(arguments));
console._log.apply(this, arguments);
}
function log(level, messages) {
var text = '';
for (message of messages) {
if (typeof message === 'object') { message = JSON.stringify(message, null, 2); }
text += ' ' + message;
}
$('#logs').append($('<div>').text('[' + level + ']' + text + '\n'));
}
}
function updateFieldsCorrespondingToStreamingProtocol() {
var isDASH = $('#protocol').val() === 'DASH';
$('#containerFormat').prop('disabled', isDASH);
$('#discontinuityMode').prop('disabled', isDASH);
$('#displayFragmentNumber').prop('disabled', !isDASH);
var players = isDASH ? DASH_PLAYERS : HLS_PLAYERS;
$('#player').empty();
players.forEach(function (player) {
var option = $('<option>').text(player);
$('#player').append(option);
});
$('#player').trigger('change');
}
updateFieldsCorrespondingToStreamingProtocol();
function updateFieldsCorrespondingToPlaybackMode() {
var isLive = $('#playbackMode').val() === 'LIVE';
$('#startTimestamp').prop('disabled', isLive);
$('#endTimestamp').prop('disabled', isLive);
}
updateFieldsCorrespondingToPlaybackMode();
$('.loader').hide();
$('.main').show();
console.log("Page loaded")