Skip to content

Commit

Permalink
Merge pull request #62 from Stremio/fix-web-video-supported
Browse files Browse the repository at this point in the history
Do Not Trust `HTMLVideo` with Supported Types
  • Loading branch information
jaruba authored Feb 21, 2024
2 parents 8f7374f + 5810e3e commit 4c30f81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/supportsTranscoding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function supportsTranscoding() {
if (typeof global.tizen !== 'undefined' || typeof global.webOS !== 'undefined') {
return Promise.resolve(false);
}
return Promise.resolve(true);
}

module.exports = supportsTranscoding;
20 changes: 12 additions & 8 deletions src/withStreamingServer/withStreamingServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var deepFreeze = require('deep-freeze');
var mediaCapabilities = require('../mediaCapabilities');
var convertStream = require('./convertStream');
var fetchVideoParams = require('./fetchVideoParams');
var supportsTranscoding = require('../supportsTranscoding');
var ERROR = require('../error');

function withStreamingServer(Video) {
Expand Down Expand Up @@ -341,15 +342,13 @@ function withStreamingServer(Video) {
}

VideoWithStreamingServer.canPlayStream = function(stream, options) {
return Video.canPlayStream(stream)
.then(function(canPlay) {
if (!canPlay) {
throw new Error('Fallback using /hlsv2/probe');
return supportsTranscoding()
.then(function(supported) {
if (!supported) {
// we cannot probe the video in this case
return Video.canPlayStream(stream);
}

return canPlay;
})
.catch(function() {
// probing normally gives more accurate results
var queryParams = new URLSearchParams([['mediaURL', stream.url]]);
return fetch(url.resolve(options.streamingServerURL, '/hlsv2/probe?' + queryParams.toString()))
.then(function(resp) {
Expand All @@ -370,6 +369,11 @@ function withStreamingServer(Video) {
return true;
});
return isFormatSupported && areStreamsSupported;
})
.catch(function() {
// this uses content-type header in HTMLVideo which
// is unreliable, check can also fail due to CORS
return Video.canPlayStream(stream);
});
});
};
Expand Down

0 comments on commit 4c30f81

Please sign in to comment.