Skip to content

Commit

Permalink
refactor chromecast (#121)
Browse files Browse the repository at this point in the history
* refactor chromecast
  • Loading branch information
shiyiya authored Mar 26, 2024
1 parent f2bf8b0 commit ff492d2
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 214 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/compressed-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: setup node.js
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Install pnpm
uses: pnpm/[email protected]
with:
Expand All @@ -32,6 +37,7 @@ jobs:
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
Expand All @@ -44,4 +50,4 @@ jobs:
with:
build-script: 'build:packs'
repo-token: '${{ secrets.GIT_HUB_TOKEN }}'
pattern: './packages/*/{dist,compiled}/**/*.{js,d.ts}'
pattern: './packages/*/{dist,compiled}/**/*.{js}'
5 changes: 3 additions & 2 deletions examples/standalone/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import hls from '@oplayer/hls'
import mpegts from '@oplayer/mpegts'
import ui from '@oplayer/ui'
import torrent from '@oplayer/torrent'
import { PlaylistPlugin } from '@oplayer/plugins'
import { PlaylistPlugin, Chromecast } from '@oplayer/plugins'

import DANMAKU from '../../packages/docs/public/danmaku.xml'
import POSTER from '../../packages/docs/public/poster.png'
Expand Down Expand Up @@ -194,7 +194,8 @@ const player = Player.make<Ctx>('#player', {
// }
// }
// },
})
}),
new Chromecast()
])
.create()

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
"cross-env": "^7.0.3",
"jsdom": "^24.0.0",
"lint-staged": "^15.2.2",
"nx": "^18.1.2",
"nx": "^18.1.3",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"terser": "^5.29.2",
"tslib": "^2.6.2",
"typescript": "^5.4.3",
"vite": "^5.2.3",
"vite": "^5.2.6",
"vite-plugin-banner": "^0.7.1",
"vitest": "^1.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.69",
"@types/react": "^18.2.70",
"@types/react-dom": "^18.2.22",
"sass": "^1.72.0"
}
Expand Down
13 changes: 10 additions & 3 deletions packages/docs/public/ohls.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@
<script>
var hlsScriptCdn = 'https://cdn.jsdelivr.net/npm/@oplayer/hls@latest/dist/index.hls.js'
var danmakuScriptCdn = 'https://cdn.jsdelivr.net/npm/@oplayer/danmaku@latest/dist/index.min.js'
var playlistScriptCdn = 'https://cdn.jsdelivr.net/npm/@oplayer/plugins@latest/dist/playlist.min.js'
var playlistScriptCdn =
'https://cdn.jsdelivr.net/npm/@oplayer/[email protected]/dist/playlist.min.js'
var chromecastScriptCdn = 'https://cdn.jsdelivr.net/npm/@oplayer/plugins@latest/dist/chromecast.min.js'

var query = document.location.search.substring(1)
Expand Down Expand Up @@ -264,7 +265,11 @@
}

var player = OPlayer.make('#oplayer', {
source: { src: !playlist.length ? src : undefined, poster, title: title || 'Free HTML5 Player' },
source: {
src: /m3u8(#|\?|$)/.test(src) || /.mpd(#|\?|$)/i.test(src) ? undefined : src,
poster,
title: title || 'Free HTML5 Player'
},
playbackRate: localStorage.getItem('@oplayer/UserPreferences/speed') || 1,
volume: localStorage.getItem('@oplayer/UserPreferences/volume') || 1
})
Expand Down Expand Up @@ -326,7 +331,7 @@
[
chromecastScriptCdn,
() => {
player.applyPlugin(OChromecast)
player.applyPlugin(new OChromecast())
}
]
]
Expand Down Expand Up @@ -372,6 +377,8 @@
})

