mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-03 05:43:50 +02:00
Simplify isWebKit, get rid of isSafari
This commit is contained in:
+4
-4
@@ -26,7 +26,7 @@ import {
|
|||||||
insertSorted,
|
insertSorted,
|
||||||
isFirefox,
|
isFirefox,
|
||||||
isNumber,
|
isNumber,
|
||||||
isSafari,
|
isWebKit,
|
||||||
last,
|
last,
|
||||||
mapAsyncGenerator,
|
mapAsyncGenerator,
|
||||||
promiseWithResolvers,
|
promiseWithResolvers,
|
||||||
@@ -918,7 +918,7 @@ class VideoDecoderWrapper extends DecoderWrapper<VideoSample> {
|
|||||||
} else {
|
} else {
|
||||||
assert(this.decoder);
|
assert(this.decoder);
|
||||||
|
|
||||||
if (!isSafari()) {
|
if (!isWebKit()) {
|
||||||
insertSorted(this.inputTimestamps, packet.timestamp, x => x);
|
insertSorted(this.inputTimestamps, packet.timestamp, x => x);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1049,7 +1049,7 @@ class VideoDecoderWrapper extends DecoderWrapper<VideoSample> {
|
|||||||
|
|
||||||
/** Handler for the WebCodecs VideoDecoder for ironing out browser differences. */
|
/** Handler for the WebCodecs VideoDecoder for ironing out browser differences. */
|
||||||
sampleHandler(sample: VideoSample) {
|
sampleHandler(sample: VideoSample) {
|
||||||
if (isSafari()) {
|
if (isWebKit()) {
|
||||||
// For correct B-frame handling, we don't just hand over the frames directly but instead add them to
|
// For correct B-frame handling, we don't just hand over the frames directly but instead add them to
|
||||||
// a queue, because we want to ensure frames are emitted in presentation order. We flush the queue
|
// a queue, because we want to ensure frames are emitted in presentation order. We flush the queue
|
||||||
// each time we receive a frame with a timestamp larger than the highest we've seen so far, as we
|
// each time we receive a frame with a timestamp larger than the highest we've seen so far, as we
|
||||||
@@ -1137,7 +1137,7 @@ class VideoDecoderWrapper extends DecoderWrapper<VideoSample> {
|
|||||||
this.alphaRaslSkipped = false;
|
this.alphaRaslSkipped = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSafari()) {
|
if (isWebKit()) {
|
||||||
for (const sample of this.sampleQueue) {
|
for (const sample of this.sampleQueue) {
|
||||||
this.finalizeAndEmitSample(sample);
|
this.finalizeAndEmitSample(sample);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-34
@@ -658,44 +658,17 @@ export class CallSerializer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let isSafariCache: boolean | null = null;
|
|
||||||
export const isSafari = () => {
|
|
||||||
if (isSafariCache !== null) {
|
|
||||||
return isSafariCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = !!(
|
|
||||||
typeof navigator !== 'undefined'
|
|
||||||
&& navigator.vendor?.match(/apple/i)
|
|
||||||
&& !navigator.userAgent?.match(/crios/i)
|
|
||||||
&& !navigator.userAgent?.match(/fxios/i)
|
|
||||||
&& !navigator.userAgent?.match(/Opera|OPT\//)
|
|
||||||
);
|
|
||||||
|
|
||||||
isSafariCache = result;
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
|
|
||||||
let isWebKitCache: boolean | null = null;
|
let isWebKitCache: boolean | null = null;
|
||||||
export const isWebKit = () => {
|
export const isWebKit = () => {
|
||||||
if (isWebKitCache !== null) return isWebKitCache;
|
if (isWebKitCache !== null) {
|
||||||
if (typeof navigator === 'undefined') return (isWebKitCache = false);
|
return isWebKitCache;
|
||||||
|
}
|
||||||
|
|
||||||
const ua = navigator.userAgent || '';
|
// This even returns true for WebKit-wrapping browsers such as Chrome on iOS
|
||||||
const maxTouchPoints = navigator.maxTouchPoints || 0;
|
const result = !!(typeof navigator !== 'undefined' && navigator.vendor?.match(/apple/i));
|
||||||
|
|
||||||
// iOS/iPadOS detection:
|
isWebKitCache = result;
|
||||||
// - All iOS/iPadOS browsers use WebKit (WKWebView)
|
return result;
|
||||||
// - iPadOS 13+ can report "Macintosh" in UA; detect via touch points
|
|
||||||
const isIOSLike
|
|
||||||
= /iPhone|iPad|iPod/i.test(ua) || (/Macintosh/i.test(ua) && maxTouchPoints > 1);
|
|
||||||
|
|
||||||
// On iOS/iPadOS: always WebKit (even if UA says CriOS/Edg/OPR/etc.)
|
|
||||||
if (isIOSLike) return (isWebKitCache = true);
|
|
||||||
|
|
||||||
// Off iOS: only Safari is WebKit on mainstream desktops
|
|
||||||
const result = isSafari();
|
|
||||||
return (isWebKitCache = result);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let isFirefoxCache: boolean | null = null;
|
let isFirefoxCache: boolean | null = null;
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ export class BlobSource extends Source {
|
|||||||
private async _runWorker(worker: ReadWorker) {
|
private async _runWorker(worker: ReadWorker) {
|
||||||
let reader = this._readers.get(worker);
|
let reader = this._readers.get(worker);
|
||||||
if (reader === undefined) {
|
if (reader === undefined) {
|
||||||
|
// https://github.com/Vanilagy/mediabunny/issues/184
|
||||||
// WebKit has critical bugs with blob.stream():
|
// WebKit has critical bugs with blob.stream():
|
||||||
// - WebKitBlobResource error 1 when streaming large files
|
// - WebKitBlobResource error 1 when streaming large files
|
||||||
// - Memory buildup and reload loops on iOS (network process crashes)
|
// - Memory buildup and reload loops on iOS (network process crashes)
|
||||||
|
|||||||
Reference in New Issue
Block a user