]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
HLS player fallback for non https context
authorChocobozzz <me@florianbigard.com>
Tue, 10 Nov 2020 09:36:50 +0000 (10:36 +0100)
committerChocobozzz <me@florianbigard.com>
Tue, 10 Nov 2020 09:36:50 +0000 (10:36 +0100)
FAQ.md
client/package.json
client/src/assets/player/p2p-media-loader/segment-validator.ts
client/yarn.lock

diff --git a/FAQ.md b/FAQ.md
index b84696620ad580895a509739f97e4fd0528e4aba..56da720ced5110bf7a6128d92fb91120533af842 100644 (file)
--- a/FAQ.md
+++ b/FAQ.md
@@ -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 .
 
index 152f8445fc7284cb29e0b26770f6e9ac202d4430..5147ca86c8b15de76045e595b339e25081a447b4 100644 (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",
     "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",
index 0614f73d2dc79bb70715cc245342a78516c27665..fa6e6df1db2fd1c898534b9fdf531f465fac65db 100644 (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 = ''
index d3603a4a9101578b5cd255e8779d87394b2a9adb..0efcabe8c6facd1ed750dd0c06d461d0d2a85406 100644 (file)
   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"