mirror of https://bitbucket.org/ausocean/av.git
Merged in m3u-minor-2 (pull request #353)
mjpeg-player: minor changes to xhr-loader and frag-loader Approved-by: Scott Barnard
This commit is contained in:
commit
defa938fd9
|
@ -1,11 +1,32 @@
|
||||||
|
/*
|
||||||
|
AUTHOR
|
||||||
|
Trek Hopton <trek@ausocean.org>
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
This file is Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
||||||
|
|
||||||
|
It is free software: you can redistribute it and/or modify them
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
It is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License in gpl.txt.
|
||||||
|
If not, see http://www.gnu.org/licenses.
|
||||||
|
|
||||||
|
For hls.js Copyright notice and license, see LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fragment Loader
|
* Fragment Loader
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Event from '../events';
|
import Event from '../events.js';
|
||||||
import EventHandler from '../event-handler';
|
import EventHandler from '../event-handler.js';
|
||||||
import { ErrorTypes, ErrorDetails } from '../errors';
|
|
||||||
import { logger } from '../utils/logger';
|
|
||||||
|
|
||||||
class FragmentLoader extends EventHandler {
|
class FragmentLoader extends EventHandler {
|
||||||
constructor(hls) {
|
constructor(hls) {
|
||||||
|
@ -39,7 +60,7 @@ class FragmentLoader extends EventHandler {
|
||||||
|
|
||||||
let loader = loaders[type];
|
let loader = loaders[type];
|
||||||
if (loader) {
|
if (loader) {
|
||||||
logger.warn(`abort previous fragment loader for type: ${type}`);
|
console.warn(`abort previous fragment loader for type: ${type}`);
|
||||||
loader.abort();
|
loader.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,29 @@
|
||||||
/**
|
/*
|
||||||
* XHR based logger
|
AUTHOR
|
||||||
|
Trek Hopton <trek@ausocean.org>
|
||||||
|
|
||||||
|
LICENSE
|
||||||
|
This file is Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
||||||
|
|
||||||
|
It is free software: you can redistribute it and/or modify them
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation, either version 3 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
It is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License in gpl.txt.
|
||||||
|
If not, see http://www.gnu.org/licenses.
|
||||||
|
|
||||||
|
For hls.js Copyright notice and license, see LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { logger } from '../utils/logger';
|
/**
|
||||||
|
* XHR based loader
|
||||||
|
*/
|
||||||
|
|
||||||
const { performance, XMLHttpRequest } = window;
|
const { performance, XMLHttpRequest } = window;
|
||||||
|
|
||||||
|
@ -43,6 +64,7 @@ class XhrLoader {
|
||||||
loadInternal() {
|
loadInternal() {
|
||||||
let xhr, context = this.context;
|
let xhr, context = this.context;
|
||||||
xhr = this.loader = new XMLHttpRequest();
|
xhr = this.loader = new XMLHttpRequest();
|
||||||
|
window.console.log("load internal xhr: " + context.url);
|
||||||
|
|
||||||
let stats = this.stats;
|
let stats = this.stats;
|
||||||
stats.tfirst = 0;
|
stats.tfirst = 0;
|
||||||
|
@ -121,11 +143,11 @@ class XhrLoader {
|
||||||
} else {
|
} else {
|
||||||
// if max nb of retries reached or if http status between 400 and 499 (such error cannot be recovered, retrying is useless), return error
|
// if max nb of retries reached or if http status between 400 and 499 (such error cannot be recovered, retrying is useless), return error
|
||||||
if (stats.retry >= config.maxRetry || (status >= 400 && status < 499)) {
|
if (stats.retry >= config.maxRetry || (status >= 400 && status < 499)) {
|
||||||
logger.error(`${status} while loading ${context.url}`);
|
console.error(`${status} while loading ${context.url}`);
|
||||||
this.callbacks.onError({ code: status, text: xhr.statusText }, context, xhr);
|
this.callbacks.onError({ code: status, text: xhr.statusText }, context, xhr);
|
||||||
} else {
|
} else {
|
||||||
// retry
|
// retry
|
||||||
logger.warn(`${status} while loading ${context.url}, retrying in ${this.retryDelay}...`);
|
console.warn(`${status} while loading ${context.url}, retrying in ${this.retryDelay}...`);
|
||||||
// aborts and resets internal state
|
// aborts and resets internal state
|
||||||
this.destroy();
|
this.destroy();
|
||||||
// schedule retry
|
// schedule retry
|
||||||
|
@ -143,7 +165,7 @@ class XhrLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadtimeout() {
|
loadtimeout() {
|
||||||
logger.warn(`timeout while loading ${this.context.url}`);
|
console.warn(`timeout while loading ${this.context.url}`);
|
||||||
this.callbacks.onTimeout(this.stats, this.context, null);
|
this.callbacks.onTimeout(this.stats, this.context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue