aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-10 10:36:50 +0100
committerChocobozzz <me@florianbigard.com>2020-11-10 10:36:50 +0100
commit6d61da4e32487bdb1f1a84a7b2eddf2df0ddf1ca (patch)
tree79a3f1d5635e4e2b44fbc53a21a8ebfee453c9e7 /client/src/assets/player
parentc2ecfe82b74f5dfeb9077a31fe70946e49f7d03a (diff)
downloadPeerTube-6d61da4e32487bdb1f1a84a7b2eddf2df0ddf1ca.tar.gz
PeerTube-6d61da4e32487bdb1f1a84a7b2eddf2df0ddf1ca.tar.zst
PeerTube-6d61da4e32487bdb1f1a84a7b2eddf2df0ddf1ca.zip
HLS player fallback for non https context
Diffstat (limited to 'client/src/assets/player')
-rw-r--r--client/src/assets/player/p2p-media-loader/segment-validator.ts15
1 files changed, 11 insertions, 4 deletions
diff --git a/client/src/assets/player/p2p-media-loader/segment-validator.ts b/client/src/assets/player/p2p-media-loader/segment-validator.ts
index 0614f73d2..fa6e6df1d 100644
--- a/client/src/assets/player/p2p-media-loader/segment-validator.ts
+++ b/client/src/assets/player/p2p-media-loader/segment-validator.ts
@@ -41,7 +41,7 @@ function segmentValidatorFactory (segmentsSha256Url: string) {
41 throw new Error(`Unknown segment name ${filename}/${range} in segment validator`) 41 throw new Error(`Unknown segment name ${filename}/${range} in segment validator`)
42 } 42 }
43 43
44 const calculatedSha = bufferToEx(await sha256(segment.data)) 44 const calculatedSha = await sha256Hex(segment.data)
45 if (calculatedSha !== hashShouldBe) { 45 if (calculatedSha !== hashShouldBe) {
46 throw new Error( 46 throw new Error(
47 `Hashes does not correspond for segment ${filename}/${range}` + 47 `Hashes does not correspond for segment ${filename}/${range}` +
@@ -68,14 +68,21 @@ function fetchSha256Segments (url: string) {
68 }) 68 })
69} 69}
70 70
71function sha256 (data?: ArrayBuffer) { 71async function sha256Hex (data?: ArrayBuffer) {
72 if (!data) return undefined 72 if (!data) return undefined
73 73
74 return window.crypto.subtle.digest('SHA-256', data) 74 if (window.crypto.subtle) {
75 return window.crypto.subtle.digest('SHA-256', data)
76 .then(data => bufferToHex(data))
77 }
78
79 // Fallback for non HTTPS context
80 const shaModule = await import('sha.js')
81 return new shaModule.sha256().update(Buffer.from(data)).digest('hex')
75} 82}
76 83
77// Thanks: https://stackoverflow.com/a/53307879 84// Thanks: https://stackoverflow.com/a/53307879
78function bufferToEx (buffer?: ArrayBuffer) { 85function bufferToHex (buffer?: ArrayBuffer) {
79 if (!buffer) return '' 86 if (!buffer) return ''
80 87
81 let s = '' 88 let s = ''