From 5555dad0832cf0ce5bef994744a0c889c5a64203 Mon Sep 17 00:00:00 2001 From: hibna Date: Tue, 4 Nov 2025 05:43:18 +0300 Subject: [PATCH] Update MPEG-TS detection to use HLS.js transmuxing Changed MPEG-TS (IPTV) stream detection to use HLS.js for transmuxing instead of native playback, as browsers do not natively support MPEG-TS. Updated related tests and marked 'needsSpecialPlayer' as true. Also configured Vite to treat 'hls.js' and 'flv.js' as external dependencies. --- src/utils/videoProtocol.test.ts | 12 ++++++------ src/utils/videoProtocol.ts | 7 ++++--- vite.config.ts | 5 +++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/utils/videoProtocol.test.ts b/src/utils/videoProtocol.test.ts index dceda70..6ca58f8 100644 --- a/src/utils/videoProtocol.test.ts +++ b/src/utils/videoProtocol.test.ts @@ -5,16 +5,16 @@ describe('videoProtocol', () => { describe('detectVideoProtocol', () => { it('should detect MPEG-TS IPTV streams', () => { const result = detectVideoProtocol('http://favoritv65.xyz:8080/live/Apollon45/HpjWrDa6gWWd/98925.ts') - expect(result.protocol).toBe('native') + expect(result.protocol).toBe('hls') expect(result.isLive).toBe(true) - expect(result.needsSpecialPlayer).toBe(false) + expect(result.needsSpecialPlayer).toBe(true) }) it('should detect .ts files with query parameters', () => { const result = detectVideoProtocol('http://example.com/stream/video.ts?token=abc123') - expect(result.protocol).toBe('native') + expect(result.protocol).toBe('hls') expect(result.isLive).toBe(true) - expect(result.needsSpecialPlayer).toBe(false) + expect(result.needsSpecialPlayer).toBe(true) }) it('should detect HLS streams', () => { @@ -75,8 +75,8 @@ describe('videoProtocol', () => { expect(isHlsStream('http://example.com/stream.m3u8')).toBe(true) }) - it('should return false for IPTV .ts streams (they are native, not HLS)', () => { - expect(isHlsStream('http://favoritv65.xyz:8080/live/user/pass/98925.ts')).toBe(false) + it('should return true for IPTV .ts streams (they use HLS.js for transmuxing)', () => { + expect(isHlsStream('http://favoritv65.xyz:8080/live/user/pass/98925.ts')).toBe(true) }) it('should return false for non-HLS streams', () => { diff --git a/src/utils/videoProtocol.ts b/src/utils/videoProtocol.ts index 08765e5..27d0094 100644 --- a/src/utils/videoProtocol.ts +++ b/src/utils/videoProtocol.ts @@ -73,12 +73,13 @@ export const detectVideoProtocol = (src: string): ProtocolDetectionResult => { // MPEG-TS (IPTV) detection // Check for .ts extension (Transport Stream used in IPTV) - // Note: These are direct TS streams, not HLS playlists, so we use native playback + // Note: These are direct TS streams, not HLS playlists + // We use HLS.js to transmux them as browsers don't support MPEG-TS natively if (lowerSrc.includes('.ts') || lowerSrc.match(/\.ts(\?|$)/)) { return { - protocol: 'native', // Use native video element for direct TS streams + protocol: 'hls', // Use HLS.js which can handle MPEG-TS transmuxing isLive: true, // IPTV streams are typically live - needsSpecialPlayer: false, // Modern browsers can handle MPEG-TS directly + needsSpecialPlayer: true, // Requires HLS.js for MPEG-TS transmuxing } } diff --git a/vite.config.ts b/vite.config.ts index ddb98da..e50dcea 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,4 +11,9 @@ export default defineConfig({ '@': path.resolve(__dirname, './src'), }, }, + build: { + rollupOptions: { + external: ['hls.js', 'flv.js'], + }, + }, })