b0e278afb5
Introduces MPEG-TS streaming support by adding mpegts.js as an optional dependency, updating keywords, and implementing new utility modules for MPEG-TS loading and setup. Updates VideoElement and videoProtocol logic to handle MPEG-TS streams, adds corresponding tests and mocks, and improves local settings for npm install.
119 lines
4.2 KiB
TypeScript
119 lines
4.2 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { detectVideoProtocol, isHlsStream, isRtmpStream, isLiveStream } from './videoProtocol'
|
|
|
|
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('mpegts')
|
|
expect(result.isLive).toBe(true)
|
|
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('mpegts')
|
|
expect(result.isLive).toBe(true)
|
|
expect(result.needsSpecialPlayer).toBe(true)
|
|
})
|
|
|
|
it('should detect HLS streams', () => {
|
|
const result = detectVideoProtocol('http://example.com/stream/playlist.m3u8')
|
|
expect(result.protocol).toBe('hls')
|
|
expect(result.needsSpecialPlayer).toBe(true)
|
|
})
|
|
|
|
it('should detect live HLS streams', () => {
|
|
const result = detectVideoProtocol('http://example.com/live/stream/playlist.m3u8')
|
|
expect(result.protocol).toBe('hls')
|
|
expect(result.isLive).toBe(true)
|
|
expect(result.needsSpecialPlayer).toBe(true)
|
|
})
|
|
|
|
it('should detect RTMP streams', () => {
|
|
const result = detectVideoProtocol('rtmp://example.com/live/stream')
|
|
expect(result.protocol).toBe('rtmp')
|
|
expect(result.isLive).toBe(true)
|
|
expect(result.needsSpecialPlayer).toBe(true)
|
|
})
|
|
|
|
it('should detect FLV streams', () => {
|
|
const result = detectVideoProtocol('http://example.com/stream.flv')
|
|
expect(result.protocol).toBe('rtmp')
|
|
expect(result.needsSpecialPlayer).toBe(true)
|
|
})
|
|
|
|
it('should detect DASH streams', () => {
|
|
const result = detectVideoProtocol('http://example.com/stream.mpd')
|
|
expect(result.protocol).toBe('dash')
|
|
expect(result.needsSpecialPlayer).toBe(true)
|
|
})
|
|
|
|
it('should detect native video formats', () => {
|
|
const result = detectVideoProtocol('http://example.com/video.mp4')
|
|
expect(result.protocol).toBe('native')
|
|
expect(result.isLive).toBe(false)
|
|
expect(result.needsSpecialPlayer).toBe(false)
|
|
})
|
|
|
|
it('should handle empty string', () => {
|
|
const result = detectVideoProtocol('')
|
|
expect(result.protocol).toBe('native')
|
|
expect(result.isLive).toBe(false)
|
|
expect(result.needsSpecialPlayer).toBe(false)
|
|
})
|
|
|
|
it('should not confuse TypeScript files with transport streams', () => {
|
|
// .ts in path but not as extension shouldn't be detected
|
|
const result = detectVideoProtocol('http://example.com/ts/video.mp4')
|
|
expect(result.protocol).toBe('native')
|
|
})
|
|
})
|
|
|
|
describe('isHlsStream', () => {
|
|
it('should return true for HLS streams', () => {
|
|
expect(isHlsStream('http://example.com/stream.m3u8')).toBe(true)
|
|
})
|
|
|
|
it('should return false for IPTV .ts streams (they use mpegts.js)', () => {
|
|
expect(isHlsStream('http://favoritv65.xyz:8080/live/user/pass/98925.ts')).toBe(false)
|
|
})
|
|
|
|
it('should return false for non-HLS streams', () => {
|
|
expect(isHlsStream('http://example.com/video.mp4')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('isRtmpStream', () => {
|
|
it('should return true for RTMP streams', () => {
|
|
expect(isRtmpStream('rtmp://example.com/live/stream')).toBe(true)
|
|
})
|
|
|
|
it('should return true for FLV streams', () => {
|
|
expect(isRtmpStream('http://example.com/stream.flv')).toBe(true)
|
|
})
|
|
|
|
it('should return false for non-RTMP streams', () => {
|
|
expect(isRtmpStream('http://example.com/video.mp4')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('isLiveStream', () => {
|
|
it('should return true for IPTV streams', () => {
|
|
expect(isLiveStream('http://favoritv65.xyz:8080/live/user/pass/98925.ts')).toBe(true)
|
|
})
|
|
|
|
it('should return true for live HLS streams', () => {
|
|
expect(isLiveStream('http://example.com/live/stream.m3u8')).toBe(true)
|
|
})
|
|
|
|
it('should return true for RTMP streams', () => {
|
|
expect(isLiveStream('rtmp://example.com/live/stream')).toBe(true)
|
|
})
|
|
|
|
it('should return false for MP4 files', () => {
|
|
expect(isLiveStream('http://example.com/video.mp4')).toBe(false)
|
|
})
|
|
})
|
|
})
|