diff --git a/examples/standalone/main.ts b/examples/standalone/main.ts index 6f8a7989..77df0551 100644 --- a/examples/standalone/main.ts +++ b/examples/standalone/main.ts @@ -23,8 +23,6 @@ interface Ctx { playlist: Playlist } -const initialIndex = 0 - const POSTER = `https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/poster.png` const DANMAKU = `https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/danmaku.xml` const THUMB = `https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/thumbnails.jpg` @@ -34,281 +32,292 @@ const SUPER_DANMAKU = `https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/天 const FLV = `https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/weathering-with-you.flv` const MP4 = `https://cdn.jsdelivr.net/gh/shiyiya/QI-ABSL@master/o/君の名は.mp4` -const player = Player.make('#player', { - // muted: true, - volume: 0.5, - // isLive: true, - // autoplay: true, - // preload: 'none', - source: { - // magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent - src: '', - poster: POSTER, - title: '君の名は' - }, - // videoAttr: { crossorigin: 'anonymous' }, // screenshot - lang: 'en' - // isNativeUI: () => true -}) - .use([ - ui({ - theme: { - watermark: { - src: vercel, - style: { - position: 'absolute', - top: '10px', - right: '10px', - width: '200px', - height: 'auto' - }, - attrs: { - class: 'watermark', - crossOrigin: 'anonymous' - } - }, - primaryColor: '#6668ab', - progress: {}, - controller: { - setting: 'auto', - display: 'always', - coverButton: true, - displayBehavior: 'hover', - header: { back: 'always' }, - slideToSeek: 'always' - } - }, - // autoFocus: true, - keyboard: { global: true }, - screenshot: true, - settings: [ - 'loop', - { - icon: '', - name: `Offset`, - type: 'slider', - default: 2, - min: -5, - max: 5, - onChange(value) { - player.context.ui.subtitle.changeOffset(value) - } - }, - { - icon: '', - name: `Power By OPlayer`, - onChange() { - alert('i love u') - } - }, - { - icon: '', - name: `Power By OPlayer`, - onChange(value) { - alert('i love u' + value) - }, - children: [ - { - name: 'children 1', - value: '1' - }, - { - name: 'children 2', - value: '2' - } - ] - } - ], - pictureInPicture: true, - // showControls: 'played', - highlight: { color: 'pink' }, - subtitle: { background: true }, - icons: { - progressIndicator: ` - - - - ` - } - }), - torrent({ - library: 'https://cdn.jsdelivr.net/npm/webtorrent@0.98.18/webtorrent.min.js' - }), - hls({ forceHLS: true }), - dash(), - mpegts(), - new Danmaku({ - enable: true - // displaySender: true, - // source: DANMAKU //SUPER_DANMAKU - }), - new Playlist({ - initialIndex: 0, - sources: [ - { - title: 'DASH DRM', - id: 'dash-drm' - }, - { - title: 'Hls DRM', - id: 'hls-drm' - }, - { - title: 'hls - muti quality & subtitle & audio', - src: 'https://storage.googleapis.com/shaka-demo-assets/angel-one-hls/hls.m3u8' - // danmaku: SUPER_DANMAKU - }, - { - title: 'dash - muti quality & subtitle & audio', - src: 'https://storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd' - }, - { - title: 'HLS with SRT subtitle', - src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8', - poster: 'https://api.imlazy.ink/img?id19', - subtitles: [ - { - name: 'Default', - src: SRT, - offset: 2 - } - ], - duration: '10:34' - }, - { - title: '君の名は - MP4', - poster: POSTER, - src: MP4, - duration: '01:32', - danmaku: DANMAKU, - thumbnails: { - src: THUMB, - number: 100 - }, - subtitles: [ - { - name: 'ass', - type: 'ass', - src: `https://web.opendrive.com/api/v1/download/file.json/MjBfMzA2MTA2OThf?temp_key=%EF%BF%BD%11%2Bj*%EF%BF%BD%EF%BF%BD%EF%BF%BDC%EF%BF%BDD%EF%BF%BD%EF%BF%BD%EF%BF%BDn%EF%BF%BDm%01%EF%BF%BD%D6%B6%D1%86%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%06%EF%BF%BD%EF%BF%BD%EF%BF%BDm%06%EF%BF%BD%EF%BF%BDv%EF%BF%BD%27%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BDz6%D1%8B%EF%BF%BD%7Bm0%EF%BF%BDm%0C%EF%BF%BDv%EF%BF%BD%EF%BF%BDM%EF%BF%BD%EF%BF%BD%5D%EF%BF%BD%EF%BF%BD%1E%EF%BF%BD%D2%9EC%EF%BF%BD%13.%EF%BF%BD%D8%A9%EF%BF%BD%EF%BF%BD%EF%BF%BDJ%EF%BF%BD%EF%BF%BD%EF%BF%BD%5E%EF%BF%BD%3Bki%EF%BF%BD9%EF%BF%BD%EF%BF%BD%DA%B2&inline=1` //'https://mentoor-st.s3.ir-thr-at1.arvanstorage.ir/media/courses/videos/a220374676eb40e4/001f4770a44497047661e446/subtitle/001f4770a44497047661e446_subtitle.srt', //SRT, - }, - { - name: 'Default', - default: true, - src: SRT, //'https://mentoor-st.s3.ir-thr-at1.arvanstorage.ir/media/courses/videos/a220374676eb40e4/001f4770a44497047661e446/subtitle/001f4770a44497047661e446_subtitle.srt', //SRT, - offset: 2 - }, - { - name: 'Japan', - src: JPSRT, - offset: 2 - } - ], - highlights: highlight - }, - { - title: "Disney's Oceans - MP4", - src: 'https://vjs.zencdn.net/v/oceans.mp4', - poster: 'https://vjs.zencdn.net/v/oceans.png', - duration: '00:46' - }, - { - title: 'Big Buck Bunny - HLS', - src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8', - poster: 'https://d2zihajmogu5jn.cloudfront.net/big-buck-bunny/bbb.png', - duration: '10:34' - }, - { - title: 'Big Buck Bunny - DASH', - src: 'https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd', - poster: 'https://d2zihajmogu5jn.cloudfront.net/big-buck-bunny/bbb.png', - duration: '10:34' - }, - { - title: 'FLV', - src: FLV, - duration: '00:17' - }, - { - title: 'webtorrent - MP4 + subtitle + poster', - src: 'https://webtorrent.io/torrents/sintel.torrent', - // 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent', - poster: 'https://api.imlazy.ink/img?webtorrent' - } - ], - customFetcher(player, source) { - if (source.id === 'dash-drm') { - ;(player.context.dash as ReturnType).options.drm = { - 'com.widevine.alpha': { - serverURL: 'https://drm-widevine-licensing.axtest.net/AcquireLicense', - httpRequestHeaders: { - 'X-AxDRM-Message': - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.4lWwW46k-oWcah8oN18LPj5OLS5ZU-_AQv7fe0JhNjA' - }, - priority: 0 - } - } - return { - ...source, - src: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd' - } - } else if (source.id == 'hls-drm') { - ;(player.context.hls as ReturnType).options.config = { - ...player.context.hls.options.config, - emeEnabled: true, - drmSystems: { - 'com.widevine.alpha': { - licenseUrl: 'https://widevine-proxy.appspot.com/proxy' - } - }, - licenseXhrSetup(xhr) { - xhr.setRequestHeader('content-type', 'application/octet-stream') - xhr.setRequestHeader('Authorization', 'Bearer token') // or other headers - } - } - - return {} //TODO - } else { - ;(player.context.dash as ReturnType).options.drm = null - ;(player.context.hls as ReturnType).options.config.emeEnabled = false - } - return source - } - // m3uList: { - // sourceFormat(info) { - // const chunk = info.title.substring(3).split(' ') - // const titleWith = chunk.find((it) => it.includes('title')).split('=')[1] - // const posterWith = chunk.find((it) => it.includes('logo'))?.split('=')[1] - // return { - // src: info.uri, - // format: 'm3u8', - // title: titleWith.substring(1, titleWith.length), - // poster: posterWith?.substring(1, posterWith.length) - // } - // } - // }, - }), - new Chromecast() - ]) - .create() - function stopLoad() { player.loader?.destroy() const u8 = Uint8Array.from(emptyBuffer) player.$video.src = URL.createObjectURL(new Blob([u8.buffer])) } +let player: Player + render( html`

