switch to let from var, switch to fetch from XHR
This commit is contained in:
parent
f4c54fc43c
commit
103d47b9d7
1 changed files with 9 additions and 15 deletions
|
@ -9,23 +9,17 @@ class PlaylistLoader {
|
||||||
this.fetch_playlist();
|
this.fetch_playlist();
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_playlist() {
|
async fetch_playlist() {
|
||||||
var xmlHttp = new XMLHttpRequest();
|
const response = await fetch(this.playlist_src);
|
||||||
xmlHttp.onreadystatechange = ( function() {
|
this.parse_playlist(await response.text());
|
||||||
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
|
||||||
this.parse_playlist(xmlHttp.responseText);
|
|
||||||
setTimeout(this.fetch_playlist.bind(this), this.refresh_interval * 1000);
|
setTimeout(this.fetch_playlist.bind(this), this.refresh_interval * 1000);
|
||||||
}
|
}
|
||||||
} ).bind(this)
|
|
||||||
xmlHttp.open("GET", this.playlist_src, true);
|
|
||||||
xmlHttp.send(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
parse_playlist(playlist_content) {
|
parse_playlist(playlist_content) {
|
||||||
var lines = playlist_content.split('\n');
|
let lines = playlist_content.split('\n');
|
||||||
var segments = [];
|
let segments = [];
|
||||||
var segment_block_flag = this.last_segment === null ? false : true;
|
let segment_block_flag = this.last_segment === null ? false : true;
|
||||||
for (var i = 0; i < lines.length; i++) {
|
for (let i = 0; i < lines.length; i++) {
|
||||||
if (lines[i].startsWith("#")) {
|
if (lines[i].startsWith("#")) {
|
||||||
if (lines[i].startsWith("EXT-X-TARGETDURATION", 1)) {
|
if (lines[i].startsWith("EXT-X-TARGETDURATION", 1)) {
|
||||||
this.refresh_interval = parseFloat(lines[i].split(':')[1]);
|
this.refresh_interval = parseFloat(lines[i].split(':')[1]);
|
||||||
|
@ -45,4 +39,4 @@ class PlaylistLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var test = new PlaylistLoader();
|
let test = new PlaylistLoader();
|
||||||
|
|
Loading…
Reference in a new issue