Update hello world

This commit is contained in:
Chocobozzz 2022-10-11 11:25:37 +02:00
parent b68f86adeb
commit dcccf3c2f2
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 84 additions and 0 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -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 () {

View File

@ -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": {}
}
}
}

View File

@ -78,5 +78,8 @@
],
"translations": {
"fr": "./languages/fr.json"
},
"dependencies": {
"ws": "^8.9.0"
}
}