Oh-Player v${Player.version}

STAR ON GitHub | - SCRIPT DEMO + SCRIPT DEMO | + | +

`, document.getElementById('meta')! ) -//@ts-ignore -window.player = player +const init = () => { + player = Player.make('#player', { + // muted: true, + volume: 0.5, + // isLive: true, + // autoplay: true, + // preload: 'none', + source: { + // magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent + src: '', + poster: POSTER, + title: '君の名は' + }, + // videoAttr: { crossorigin: 'anonymous' }, // screenshot + lang: 'en', + languages: { + en: { + Play: '👏' + } + } + // isNativeUI: () => true + }) + .use([ + ui({ + theme: { + watermark: { + src: vercel, + style: { + position: 'absolute', + top: '10px', + right: '10px', + width: '200px', + height: 'auto' + }, + attrs: { + class: 'watermark', + crossOrigin: 'anonymous' + } + }, + primaryColor: '#6668ab', + progress: {}, + controller: { + setting: 'auto', + display: 'always', + coverButton: true, + displayBehavior: 'hover', + header: { back: 'always' }, + slideToSeek: 'always' + } + }, + // autoFocus: true, + keyboard: { global: true }, + screenshot: true, + settings: [ + 'loop', + { + icon: '', + name: `Offset`, + type: 'slider', + default: 2, + min: -5, + max: 5, + onChange(value) { + player.context.ui.subtitle.changeOffset(value) + } + }, + { + icon: '', + name: `Power By OPlayer`, + onChange() { + alert('i love u') + } + }, + { + icon: '', + name: `Power By OPlayer`, + onChange(value) { + alert('i love u' + value) + }, + children: [ + { + name: 'children 1', + value: '1' + }, + { + name: 'children 2', + value: '2' + } + ] + } + ], + pictureInPicture: true, + // showControls: 'played', + highlight: { color: 'pink' }, + subtitle: { background: true }, + icons: { + progressIndicator: ` + + + + `, + next: '👉' + } + }), + torrent({ + library: 'https://cdn.jsdelivr.net/npm/webtorrent@0.98.18/webtorrent.min.js' + }), + hls({ forceHLS: true }), + dash(), + mpegts(), + new Danmaku({ + enable: true + // displaySender: true, + // source: DANMAKU //SUPER_DANMAKU + }), + new Playlist({ + initialIndex: 0, + sources: [ + { + title: 'DASH DRM', + id: 'dash-drm' + }, + { + title: 'Hls DRM', + id: 'hls-drm' + }, + { + title: 'hls - muti quality & subtitle & audio', + src: 'https://storage.googleapis.com/shaka-demo-assets/angel-one-hls/hls.m3u8' + // danmaku: SUPER_DANMAKU + }, + { + title: 'dash - muti quality & subtitle & audio', + src: 'https://storage.googleapis.com/shaka-demo-assets/angel-one/dash.mpd' + }, + { + title: 'HLS with SRT subtitle', + src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8', + poster: 'https://api.imlazy.ink/img?id19', + subtitles: [ + { + name: 'Default', + src: SRT, + offset: 2 + } + ], + duration: '10:34' + }, + { + title: '君の名は - MP4', + poster: POSTER, + src: MP4, + duration: '01:32', + danmaku: DANMAKU, + thumbnails: { + src: THUMB, + number: 100 + }, + subtitles: [ + { + name: 'ass', + type: 'ass', + src: `https://web.opendrive.com/api/v1/download/file.json/MjBfMzA2MTA2OThf?temp_key=%EF%BF%BD%11%2Bj*%EF%BF%BD%EF%BF%BD%EF%BF%BDC%EF%BF%BDD%EF%BF%BD%EF%BF%BD%EF%BF%BDn%EF%BF%BDm%01%EF%BF%BD%D6%B6%D1%86%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%06%EF%BF%BD%EF%BF%BD%EF%BF%BDm%06%EF%BF%BD%EF%BF%BDv%EF%BF%BD%27%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BDz6%D1%8B%EF%BF%BD%7Bm0%EF%BF%BDm%0C%EF%BF%BDv%EF%BF%BD%EF%BF%BDM%EF%BF%BD%EF%BF%BD%5D%EF%BF%BD%EF%BF%BD%1E%EF%BF%BD%D2%9EC%EF%BF%BD%13.%EF%BF%BD%D8%A9%EF%BF%BD%EF%BF%BD%EF%BF%BDJ%EF%BF%BD%EF%BF%BD%EF%BF%BD%5E%EF%BF%BD%3Bki%EF%BF%BD9%EF%BF%BD%EF%BF%BD%DA%B2&inline=1` //'https://mentoor-st.s3.ir-thr-at1.arvanstorage.ir/media/courses/videos/a220374676eb40e4/001f4770a44497047661e446/subtitle/001f4770a44497047661e446_subtitle.srt', //SRT, + }, + { + name: 'Default', + default: true, + src: SRT, //'https://mentoor-st.s3.ir-thr-at1.arvanstorage.ir/media/courses/videos/a220374676eb40e4/001f4770a44497047661e446/subtitle/001f4770a44497047661e446_subtitle.srt', //SRT, + offset: 2 + }, + { + name: 'Japan', + src: JPSRT, + offset: 2 + } + ], + highlights: highlight + }, + { + title: "Disney's Oceans - MP4", + src: 'https://vjs.zencdn.net/v/oceans.mp4', + poster: 'https://vjs.zencdn.net/v/oceans.png', + duration: '00:46' + }, + { + title: 'Big Buck Bunny - HLS', + src: 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8', + poster: 'https://d2zihajmogu5jn.cloudfront.net/big-buck-bunny/bbb.png', + duration: '10:34' + }, + { + title: 'Big Buck Bunny - DASH', + src: 'https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd', + poster: 'https://d2zihajmogu5jn.cloudfront.net/big-buck-bunny/bbb.png', + duration: '10:34' + }, + { + title: 'FLV', + src: FLV, + duration: '00:17' + }, + { + title: 'webtorrent - MP4 + subtitle + poster', + src: 'https://webtorrent.io/torrents/sintel.torrent', + // 'magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10&dn=Sintel&tr=udp%3A%2F%2Fexplodie.org%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.empire-js.us%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&ws=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2F&xs=https%3A%2F%2Fwebtorrent.io%2Ftorrents%2Fsintel.torrent', + poster: 'https://api.imlazy.ink/img?webtorrent' + } + ], + customFetcher(player, source) { + if (source.id === 'dash-drm') { + ;(player.context.dash as ReturnType).options.drm = { + 'com.widevine.alpha': { + serverURL: 'https://drm-widevine-licensing.axtest.net/AcquireLicense', + httpRequestHeaders: { + 'X-AxDRM-Message': + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.4lWwW46k-oWcah8oN18LPj5OLS5ZU-_AQv7fe0JhNjA' + }, + priority: 0 + } + } + return { + ...source, + src: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd' + } + } else if (source.id == 'hls-drm') { + ;(player.context.hls as ReturnType).options.config = { + ...player.context.hls.options.config, + emeEnabled: true, + drmSystems: { + 'com.widevine.alpha': { + licenseUrl: 'https://widevine-proxy.appspot.com/proxy' + } + }, + licenseXhrSetup(xhr) { + xhr.setRequestHeader('content-type', 'application/octet-stream') + xhr.setRequestHeader('Authorization', 'Bearer token') // or other headers + } + } + + return {} //TODO + } else { + ;(player.context.dash as ReturnType).options.drm = null + ;(player.context.hls as ReturnType).options.config.emeEnabled = false + } + return source + } + // m3uList: { + // sourceFormat(info) { + // const chunk = info.title.substring(3).split(' ') + // const titleWith = chunk.find((it) => it.includes('title')).split('=')[1] + // const posterWith = chunk.find((it) => it.includes('logo'))?.split('=')[1] + // return { + // src: info.uri, + // format: 'm3u8', + // title: titleWith.substring(1, titleWith.length), + // poster: posterWith?.substring(1, posterWith.length) + // } + // } + // }, + }), + new Chromecast() + ]) + .create() +} + +init() diff --git a/examples/standalone/package-lock.json b/examples/standalone/package-lock.json index 761beeff..0065bb17 100644 --- a/examples/standalone/package-lock.json +++ b/examples/standalone/package-lock.json @@ -24,7 +24,7 @@ }, "../../packages/core": { "name": "@oplayer/core", - "version": "1.2.38-beta.1", + "version": "1.2.38-beta.2", "license": "MIT" }, "../../packages/danmaku": { @@ -32,7 +32,7 @@ "version": "1.2.25", "license": "MIT", "dependencies": { - "danmaku": "^2.0.7" + "danmaku": "2.0.7" }, "devDependencies": { "@oplayer/core": "workspace:*" @@ -43,7 +43,7 @@ }, "../../packages/dash": { "name": "@oplayer/dash", - "version": "1.2.26", + "version": "1.2.27-beta.1", "license": "MIT", "devDependencies": { "@oplayer/core": "workspace:*", @@ -56,11 +56,11 @@ }, "../../packages/hls": { "name": "@oplayer/hls", - "version": "1.2.27", + "version": "1.2.28-beta.1", "license": "MIT", "devDependencies": { "@oplayer/core": "workspace:*", - "hls.js": "^1.5.18" + "hls.js": "^1.5.20" }, "peerDependencies": { "@oplayer/core": ">=1.0.0", @@ -69,7 +69,7 @@ }, "../../packages/mpegts": { "name": "@oplayer/mpegts", - "version": "1.2.25", + "version": "1.2.26-beta.0", "license": "MIT", "devDependencies": { "@oplayer/core": "workspace:*", @@ -82,7 +82,7 @@ }, "../../packages/plugins": { "name": "@oplayer/plugins", - "version": "1.0.15-beta.0", + "version": "1.0.15-beta.3", "license": "MIT", "devDependencies": { "@oplayer/core": "workspace:*", @@ -116,7 +116,7 @@ }, "../../packages/ui": { "name": "@oplayer/ui", - "version": "1.3.4-beta.1", + "version": "1.3.4-beta.3", "license": "MIT", "devDependencies": { "@oplayer/core": "workspace:*" diff --git a/packages/core/src/i18n/index.ts b/packages/core/src/i18n/index.ts index 83910e1a..1a7329ef 100644 --- a/packages/core/src/i18n/index.ts +++ b/packages/core/src/i18n/index.ts @@ -1,8 +1,8 @@ import type { Lang } from '../types' import { mergeDeep } from '../utils' import CN from './zh-CN.json' -import FA from "./fa.json" -import PA from "./pa.json" +import FA from './fa.json' +import PA from './pa.json' export default class I18n { public lang: Lang @@ -14,11 +14,16 @@ export default class I18n { en: Object.keys(CN).reduce>( (previous, current) => ((previous[current] = current), previous), {} - ), + ) } - constructor(defaultLang: Lang) { + constructor(defaultLang: Lang, userLanguages?: Partial>) { this.lang = defaultLang === 'auto' ? (navigator.language as Lang) : defaultLang + + if (userLanguages) { + mergeDeep(this.languages, userLanguages) + } + if (!this.languages[this.lang]) { navigator.languages.some((lang) => { if (this.languages[lang as Lang]) { @@ -37,6 +42,7 @@ export default class I18n { return false }) } + if (!this.languages[this.lang]) this.lang = 'en' } diff --git a/packages/core/src/player.ts b/packages/core/src/player.ts index a32866b7..3a2e9caf 100644 --- a/packages/core/src/player.ts +++ b/packages/core/src/player.ts @@ -11,6 +11,7 @@ import type { PlayerListener, PlayerOptions, PlayerPlugin, + RequiredPartial, Source } from './types' @@ -28,13 +29,13 @@ const defaultOptions = { isLive: false, autopause: true, isNativeUI: () => isQQBrowser -} +} as const export class Player = Record> { static players: Player[] = [] container: HTMLElement - options: Required + options: RequiredPartial locales: I18n eventEmitter: EventEmitter @@ -62,7 +63,7 @@ export class Player = Record> { typeof options === 'string' ? { source: { src: options } } : options ) - this.locales = new I18n(this.options.lang) + this.locales = new I18n(this.options.lang, this.options.languages) this.eventEmitter = new EventEmitter() } diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 2727780b..cb52d573 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -57,6 +57,7 @@ export interface PlayerOptions { playsinline?: boolean preload?: 'auto' | 'metadata' | 'none' lang?: Lang + languages?: Partial> isLive?: boolean videoAttr?: Record isNativeUI?: () => boolean diff --git a/packages/danmaku/package.json b/packages/danmaku/package.json index 4632d58f..757d7d05 100644 --- a/packages/danmaku/package.json +++ b/packages/danmaku/package.json @@ -1,6 +1,6 @@ { "name": "@oplayer/danmaku", - "version": "1.2.25", + "version": "1.2.26-beta.0", "description": "Danmaku plugin for oplayer", "type": "module", "main": "./dist/index.es.js",