mirror of
https://github.com/bytedream/stream-bypass.git
synced 2025-05-11 13:15:13 +02:00
Remove error message when video is not loaded properly
This commit is contained in:
parent
dd9bf71a5c
commit
6989587161
@ -1,5 +1,5 @@
|
|||||||
export enum Reliability {
|
export enum Reliability {
|
||||||
HIGH = 1,
|
HIGH,
|
||||||
NORMAL,
|
NORMAL,
|
||||||
LOW,
|
LOW,
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {Match, matches, Reliability} from "../../match/matches";
|
import {matches} from "../../match/matches";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import Hls from "hls.js";
|
import Hls from "hls.js";
|
||||||
|
|
||||||
@ -8,51 +8,13 @@ function show_message(message: string) {
|
|||||||
document.getElementById('video').hidden = true
|
document.getElementById('video').hidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function check_loaded(match: Match, check: Promise<boolean>) {
|
async function play_native(url: string) {
|
||||||
const loaded = await new Promise((resolve, _) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve(false)
|
|
||||||
}, match.reliability * 3000)
|
|
||||||
|
|
||||||
check
|
|
||||||
.then(value => resolve(value))
|
|
||||||
.catch(_ => resolve(false))
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!loaded) {
|
|
||||||
let message: string
|
|
||||||
switch (match.reliability) {
|
|
||||||
case Reliability.LOW:
|
|
||||||
message = `The reliability for this domain is low, errors like this are common.
|
|
||||||
Try to choose another streaming provider (if existent) or deactivate the addon for this provider (${match.name}) and try again`
|
|
||||||
break
|
|
||||||
case Reliability.NORMAL:
|
|
||||||
message = `The reliability for this domain is normal, errors like this can occur but are not very common. Try to refresh the page`
|
|
||||||
break
|
|
||||||
case Reliability.HIGH:
|
|
||||||
message = `The reliability for this domains is high, errors like this are very unlikely to happen.
|
|
||||||
Try to refresh the page and if the error still exists you might want to open a new issue.
|
|
||||||
When you're using Tor, such errors have a slight chance to occur more often,
|
|
||||||
so if this is the case just try to reload the page and see if it's working then`
|
|
||||||
break
|
|
||||||
}
|
|
||||||
show_message(`Could not load video. ${message}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function play_native(url: string, match: Match) {
|
|
||||||
const video = document.getElementById('video') as HTMLVideoElement
|
const video = document.getElementById('video') as HTMLVideoElement
|
||||||
video.controls = true
|
video.controls = true
|
||||||
video.src = url
|
video.src = url
|
||||||
|
|
||||||
const readyState = new Promise<boolean>((resolve, _) => {
|
|
||||||
video.onloadeddata = () => resolve(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
await check_loaded(match, readyState)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function play_hls(url: string, match: Match) {
|
async function play_hls(url: string) {
|
||||||
const video = document.getElementById('video') as HTMLVideoElement
|
const video = document.getElementById('video') as HTMLVideoElement
|
||||||
video.controls = true
|
video.controls = true
|
||||||
|
|
||||||
@ -64,12 +26,6 @@ async function play_hls(url: string, match: Match) {
|
|||||||
})
|
})
|
||||||
hls.loadSource(url)
|
hls.loadSource(url)
|
||||||
hls.attachMedia(video)
|
hls.attachMedia(video)
|
||||||
|
|
||||||
const readyState = new Promise<boolean>((resolve, _) => {
|
|
||||||
video.onloadeddata = () => resolve(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
await check_loaded(match, readyState)
|
|
||||||
} else {
|
} else {
|
||||||
show_message('Failed to play m3u8 video (hls is not supported). Try again or create a new issue <a href="https://github.com/ByteDream/stream-bypass/issues/new">here</a>')
|
show_message('Failed to play m3u8 video (hls is not supported). Try again or create a new issue <a href="https://github.com/ByteDream/stream-bypass/issues/new">here</a>')
|
||||||
}
|
}
|
||||||
@ -88,7 +44,7 @@ async function main() {
|
|||||||
}
|
}
|
||||||
document.title = `Stream Bypass (${domain})`
|
document.title = `Stream Bypass (${domain})`
|
||||||
|
|
||||||
url.endsWith('.m3u8') ? await play_hls(url, match) : await play_native(url, match)
|
url.endsWith('.m3u8') ? await play_hls(url) : await play_native(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user