Skip to content

Commit

Permalink
use fetch with get meta m3u8 (fix loop in start >50tabs)
Browse files Browse the repository at this point in the history
  • Loading branch information
tachibana-shin committed Sep 16, 2023
1 parent fca3306 commit 725b4f2
Showing 1 changed file with 85 additions and 83 deletions.
168 changes: 85 additions & 83 deletions src/components/BrtPlayer.vue
Expand Up @@ -1884,94 +1884,96 @@ function remount(resetCurrentTime?: boolean, noDestroy = false) {
return new Request(context.url, initParams)
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any, functional/no-classes

Check failure on line 1886 in src/components/BrtPlayer.vue

View workflow job for this annotation

GitHub Actions / Run eslint scanning

'@typescript-eslint/no-explicit-any' rule is disabled but never reported
pLoader: class CustomLoader extends (Hls.DefaultConfig.loader as any) {
loadInternal(): void {
const { config, context } = this
if (!config) {
return
}
const { stats } = this
stats.loading.first = 0
stats.loaded = 0
const controller = new AbortController()
const xhr = (this.loader = {
readyState: 0,
status: 0,
responseType: context.responseType,
abort() {
controller.abort()
},
onreadystatechange: <(() => void) | null>null,
onprogress: <
((eventt: { loaded: number; total: number }) => void) | null
>null,
response: <ArrayBuffer | null>null,
responseText: <string | null>null,
})
const headers = new Headers()
if (this.context.headers)
// eslint-disable-next-line functional/no-loop-statements
for (const [key, val] of Object.entries(this.context.headers))
headers.set(key, val as string)
const { maxTimeToFirstByteMs, maxLoadTimeMs } = config.loadPolicy
if (context.rangeEnd) {
headers.set(
"Range",
"bytes=" + context.rangeStart + "-" + (context.rangeEnd - 1)
)
}
pLoader: offEnds
? undefined
: (class CustomLoader extends (Hls.DefaultConfig.loader as any) {

Check failure on line 1889 in src/components/BrtPlayer.vue

View workflow job for this annotation

GitHub Actions / Run eslint scanning

Unexpected class, use functions not classes

Check warning on line 1889 in src/components/BrtPlayer.vue

View workflow job for this annotation

GitHub Actions / Run eslint scanning

Unexpected any. Specify a different type
loadInternal(): void {
const { config, context } = this
if (!config) {
return
}
xhr.onreadystatechange = this.readystatechange.bind(this)
xhr.onprogress = this.loadprogress.bind(this)
self.clearTimeout(this.requestTimeout)
config.timeout =
maxTimeToFirstByteMs && Number.isFinite(maxTimeToFirstByteMs)
? maxTimeToFirstByteMs
: maxLoadTimeMs
this.requestTimeout = self.setTimeout(
this.loadtimeout.bind(this),
config.timeout
)
fetchJava(context.url + "#animevsub-vsub", {
headers,
signal: controller.signal,
})
.then(async (res) => {
// eslint-disable-next-line functional/no-let
let byteLength: number
if (context.responseType !== "text") {
xhr.response = await res.arrayBuffer()
byteLength = xhr.response.byteLength
} else {
xhr.responseText = await res.text()
byteLength = xhr.responseText.length
const { stats } = this
stats.loading.first = 0
stats.loaded = 0
const controller = new AbortController()
const xhr = (this.loader = {
readyState: 0,
status: 0,
responseType: context.responseType,
abort() {
controller.abort()
},
onreadystatechange: <(() => void) | null>null,
onprogress: <
((eventt: { loaded: number; total: number }) => void) | null
>null,
response: <ArrayBuffer | null>null,
responseText: <string | null>null,
})
const headers = new Headers()
if (this.context.headers)
// eslint-disable-next-line functional/no-loop-statements
for (const [key, val] of Object.entries(this.context.headers))
headers.set(key, val as string)
const { maxTimeToFirstByteMs, maxLoadTimeMs } = config.loadPolicy
if (context.rangeEnd) {
headers.set(
"Range",
"bytes=" + context.rangeStart + "-" + (context.rangeEnd - 1)
)
}
xhr.readyState = 4
xhr.status = 200
xhr.responseType = context.responseType
xhr.onreadystatechange = this.readystatechange.bind(this)
xhr.onprogress = this.loadprogress.bind(this)
self.clearTimeout(this.requestTimeout)
config.timeout =
maxTimeToFirstByteMs && Number.isFinite(maxTimeToFirstByteMs)
? maxTimeToFirstByteMs
: maxLoadTimeMs
this.requestTimeout = self.setTimeout(
this.loadtimeout.bind(this),
config.timeout
)
xhr.onprogress?.({
loaded: byteLength,
total: byteLength,
fetchJava(context.url + "#animevsub-vsub", {
headers,
signal: controller.signal,
})
// eslint-disable-next-line promise/always-return
xhr.onreadystatechange?.()
})
.catch((e) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.callbacks!.onError(
{ code: xhr.status, text: e.message },
context,
xhr
)
})
}
} as unknown as PlaylistLoaderConstructor,
.then(async (res) => {
// eslint-disable-next-line functional/no-let
let byteLength: number
if (context.responseType !== "text") {
xhr.response = await res.arrayBuffer()
byteLength = xhr.response.byteLength
} else {
xhr.responseText = await res.text()
byteLength = xhr.responseText.length
}
xhr.readyState = 4
xhr.status = 200
xhr.responseType = context.responseType
xhr.onprogress?.({
loaded: byteLength,
total: byteLength,
})
// eslint-disable-next-line promise/always-return
xhr.onreadystatechange?.()
})
.catch((e) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.callbacks!.onError(
{ code: xhr.status, text: e.message },
context,
xhr
)
})
}
} as unknown as PlaylistLoaderConstructor),
})
if (!offEnds) patcher(hls)
currentHls = hls
Expand Down

0 comments on commit 725b4f2

Please sign in to comment.