From dcccf3c2f20e697645d3c528bf0d86498a4c43b1 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Oct 2022 11:25:37 +0200 Subject: [PATCH] Update hello world --- .../client/common-client-plugin.js | 12 ++++++ .../client/video-watch-client-plugin.js | 2 + peertube-plugin-hello-world/main.js | 24 +++++++++++ peertube-plugin-hello-world/package-lock.json | 43 +++++++++++++++++++ peertube-plugin-hello-world/package.json | 3 ++ 5 files changed, 84 insertions(+) create mode 100644 peertube-plugin-hello-world/package-lock.json diff --git a/peertube-plugin-hello-world/client/common-client-plugin.js b/peertube-plugin-hello-world/client/common-client-plugin.js index 4337651..4faeedd 100644 --- a/peertube-plugin-hello-world/client/common-client-plugin.js +++ b/peertube-plugin-hello-world/client/common-client-plugin.js @@ -154,6 +154,18 @@ function register ({ registerHook, registerSettingsScript, registerClientRoute, rootEl.innerHTML = 'hello' } }) + + // WebSocket + + const baseScheme = window.location.protocol === 'https:' + ? 'wss:' + : 'ws:' + + const socket = new WebSocket(baseScheme + '//' + window.location.host + peertubeHelpers.getBaseWebSocketRoute() + '/toto'); + + socket.addEventListener('message', (event) => { + console.log(event.data) + }) } export { diff --git a/peertube-plugin-hello-world/client/video-watch-client-plugin.js b/peertube-plugin-hello-world/client/video-watch-client-plugin.js index 3257faa..d9a2988 100644 --- a/peertube-plugin-hello-world/client/video-watch-client-plugin.js +++ b/peertube-plugin-hello-world/client/video-watch-client-plugin.js @@ -66,6 +66,8 @@ function register ({ registerHook, peertubeHelpers }) { registerHook({ target: 'filter:internal.player.videojs.options.result', handler: (options) => { + console.log(options.plugins.p2pMediaLoader) + options.poster = '' return options } diff --git a/peertube-plugin-hello-world/main.js b/peertube-plugin-hello-world/main.js index 30b6695..3b9e429 100644 --- a/peertube-plugin-hello-world/main.js +++ b/peertube-plugin-hello-world/main.js @@ -1,6 +1,9 @@ +const WebSocketServer = require('ws').WebSocketServer + async function register ({ registerHook, getRouter, + registerWebSocketRoute, registerSetting, settingsManager, storageManager, @@ -163,6 +166,27 @@ async function register ({ } }) } + + // WebSocket + const wss = new WebSocketServer({ noServer: true }) + + wss.on('connection', function connection(ws) { + peertubeHelpers.logger.info('Websocket connected!') + + setInterval(() => { + ws.send('Websocket message sent by server'); + }, 1000) + }) + + registerWebSocketRoute({ + route: '/toto', + + handler: (request, socket, head) => { + wss.handleUpgrade(request, socket, head, ws => { + wss.emit('connection', ws, request) + }) + } + }) } async function unregister () { diff --git a/peertube-plugin-hello-world/package-lock.json b/peertube-plugin-hello-world/package-lock.json new file mode 100644 index 0000000..b6754a7 --- /dev/null +++ b/peertube-plugin-hello-world/package-lock.json @@ -0,0 +1,43 @@ +{ + "name": "peertube-plugin-hello-world", + "version": "0.0.20", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "peertube-plugin-hello-world", + "version": "0.0.20", + "dependencies": { + "ws": "^8.9.0" + } + }, + "node_modules/ws": { + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.9.0.tgz", + "integrity": "sha512-Ja7nszREasGaYUYCI2k4lCKIRTt+y7XuqVoHR44YpI49TtryyqbqvDMn5eqfW7e6HzTukDRIsXqzVHScqRcafg==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + }, + "dependencies": { + "ws": { + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.9.0.tgz", + "integrity": "sha512-Ja7nszREasGaYUYCI2k4lCKIRTt+y7XuqVoHR44YpI49TtryyqbqvDMn5eqfW7e6HzTukDRIsXqzVHScqRcafg==", + "requires": {} + } + } +} diff --git a/peertube-plugin-hello-world/package.json b/peertube-plugin-hello-world/package.json index 14462e1..b35f000 100644 --- a/peertube-plugin-hello-world/package.json +++ b/peertube-plugin-hello-world/package.json @@ -78,5 +78,8 @@ ], "translations": { "fr": "./languages/fr.json" + }, + "dependencies": { + "ws": "^8.9.0" } }