Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cast plugin #72

Merged
merged 18 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ The player exposes some custom CSS properties, locally scopped under the `.v-vli
| `--vlite-controlBarBackground` | `linear-gradient(to top, #000 -50%, transparent)` | Control bar background |
| `--vlite-controlsColor` | `#fff\|#000` | Controls color (video\|audio) |
| `--vlite-controlsOpacity` | `0.9` | Controls opacity |
| `--vlite-controlsIconWidth` | `28px` | Controls icon width |
| `--vlite-controlsIconHeight` | `28px` | Controls icon height |
| `--vlite-progressBarHeight` | `5px` | Progress bar height |
| `--vlite-progressBarBackground` | `rgba(0 0 0 / 25%)` | Progress bar background |

Expand Down
6 changes: 4 additions & 2 deletions config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = {
plugins: ['prettier'],

rules: {
indent: ['error', 'tab', { ignoredNodes: ['TemplateLiteral *'] }],
indent: ['error', 'tab', { ignoredNodes: ['TemplateLiteral *'], SwitchCase: 1 }],
'no-tabs': 0,
'space-before-function-paren': [
'error',
Expand All @@ -31,6 +31,8 @@ module.exports = {
globals: {
document: false,
navigator: false,
window: false
window: false,
chrome: false,
cast: false
}
}
15 changes: 13 additions & 2 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ const plugins = [
entrykey: 'plugins/pip',
library: `${libraryName}Pip`,
path: './src/plugins/pip/config'
},
{
entrykey: 'plugins/cast',
library: `${libraryName}Cast`,
path: './src/plugins/cast/config'
}
]

Expand All @@ -69,7 +74,8 @@ const generator = ({ entry, library = false, isProduction }) => {
export: 'default'
}
}
return {

const config = {
watch: !isProduction,
entry,
watchOptions: {
Expand Down Expand Up @@ -136,7 +142,6 @@ const generator = ({ entry, library = false, isProduction }) => {
},
context: appDirectory,
plugins: [
new webpack.ProgressPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[name].css'
Expand Down Expand Up @@ -180,6 +185,12 @@ const generator = ({ entry, library = false, isProduction }) => {
splitChunks: false
}
}

if (!isProduction) {
config.plugins.push(new webpack.ProgressPlugin())
}

return config
}

module.exports = (env, argv) => {
Expand Down
13 changes: 12 additions & 1 deletion examples/html5/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import '../../dist/vlite.css'
import '../../dist/plugins/subtitle.css'
import '../../dist/plugins/cast.css'
import Vlitejs from '../../dist/vlite.js'
import VlitejsSubtitle from '../../dist/plugins/subtitle.js'
import VlitejsPip from '../../dist/plugins/pip.js'
import VlitejsCast from '../../dist/plugins/cast.js'

Vlitejs.registerPlugin('subtitle', VlitejsSubtitle)
Vlitejs.registerPlugin('pip', VlitejsPip)
Vlitejs.registerPlugin('cast', VlitejsCast, {
textTrackStyle: {
backgroundColor: '#21212190'
},
metadata: {
title: 'The Jungle Book',
subtitle: 'Walt Disney Animation Studios'
}
})

/* eslint-disable no-unused-vars */
const vlite = new Vlitejs('#player', {
Expand All @@ -24,7 +35,7 @@ const vlite = new Vlitejs('#player', {
muted: false,
autoHide: true
},
plugins: ['subtitle', 'pip'],
plugins: ['subtitle', 'pip', 'cast'],
onReady: function (player) {
console.log(player)

Expand Down
1 change: 1 addition & 0 deletions examples/html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<video crossorigin id="player" class="vlite-js" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-video-html5.mp4">
<track label="English" kind="subtitles" srclang="en" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-video-html5-subtitle-en.vtt" default />
<track label="French" kind="subtitles" srclang="fr" src="https://yoriiis.github.io/cdn/static/vlitejs/demo-video-html5-subtitle-fr.vtt" />
</video>
</body>
</html>
14 changes: 11 additions & 3 deletions examples/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const resolveApp = (relativePath) => path.resolve(appDirectory, relativePath)
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production'

return {
const config = {
entry: {
html5: `${resolveApp('examples/html5/config.js')}`,
audio: `${resolveApp('examples/audio/config.js')}`,
Expand Down Expand Up @@ -69,11 +69,13 @@ module.exports = (env, argv) => {
historyApiFallback: true,
port: 3000,
compress: true,
hot: true
hot: true,
host: '0.0.0.0',
https: true,
open: ['/html5']
},
context: appDirectory,
plugins: [
new webpack.ProgressPlugin(),
new MiniCssExtractPlugin({
filename: 'styles/[name].css',
chunkFilename: 'styles/[name].css'
Expand Down Expand Up @@ -152,4 +154,10 @@ module.exports = (env, argv) => {
splitChunks: false
}
}

if (!isProduction) {
config.plugins.push(new webpack.ProgressPlugin())
}

return config
}
77 changes: 77 additions & 0 deletions src/plugins/cast/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Plugin: Cast

Supports for Google Cast API.

## Overview

| <!-- --> | <!-- --> |
| ----------------- | ----------------------------------- |
| Name | `cast` |
| Global name&sup1; | `window.VlitejsCast` |
| Path | `vlitejs/dist/plugins/cast` |
| Entry point | `vlitejs/dist/plugins/cast/cast.js` |
| Stylesheet | - |
| Provider&sup2; | `'html5'` |
| Media type&sup3; | `'video'` |

- _&sup1; Useful only if `vLitejs` is included with a `<script>` tag (see [CDN](../../../README.md#CDN) section)._
- _&sup2;Providers: `html5|youtube|vimeo`_
- _&sup3;Media type: `video|audio`_

## Usage

### HTML

```html
<video id="player" class="vlite-js" src="<path_to_video_mp4>"></video>
```

### JavaScript

```js
import 'vlitejs/dist/vlite.css';
import 'vlitejs/dist/plugins/cast.css';
import Vlitejs from 'vlitejs';
import VlitejsCast from 'vlitejs/dist/plugins/cast';

Vlitejs.registerPlugin('cast', VlitejsCast);

new Vlitejs('#player', {
plugins: ['cast']
});
```

### Configuration

The plugin allows customization with an optional object as the third parameter of the `registerPlugin` function.

#### Subtitle

Describes style information for a text subtitle.

```js
Vlitejs.registerPlugin('cast', VlitejsCast, {
textTrackStyle: {
backgroundColor: '#21212190'
}
});
```

See the [TextTrackStyle](https://developers.google.com/cast/docs/reference/web_sender/chrome.cast.media.TextTrackStyle) reference for available fields.

#### Metadata

Describes media metadata description.

```js
Vlitejs.registerPlugin('cast', VlitejsCast, {
metadata: {
title: 'The Jungle Book',
subtitle: 'Walt Disney Animation Studios'
}
});
```

> The `images` field automatically displays the poster available in the [Vlitejs options](../../../README.md#Options).

See the [Metadata](https://developers.google.com/cast/docs/reference/web_sender/chrome.cast.media.GenericMediaMetadata) reference for available fields.
7 changes: 7 additions & 0 deletions src/plugins/cast/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// import CSS
import './css/cast.css'

// import JS
import cast from './js/cast'

export default cast
36 changes: 36 additions & 0 deletions src/plugins/cast/css/cast.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.v {
&-castButton {
&.v-active svg {
fill: var(--vlite-colorPrimary);
}
}

&-deviceName {
display: none;
position: absolute;
top: 0;
right: 0;
color: #fff;
width: auto;
padding: 10px;
font-size: 12px;
line-height: 12px;
pointer-events: none;
}

&-remote {
.v-pipButton,
.v-fullscreenButton {
display: none;
}

.vlite-js,
.v-captions {
display: none;
}

.v-deviceName {
display: block;
}
}
}
Loading