mirror of https://bitbucket.org/ausocean/av.git
mjpeg-player: minor changes to xhr-loader and frag-loader
Changes include: using console for logger, import statements, formatting.
This commit is contained in:
parent
1b7e817266
commit
5647946bac
|
@ -1,19 +1,40 @@
|
|||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
import Event from '../events';
|
||||
import EventHandler from '../event-handler';
|
||||
import { ErrorTypes, ErrorDetails } from '../errors';
|
||||
import { logger } from '../utils/logger';
|
||||
import Event from '../events.js';
|
||||
import EventHandler from '../event-handler.js';
|
||||
|
||||
class FragmentLoader extends EventHandler {
|
||||
constructor (hls) {
|
||||
constructor(hls) {
|
||||
super(hls, Event.FRAG_LOADING);
|
||||
this.loaders = {};
|
||||
}
|
||||
|
||||
destroy () {
|
||||
destroy() {
|
||||
let loaders = this.loaders;
|
||||
for (let loaderName in loaders) {
|
||||
let loader = loaders[loaderName];
|
||||
|
@ -26,7 +47,7 @@ class FragmentLoader extends EventHandler {
|
|||
super.destroy();
|
||||
}
|
||||
|
||||
onFragLoading (data) {
|
||||
onFragLoading(data) {
|
||||
const frag = data.frag,
|
||||
type = frag.type,
|
||||
loaders = this.loaders,
|
||||
|
@ -39,7 +60,7 @@ class FragmentLoader extends EventHandler {
|
|||
|
||||
let loader = loaders[type];
|
||||
if (loader) {
|
||||
logger.warn(`abort previous fragment loader for type: ${type}`);
|
||||
console.warn(`abort previous fragment loader for type: ${type}`);
|
||||
loader.abort();
|
||||
}
|
||||
|
||||
|
@ -75,7 +96,7 @@ class FragmentLoader extends EventHandler {
|
|||
loader.load(loaderContext, loaderConfig, loaderCallbacks);
|
||||
}
|
||||
|
||||
loadsuccess (response, stats, context, networkDetails = null) {
|
||||
loadsuccess(response, stats, context, networkDetails = null) {
|
||||
let payload = response.data, frag = context.frag;
|
||||
// detach fragment loader on load success
|
||||
frag.loader = undefined;
|
||||
|
@ -83,7 +104,7 @@ class FragmentLoader extends EventHandler {
|
|||
this.hls.trigger(Event.FRAG_LOADED, { payload: payload, frag: frag, stats: stats, networkDetails: networkDetails });
|
||||
}
|
||||
|
||||
loaderror (response, context, networkDetails = null) {
|
||||
loaderror(response, context, networkDetails = null) {
|
||||
const frag = context.frag;
|
||||
let loader = frag.loader;
|
||||
if (loader) {
|
||||
|
@ -94,7 +115,7 @@ class FragmentLoader extends EventHandler {
|
|||
this.hls.trigger(Event.ERROR, { type: ErrorTypes.NETWORK_ERROR, details: ErrorDetails.FRAG_LOAD_ERROR, fatal: false, frag: context.frag, response: response, networkDetails: networkDetails });
|
||||
}
|
||||
|
||||
loadtimeout (stats, context, networkDetails = null) {
|
||||
loadtimeout(stats, context, networkDetails = null) {
|
||||
const frag = context.frag;
|
||||
let loader = frag.loader;
|
||||
if (loader) {
|
||||
|
@ -106,7 +127,7 @@ class FragmentLoader extends EventHandler {
|
|||
}
|
||||
|
||||
// data will be used for progressive parsing
|
||||
loadprogress (stats, context, data, networkDetails = null) { // jshint ignore:line
|
||||
loadprogress(stats, context, data, networkDetails = null) { // jshint ignore:line
|
||||
let frag = context.frag;
|
||||
frag.loaded = stats.loaded;
|
||||
this.hls.trigger(Event.FRAG_LOAD_PROGRESS, { frag: frag, stats: stats, networkDetails: networkDetails });
|
||||
|
|
|
@ -1,24 +1,45 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
class XhrLoader {
|
||||
constructor (config) {
|
||||
constructor(config) {
|
||||
if (config && config.xhrSetup) {
|
||||
this.xhrSetup = config.xhrSetup;
|
||||
}
|
||||
}
|
||||
|
||||
destroy () {
|
||||
destroy() {
|
||||
this.abort();
|
||||
this.loader = null;
|
||||
}
|
||||
|
||||
abort () {
|
||||
abort() {
|
||||
let loader = this.loader;
|
||||
if (loader && loader.readyState !== 4) {
|
||||
this.stats.aborted = true;
|
||||
|
@ -31,7 +52,7 @@ class XhrLoader {
|
|||
this.retryTimeout = null;
|
||||
}
|
||||
|
||||
load (context, config, callbacks) {
|
||||
load(context, config, callbacks) {
|
||||
this.context = context;
|
||||
this.config = config;
|
||||
this.callbacks = callbacks;
|
||||
|
@ -40,10 +61,11 @@ class XhrLoader {
|
|||
this.loadInternal();
|
||||
}
|
||||
|
||||
loadInternal () {
|
||||
loadInternal() {
|
||||
let xhr, context = this.context;
|
||||
xhr = this.loader = new XMLHttpRequest();
|
||||
|
||||
window.console.log("load internal xhr: " + context.url);
|
||||
|
||||
let stats = this.stats;
|
||||
stats.tfirst = 0;
|
||||
stats.loaded = 0;
|
||||
|
@ -82,7 +104,7 @@ class XhrLoader {
|
|||
xhr.send();
|
||||
}
|
||||
|
||||
readystatechange (event) {
|
||||
readystatechange(event) {
|
||||
let xhr = event.currentTarget,
|
||||
readyState = xhr.readyState,
|
||||
stats = this.stats,
|
||||
|
@ -121,11 +143,11 @@ class XhrLoader {
|
|||
} 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 (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);
|
||||
} else {
|
||||
// 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
|
||||
this.destroy();
|
||||
// schedule retry
|
||||
|
@ -142,12 +164,12 @@ class XhrLoader {
|
|||
}
|
||||
}
|
||||
|
||||
loadtimeout () {
|
||||
logger.warn(`timeout while loading ${this.context.url}`);
|
||||
loadtimeout() {
|
||||
console.warn(`timeout while loading ${this.context.url}`);
|
||||
this.callbacks.onTimeout(this.stats, this.context, null);
|
||||
}
|
||||
|
||||
loadprogress (event) {
|
||||
loadprogress(event) {
|
||||
let xhr = event.currentTarget,
|
||||
stats = this.stats;
|
||||
|
||||
|
|
Loading…
Reference in New Issue