Add embed api build
authorChocobozzz <me@florianbigard.com>
Tue, 17 Dec 2019 15:17:22 +0000 (16:17 +0100)
committerChocobozzz <me@florianbigard.com>
Wed, 18 Dec 2019 09:14:25 +0000 (10:14 +0100)
client/src/standalone/player/.npmignore [new file with mode: 0644]
client/src/standalone/player/package.json
client/src/standalone/player/player.ts
client/src/standalone/player/tsconfig.json [new file with mode: 0644]
client/src/standalone/player/webpack.config.js [new file with mode: 0644]
package.json
scripts/build/client.sh
scripts/build/embed.sh
scripts/dev/embed.sh [changed mode: 0644->0755]
scripts/release-embed-api.sh [new file with mode: 0755]
support/doc/api/embeds.md

diff --git a/client/src/standalone/player/.npmignore b/client/src/standalone/player/.npmignore
new file mode 100644 (file)
index 0000000..870b631
--- /dev/null
@@ -0,0 +1,3 @@
+tsconfig.json
+*.ts
+webpack.config.ts
index b056de718f2632f90d0a820f67adb0bdf063e42d..591c3ee3d9fdd094cbb60fefae051d3ef08094b8 100644 (file)
@@ -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"
     "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"
+  }
 }
index f33539134c892f301cc4341e93511134737dc79c..71c41295076db65bdc1a8e36c1e97510deaa6007 100644 (file)
@@ -192,4 +192,4 @@ export class PeerTubePlayer {
 }
 
 // put it on the window as well as the export
-window[ 'PeerTubePlayer' ] = PeerTubePlayer
+(window[ 'PeerTubePlayer' ] as any) = PeerTubePlayer
diff --git a/client/src/standalone/player/tsconfig.json b/client/src/standalone/player/tsconfig.json
new file mode 100644 (file)
index 0000000..eecc63d
--- /dev/null
@@ -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.js
new file mode 100644 (file)
index 0000000..48d350e
--- /dev/null
@@ -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')
+    }
+  }
+]
index acc4b7e1f375d7c17039ba3fac94f47b0300f34c..d4884151704ba4c8409476cfab80d91ea7909a10 100644 (file)
@@ -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"
   },
index fd9190660023e01cb2e336629c4a493ad2ae64f2..d95bb95745974507eedad2e0761c4f7f99b99365 100755 (executable)
@@ -62,7 +62,7 @@ if [ -z ${1+x} ] || [ "$1" != "--light" ]; then
     done
 fi
 
-npm run build:embed
+cd ../ && npm run build:embed && cd client/
 
 # Copy runtime locales
 cp -r "./src/locale" "./dist/locale"
index ea5e7d57dce27460ab56472f4bc010244582cfbe..47e195d962f7440d2097524df9772e7e12c81a53 100755 (executable)
@@ -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"
old mode 100644 (file)
new mode 100755 (executable)
diff --git a/scripts/release-embed-api.sh b/scripts/release-embed-api.sh
new file mode 100755 (executable)
index 0000000..ae76a65
--- /dev/null
@@ -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_modules
index c2317a0309aec4daafd0b242ef49c397b8f01dee..ca480006d9c603ea13df5583c053454655a1ff95 100644 (file)
@@ -21,6 +21,24 @@ Now just use the `PeerTubePlayer` class exported by the module:
 ```typescript
 import { PeerTubePlayer } from '@peertube/embed-api'
 
+...
+```
+
+Or use the minified build from NPM CDN in your HTML file:
+
+```
+<script src="https://unpkg.com/@peertube/embed-api@0.0.1/build/player.min.js"></script>
+
+<script>
+  const PeerTubePlayer = window['PeerTubePlayer']
+
+  ...
+</script>
+```
+
+Then you can instantiate the player:
+
+```typescript
 let 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`.
+
 # Events
 
 You can subscribe to events by using `addEventListener()`. See above for details.