ActivityPub-federated video streaming platform using P2P directly in your web browser
Add embed api build
Chocobozzz03d641a0d7f9
diff --git a/client/src/standalone/player/.npmignore b/client/src/standalone/player/.npmignorenew file mode 100644index 0000000000..870b6315b1--- /dev/null+++ b/client/src/standalone/player/.npmignore@@ -0,0 +1,3 @@+tsconfig.json+*.ts+webpack.config.tsdiff --git a/client/src/standalone/player/package.json b/client/src/standalone/player/package.jsonindex b056de718f..591c3ee3d9 100644--- a/client/src/standalone/player/package.json+++ b/client/src/standalone/player/package.json@@ -1,6 +1,7 @@{"name": "@peertube/embed-api",- "version": "1.0.0",+ "private": false,+ "version": "0.0.1","description": "API to communicate with the PeerTube player embed","scripts": {"test": "echo \"Error: no test specified\" && exit 1"@@ -13,11 +14,15 @@"peertube","embed"],- "main": "./player.ts",+ "main": "./dist/player.js",+ "types": "./dist/player.d.ts","author": "Chocobozzz","license": "AGPL-3.0","bugs": {"url": "https://github.com/Chocobozzz/PeerTube/issues"},- "homepage": "https://github.com/Chocobozzz/PeerTube#readme"+ "homepage": "https://github.com/Chocobozzz/PeerTube#readme",+ "dependencies": {+ "jschannel": "^1.0.2"+ }}diff --git a/client/src/standalone/player/player.ts b/client/src/standalone/player/player.tsindex f33539134c..71c4129507 100644--- a/client/src/standalone/player/player.ts+++ b/client/src/standalone/player/player.ts@@ -192,4 +192,4 @@ export class PeerTubePlayer {}// put it on the window as well as the export-window[ 'PeerTubePlayer' ] = PeerTubePlayer+(window[ 'PeerTubePlayer' ] as any) = PeerTubePlayerdiff --git a/client/src/standalone/player/tsconfig.json b/client/src/standalone/player/tsconfig.jsonnew file mode 100644index 0000000000..eecc63dfb2--- /dev/null+++ b/client/src/standalone/player/tsconfig.json@@ -0,0 +1,19 @@+{+ "compilerOptions": {+ "module": "commonjs",+ "removeComments": true,+ "sourceMap": false,+ "typeRoots": [+ "../../../node_modules/@types"+ ],+ "outDir": "./dist",+ "declaration": true,+ "target": "es5",+ "types": [],+ "lib": [+ "es2018",+ "dom"+ ]+ },+ "files": [ "./player.ts" ]+}diff --git a/client/src/standalone/player/webpack.config.js b/client/src/standalone/player/webpack.config.jsnew file mode 100644index 0000000000..48d350edfc--- /dev/null+++ b/client/src/standalone/player/webpack.config.js@@ -0,0 +1,12 @@+const path = require('path')++module.exports = [+ {+ mode: 'production',+ entry: './dist/player.js',+ output: {+ filename: 'player.min.js',+ path: path.resolve(__dirname, 'build')+ }+ }+]diff --git a/package.json b/package.jsonindex acc4b7e1f3..d488415170 100644--- a/package.json+++ b/package.json@@ -46,7 +46,6 @@"dev:embed": "scripty","dev:client": "scripty","dev:cli": "scripty",- "dev:embed": "scripty","start": "node dist/server","start:server": "node dist/server --no-client","update-host": "node ./dist/scripts/update-host.js",@@ -73,6 +72,7 @@"mocha": "mocha","ci": "scripty","release": "scripty",+ "release-embed-api": "scripty","nightly": "scripty","client-report": "scripty"},diff --git a/scripts/build/client.sh b/scripts/build/client.shindex fd91906600..d95bb95745 100755--- a/scripts/build/client.sh+++ b/scripts/build/client.sh@@ -62,7 +62,7 @@ if [ -z ${1+x} ] || [ "$1" != "--light" ]; thendonefi-npm run build:embed+cd ../ && npm run build:embed && cd client/# Copy runtime localescp -r "./src/locale" "./dist/locale"diff --git a/scripts/build/embed.sh b/scripts/build/embed.shindex ea5e7d57dc..47e195d962 100755--- a/scripts/build/embed.sh+++ b/scripts/build/embed.sh@@ -2,4 +2,6 @@set -eu+cd client+NODE_ENV=production npm run webpack -- --config webpack/webpack.video-embed.js --mode production --json > "./dist/embed-stats.json"diff --git a/scripts/dev/embed.sh b/scripts/dev/embed.shold mode 100644new mode 100755diff --git a/scripts/release-embed-api.sh b/scripts/release-embed-api.shnew file mode 100755index 0000000000..ae76a65f5a--- /dev/null+++ b/scripts/release-embed-api.sh@@ -0,0 +1,11 @@+#!/bin/sh++set -eu++cd client/src/standalone/player++rm -rf dist build && tsc -p . && ../../../node_modules/.bin/webpack --config ./webpack.config.js++npm publish --access public++rm -rf dist build node_modulesdiff --git a/support/doc/api/embeds.md b/support/doc/api/embeds.mdindex c2317a0309..ca480006d9 100644--- a/support/doc/api/embeds.md+++ b/support/doc/api/embeds.md@@ -21,6 +21,24 @@ Now just use the `PeerTubePlayer` class exported by the module:```typescriptimport { PeerTubePlayer } from '@peertube/embed-api'+...+```++Or use the minified build from NPM CDN in your HTML file:++```+<script src="https://unpkg.com/@peertube/[email protected]/build/player.min.js"></script>++<script>+ const PeerTubePlayer = window['PeerTubePlayer']++ ...+</script>+```++Then you can instantiate the player:++```typescriptlet player = new PeerTubePlayer(document.querySelector('iframe'))await player.ready // wait for the player to be ready@@ -56,7 +74,7 @@ Get the available resolutions. A `PeerTubeResolution` looks like:{"id": 3,"label": "720p",- "src": "//src-url-here",+ "height": "720","active": true}```@@ -87,6 +105,7 @@ Set the playback volume. Value should be between `0` and `1`.## `getVolume(): Promise<number>`Get the playback volume. Returns a value between `0` and `1`.+# EventsYou can subscribe to events by using `addEventListener()`. See above for details.