switch to let from var, switch to fetch from XHR

This commit is contained in:
Muaz Ahmad 2023-08-23 15:43:29 +05:00
parent f4c54fc43c
commit 103d47b9d7

View file

@ -9,23 +9,17 @@ class PlaylistLoader {
this.fetch_playlist();
}
fetch_playlist() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = ( function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
this.parse_playlist(xmlHttp.responseText);
async fetch_playlist() {
const response = await fetch(this.playlist_src);
this.parse_playlist(await response.text());
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) {
var lines = playlist_content.split('\n');
var segments = [];
var segment_block_flag = this.last_segment === null ? false : true;
for (var i = 0; i < lines.length; i++) {
let lines = playlist_content.split('\n');
let segments = [];
let segment_block_flag = this.last_segment === null ? false : true;
for (let i = 0; i < lines.length; i++) {
if (lines[i].startsWith("#")) {
if (lines[i].startsWith("EXT-X-TARGETDURATION", 1)) {
this.refresh_interval = parseFloat(lines[i].split(':')[1]);
@ -45,4 +39,4 @@ class PlaylistLoader {
}
}
var test = new PlaylistLoader();
let test = new PlaylistLoader();