function bootstrap() {
if (!player.options.source.src && src) player.changeSource({ src, poster })

if (danmaku) {
loadScripts([danmakuScriptCdn]).then((p) => {
player.applyPlugin(ODanmaku({ source: danmaku }))
Expand Down
8 changes: 5 additions & 3 deletions packages/docs/src/pages/components/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import hls from '@oplayer/hls'
import dash from '@oplayer/dash'
import mpegts from '@oplayer/mpegts'
import style from './player.module.scss'
import { Chromecast } from '@oplayer/plugins'

const userPreferencesPlugin: PlayerPlugin = {
name: 'userPreferencesPlugin',
Expand Down Expand Up @@ -48,7 +49,8 @@ export default () => {
hls({ forceHLS: true }),
dash(),
mpegts(),
userPreferencesPlugin
userPreferencesPlugin,
new Chromecast()
])
.create()
.on(console.log)
Expand Down Expand Up @@ -87,8 +89,8 @@ export default () => {
</button>
</div>
<p className="tips">
Your streaming URL must be HTTPS-compatible, otherwise your stream may not play. Make sure
CORS is enabled on streaming server when using HLS and MPEG-DASH streams.
Your streaming URL must be HTTPS-compatible, otherwise your stream may not play. Make sure CORS is
enabled on streaming server when using HLS and MPEG-DASH streams.
</p>
<div
id="oplayer"
Expand Down
13 changes: 6 additions & 7 deletions packages/docs/src/pages/plugins/chromecast.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ npm i @oplayer/plugins
```

```js
import { chromecast } from '@oplayer/plugins'
import { Chromecast } from '@oplayer/plugins'

Player.make('#oplayer').use([new Chromecast()]).create()
```

```html
<!-- Chromecast -->
<script src="https://cdn.jsdelivr.net/npm/@oplayer/plugins@latest/dist/chromecast.min.js"></script>
```

### Chromecast

```js
Player.make('#oplayer').use([chromecast]).create()
<script>
Player.make('#oplayer').use([new OChromecast()]).create()
</script>
```
9 changes: 5 additions & 4 deletions packages/docs/src/pages/preview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dash from '@oplayer/dash'
import mpegts from '@oplayer/mpegts'
import ui from '@oplayer/ui'
import danmaku from '@oplayer/danmaku'
import { PlaylistPlugin, chromecast } from '@oplayer/plugins'
import { PlaylistPlugin, Chromecast } from '@oplayer/plugins'

<div className="nx-rounded-sm nx-overflow-hidden" style={{ maxWidth: '1024px', margin: '1.25rem auto' }}>
<Player
Expand All @@ -25,7 +25,7 @@ import { PlaylistPlugin, chromecast } from '@oplayer/plugins'
name: '',
position: 'top',
onClick() {
alert('你也喜欢我么?')
alert('miss u')
}
},
{
Expand All @@ -49,7 +49,7 @@ import { PlaylistPlugin, chromecast } from '@oplayer/plugins'
alert(`${value}`)
}
},
].filter(Boolean)
]
}),
hls({ forceHLS: true }),
dash(),
Expand All @@ -68,6 +68,7 @@ import { PlaylistPlugin, chromecast } from '@oplayer/plugins'
src: '/thumbnails.jpg',
number: 100
},
danmaku: '/danmaku.xml',
subtitles: [
{
name: 'Japanese',
Expand Down Expand Up @@ -117,7 +118,7 @@ import { PlaylistPlugin, chromecast } from '@oplayer/plugins'
}
]
}),
chromecast
new Chromecast()
].filter((it) => it?.apply)}

/>
Expand Down
8 changes: 6 additions & 2 deletions packages/plugins/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

## UnRelease

## 1.0.12-beta.0

- chromecast: refactor

## 1.0.11

- support danmaku
- playlist: support danmaku

## 1.0.11-alpha.1

- add error fallback for poster
- playlist: add error fallback for poster

## 1.0.10-beta.3

Expand Down
6 changes: 4 additions & 2 deletions packages/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ npm i @oplayer/plugins
```

```js
import { PlaylistPlugin, vttThumbnails, chromecast, ad } from '@oplayer/plugins'
import { PlaylistPlugin, Chromecast, ad, vttThumbnails } from '@oplayer/plugins'
```

```html
Expand Down Expand Up @@ -94,6 +94,8 @@ Player.make('#oplayer')

### Chromecast

Player.make('#oplayer').use([chromecast]).create()
```js
Player.make('#oplayer').use([new Chromecast()]).create()
```

### AD
5 changes: 2 additions & 3 deletions packages/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import chromecast from './src/chromecast'
import Chromecast from './src/chromecast'
import vttThumbnails from './src/vttThumbnails'
import PlaylistPlugin from './src/playlist'
import Hello from './src/hello'
import ad from './src/ad'

export { chromecast, vttThumbnails, ad, Hello, PlaylistPlugin }
export { Chromecast, vttThumbnails, ad, PlaylistPlugin }
2 changes: 1 addition & 1 deletion packages/plugins/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@oplayer/plugins",
"version": "1.0.11",
"version": "1.0.12-beta.0",
"author": "shiyiya",
"description": "oplayer's plugin",
"homepage": "https://github.com/shiyiya/oplayer",
Expand Down
Loading

0 comments on commit ff492d2

Please sign in to comment.