HLS player fallback for non https context

This commit is contained in:
Chocobozzz 2020-11-10 10:36:50 +01:00
parent c2ecfe82b7
commit 6d61da4e32
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 21 additions and 5 deletions

2
FAQ.md
View File

@ -114,7 +114,7 @@ As a real life example, the PeerTube demonstration server [https://peertube.cpy.
### CPU
Except for video transcoding, a PeerTube instance is not CPU bound. Neither Nginx, PeerTube itself, PpostgreSQL nor Redis require a lot of computing power. If it were only for those, one could easily get by with just one thread/vCPU.
Except for video transcoding, a PeerTube instance is not CPU bound. Neither Nginx, PeerTube itself, PostgreSQL nor Redis require a lot of computing power. If it were only for those, one could easily get by with just one thread/vCPU.
You will hugely benefit from at least a second thread though, because of transcoding. Transcoding _is_ very cpu intensive. It serves two purposes on a PeerTube instance: it ensures all videos can be played optimally in the web interface, and it generates different resolutions for the same video. PeerTube support for offloading transcoding to other machines is being discussed, but not yet implemented. See https://github.com/Chocobozzz/PeerTube/issues/947 .

View File

@ -63,6 +63,7 @@
"@types/markdown-it": "^10.0.1",
"@types/node": "^14.0.14",
"@types/sanitize-html": "1.23.3",
"@types/sha.js": "^2.4.0",
"@types/socket.io-client": "^1.4.32",
"@types/video.js": "^7.3.8",
"@types/webtorrent": "^0.107.0",
@ -110,6 +111,7 @@
"sass-lint": "^1.13.1",
"sass-loader": "8.0.2",
"sass-resources-loader": "^2.0.0",
"sha.js": "^2.4.11",
"socket.io-client": "^2.2.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.0.0",

View File

@ -41,7 +41,7 @@ function segmentValidatorFactory (segmentsSha256Url: string) {
throw new Error(`Unknown segment name ${filename}/${range} in segment validator`)
}
const calculatedSha = bufferToEx(await sha256(segment.data))
const calculatedSha = await sha256Hex(segment.data)
if (calculatedSha !== hashShouldBe) {
throw new Error(
`Hashes does not correspond for segment ${filename}/${range}` +
@ -68,14 +68,21 @@ function fetchSha256Segments (url: string) {
})
}
function sha256 (data?: ArrayBuffer) {
async function sha256Hex (data?: ArrayBuffer) {
if (!data) return undefined
return window.crypto.subtle.digest('SHA-256', data)
if (window.crypto.subtle) {
return window.crypto.subtle.digest('SHA-256', data)
.then(data => bufferToHex(data))
}
// Fallback for non HTTPS context
const shaModule = await import('sha.js')
return new shaModule.sha256().update(Buffer.from(data)).digest('hex')
}
// Thanks: https://stackoverflow.com/a/53307879
function bufferToEx (buffer?: ArrayBuffer) {
function bufferToHex (buffer?: ArrayBuffer) {
if (!buffer) return ''
let s = ''

View File

@ -1495,6 +1495,13 @@
resolved "https://registry.yarnpkg.com/@types/selenium-webdriver/-/selenium-webdriver-3.0.17.tgz#50bea0c3c2acc31c959c5b1e747798b3b3d06d4b"
integrity sha512-tGomyEuzSC1H28y2zlW6XPCaDaXFaD6soTdb4GNdmte2qfHtrKqhy0ZFs4r/1hpazCfEZqeTSRLvSasmEx89uw==
"@types/sha.js@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@types/sha.js/-/sha.js-2.4.0.tgz#bce682ef860b40f419d024fa08600c3b8d24bb01"
integrity sha512-amxKgPy6WJTKuw8mpUwjX2BSxuBtBmZfRwIUDIuPJKNwGN8CWDli8JTg5ONTWOtcTkHIstvT7oAhhYXqEjStHQ==
dependencies:
"@types/node" "*"
"@types/simple-peer@*":
version "9.6.0"
resolved "https://registry.yarnpkg.com/@types/simple-peer/-/simple-peer-9.6.0.tgz#b5828d835b7f42dde27db584ba127e7a9f9072f4"