Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
XHR(opts, Fn.bind(this, function(err, response, responseBody){
if (err) {
return log.error(err, response);
}
track.loaded_ = true;
// NOTE: this is only used for the alt/video.novtt.js build
if (typeof window.WebVTT !== 'function') {
window.setTimeout(function() {
parseCues(responseBody, track);
}, 100);
} else {
parseCues(responseBody, track);
}
}));
};
function isFunction (fn) {
var string = toString.call(fn)
return string === '[object Function]' ||
(typeof fn === 'function' && string !== '[object RegExp]') ||
(typeof window !== 'undefined' &&
// IE8 and below
(fn === window.setTimeout ||
fn === window.alert ||
fn === window.confirm ||
fn === window.prompt))
};
// merge this playlist into the master
const update = updateMaster(this.master, parser.manifest);
this.targetDuration = parser.manifest.targetDuration;
if (update) {
this.master = update;
this.media_ = this.master.playlists[id];
} else {
this.trigger('playlistunchanged');
}
// refresh live playlists after a target duration passes
if (!this.media().endList) {
window.clearTimeout(this.mediaUpdateTimeout);
this.mediaUpdateTimeout = window.setTimeout(() => {
this.trigger('mediaupdatetimeout');
}, refreshDelay(this.media(), !!update));
}
this.trigger('loadedplaylist');
}
request.onreadystatechange = function() {
if (request.readyState === 4) {
if (request.timedout) {
return errorHandler('timeout');
}
if (request.status === 200 || fileUrl && request.status === 0) {
successHandler();
} else {
errorHandler();
}
}
};
if (options.timeout) {
abortTimeout = window.setTimeout(function() {
if (request.readyState !== 4) {
request.timedout = true;
request.abort();
}
}, options.timeout);
}
}
// open the connection
try {
// Third arg is async, or ignored by XDomainRequest
request.open(options.method || 'GET', options.uri, true);
} catch(err) {
return errorHandler(err);
}
setTimeout(fn, timeout) {
// declare as variables so they are properly available in timeout function
// eslint-disable-next-line
var timeoutId, disposeFn;
fn = Fn.bind(this, fn);
this.clearTimersOnDispose_();
timeoutId = window.setTimeout(() => {
if (this.setTimeoutIds_.has(timeoutId)) {
this.setTimeoutIds_.delete(timeoutId);
}
fn();
}, timeout);
this.setTimeoutIds_.add(timeoutId);
return timeoutId;
}
function isFunction (fn) {
var string = toString.call(fn)
return string === '[object Function]' ||
(typeof fn === 'function' && string !== '[object RegExp]') ||
(typeof window !== 'undefined' &&
// IE8 and below
(fn === window.setTimeout ||
fn === window.alert ||
fn === window.confirm ||
fn === window.prompt))
};
}
// switching to the active playlist is a no-op
if (!mediaChange) {
return;
}
// switching from an already loaded playlist
if (this.media_) {
this.trigger('mediachanging');
}
if (!playlist.sidx) {
// Continue asynchronously if there is no sidx
// wait one tick to allow haveMaster to run first on a child loader
this.mediaRequest_ = window.setTimeout(
this.haveMetadata.bind(this, { startingState, playlist }),
0
);
// exit early and don't do sidx work
return;
}
// we have sidx mappings
let oldMaster;
let sidxMapping;
// sidxMapping is used when parsing the masterXml, so store
// it on the masterPlaylistLoader
if (this.masterPlaylistLoader_) {
oldMaster = this.masterPlaylistLoader_.master;
private reconnectAndSend(
retryCount: number,
req: WsRequest,
timeoutId?: number
): void {
const readyState = this.ws.readyState;
if (timeoutId) {
window.clearTimeout(timeoutId);
}
if (retryCount > 0) {
const id = window.setTimeout(() => {
if (readyState === 1) {
this.ws.send(JSON.stringify(req));
window.clearTimeout(id);
} else {
const count = retryCount - 1;
this.reconnectAndSend(count, req, id);
}
}, this.options.retryDuration);
} else {
window.console.error(
"ws plugin connect error, please retry again later."
);
}
}
const updatedMaster = updateMaster(oldMaster, newMaster);
if (updatedMaster) {
if (this.masterPlaylistLoader_) {
this.masterPlaylistLoader_.master = updatedMaster;
} else {
this.master = updatedMaster;
}
this.media_ = updatedMaster.playlists[mediaID];
} else {
this.media_ = newMaster.playlists[mediaID];
this.trigger('playlistunchanged');
}
if (!this.media().endList) {
this.mediaUpdateTimeout = window.setTimeout(() => {
this.trigger('mediaupdatetimeout');
}, refreshDelay(this.media(), !!updatedMaster));
}
this.trigger('loadedplaylist');
}
}