Skip to content

Commit

Permalink
Distinguish test logs from player logs
Browse files Browse the repository at this point in the history
trace video.play()
  • Loading branch information
Rob Walch committed May 7, 2020
1 parent 3b3aeb4 commit 17a3417
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
10 changes: 5 additions & 5 deletions tests/functional/auto/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ async function testSmoothSwitch (url, config) {
window.switchToHighestLevel('next');
});
window.hls.on(window.Hls.Events.LEVEL_SWITCHED, (event, data) => {
console.log(`[log] > level switched: ${data.level}`);
console.log(`[test] > level switched: ${data.level}`);
let currentTime = video.currentTime;
if (data.level === window.hls.levels.length - 1) {
console.log(`[log] > switched on level: ${data.level}`);
console.log(`[test] > switched on level: ${data.level}`);
window.setTimeout(() => {
let newCurrentTime = video.currentTime;
console.log(
`[log] > currentTime delta : ${newCurrentTime - currentTime}`
`[test] > currentTime delta : ${newCurrentTime - currentTime}`
);
callback({
code: newCurrentTime > currentTime,
Expand Down Expand Up @@ -204,13 +204,13 @@ async function testIsPlayingVOD (url, config) {
if (expectedPlaying) {
window.setTimeout(() => {
console.log(
`video expected playing. [last currentTime/new currentTime]=[${currentTime}/${video.currentTime}]`
`[test] > video expected playing. [last currentTime/new currentTime]=[${currentTime}/${video.currentTime}]`
);
callback({ playing: currentTime !== video.currentTime });
}, 5000);
} else {
console.log(
`video not playing. [paused/ended/buffered.length]=[${video.paused}/${video.ended}/${video.buffered.length}]`
`[test] > video not playing. [paused/ended/buffered.length]=[${video.paused}/${video.ended}/${video.buffered.length}]`
);
callback({ playing: false });
}
Expand Down
86 changes: 44 additions & 42 deletions tests/functional/auto/testbench.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,54 +74,55 @@ function startStream (streamUrl, config, callback) {
if (!Hls) {
throw new Error('Hls not installed');
}

if (Hls.isSupported()) {
if (hls) {
callback({ code: 'hlsjsAlreadyInitialised', logs: logString });
return;
}
window.video = video = document.getElementById('video');
try {
window.hls = hls = new Hls(objectAssign({}, config, { debug: true }));
console.log(navigator.userAgent);
hls.loadSource(streamUrl);
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
var playPromise = video.play();
if (playPromise) {
playPromise.catch(function (error) {
console.log('video.play() failed with error:', error);
if (error.name === 'NotAllowedError') {
console.log('Attempting to play with video muted');
video.muted = true;
return video.play();
}
});
}
});
hls.on(Hls.Events.ERROR, function (event, data) {
if (data.fatal) {
console.log('hlsjs fatal error :' + data.details);
if (data.details === Hls.ErrorDetails.INTERNAL_EXCEPTION) {
console.log('exception in :' + data.event);
console.log(data.err.stack ? JSON.stringify(data.err.stack) : data.err.message);
if (!Hls.isSupported()) {
callback({ code: 'notSupported', logs: logString });
return;
}
if (hls) {
callback({ code: 'hlsjsAlreadyInitialised', logs: logString });
return;
}
window.video = video = document.getElementById('video');
try {
window.hls = hls = new Hls(objectAssign({}, config, { debug: true }));
console.log('[test] > userAgent:', navigator.userAgent);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
console.log('[test] > Manifest parsed. Calling video.play()');
var playPromise = video.play();
if (playPromise) {
playPromise.catch(function (error) {
console.log('[test] > video.play() failed with error:', error);
if (error.name === 'NotAllowedError') {
console.log('[test] > Attempting to play with video muted');
video.muted = true;
return video.play();
}
callback({ code: data.details, logs: logString });
});
}
});
hls.on(Hls.Events.ERROR, function (event, data) {
if (data.fatal) {
console.log('[test] > hlsjs fatal error :' + data.details);
if (data.details === Hls.ErrorDetails.INTERNAL_EXCEPTION) {
console.log('[test] > exception in :' + data.event);
console.log(data.err.stack ? JSON.stringify(data.err.stack) : data.err.message);
}
});
video.onerror = function (event) {
console.log('video error, code :' + video.error.code);
callback({ code: 'video_error_' + video.error.code, logs: logString });
};
} catch (err) {
callback({ code: 'exception', logs: logString });
}
} else {
callback({ code: 'notSupported', logs: logString });
callback({ code: data.details, logs: logString });
}
});
video.onerror = function (event) {
console.log('[test] > video error, code :' + video.error.code);
callback({ code: 'video_error_' + video.error.code, logs: logString });
};
hls.loadSource(streamUrl);
hls.attachMedia(video);
} catch (err) {
callback({ code: 'exception', logs: logString });
}
}

function switchToLowestLevel (mode) {
console.log('[test] > switch to lowest level', mode);
switch (mode) {
case 'current':
hls.currentLevel = 0;
Expand All @@ -138,6 +139,7 @@ function switchToLowestLevel (mode) {

function switchToHighestLevel (mode) {
var highestLevel = hls.levels.length - 1;
console.log('[test] > switch to highest level', highestLevel, mode);
switch (mode) {
case 'current':
hls.currentLevel = highestLevel;
Expand Down

0 comments on commit 17a3417

Please sign in to comment.