From 44778afc7d00f11002e99028f58e48941f78de88 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Wed, 25 May 2022 18:47:38 +0000 Subject: [PATCH] Development --- package.json | 8 ++-- public/assets/ErbosDraco.woff2 | Bin 0 -> 1540 bytes public/assets/app.css | 15 +++++++ public/assets/app.js | 51 ++++++++++++++++++++---- public/assets/favicon - Copy.ico | Bin 0 -> 22382 bytes public/assets/favicon.ico | Bin 22382 -> 9326 bytes server/ffmpeg/encoder.mjs | 65 +++++++++++++++++++++++++++++++ server/ffmpeg/monitor.mjs | 27 +++++++++++++ server/ffmpeg/startup.mjs | 12 ++++++ server/server.mjs | 43 ++++++++++++++++---- 10 files changed, 201 insertions(+), 20 deletions(-) create mode 100644 public/assets/ErbosDraco.woff2 create mode 100644 public/assets/favicon - Copy.ico create mode 100644 server/ffmpeg/encoder.mjs create mode 100644 server/ffmpeg/monitor.mjs create mode 100644 server/ffmpeg/startup.mjs diff --git a/package.json b/package.json index 82fd424..9351f30 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "description": "FFmpeg streaming service", "main": "index.js", "scripts": { - "dev:server": "node dev.mjs | bunyan", - "dev:server:watch": "npm-watch dev:server", + "server:bunyan": "node dev.mjs | bunyan", + "dev": "npm-watch server:bunyan", "test": "echo \"Error: no test specified\" && exit 1" }, "watch": { - "dev:server": { + "server:bunyan": { "patterns": [ "server/*" ], @@ -28,7 +28,7 @@ "service-core": "^3.0.0-beta.17" }, "dependencies": { - "flaska": "^1.2.3", + "flaska": "^1.2.4", "ws": "^8.6.0" } } diff --git a/public/assets/ErbosDraco.woff2 b/public/assets/ErbosDraco.woff2 new file mode 100644 index 0000000000000000000000000000000000000000..17fa31148fc2280a9e6b3fde78244bee426d2024 GIT binary patch literal 1540 zcmV+f2K)JUPew8T0RR9100smA3IG5A0BX27zZF5nl2D53hbtb!%WfNe!EB0s={Ew z^E8*enPl;20$Y?LOv~~BFgd_%0h1!RBXp+>Nnj&-LbKZd;Q8F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3eoqPZ`Wur|fgaIfKLIC)}QKNS>K<-kcfp qb#pACtvj>> 0, 1) : group.set(type, [])) + } + emit(type, payload) { + var group = this.all.get(type) + if (group) { group.forEach(x => x(payload)) } + if (group = this.all.get('*')) { + group.forEach(x => x(type, payload)) + } + } +} + class Animator { constructor() { this.running = null @@ -23,9 +45,10 @@ class Animator { const animator = new Animator() -class WSClient +class WSClient extends Mitt { constructor(url = 'ws://localhost:4040') { + super() this.url = url this.socket = null this.connected = false @@ -64,13 +87,16 @@ class WSClient this.connectingAt = null this.reconnectingAt = null this.connected = true - this.send({ msg: 'Hello Server!' }) + // this.send('onopen', { msg: 'Hello Server!' }) m.redraw() } - send(payload) { + send(type, payload) { if (!this.connected) return - this.socket.send(JSON.stringify(payload)) + this.socket.send(JSON.stringify({ + type: type, + payload: payload, + })) } onerror() { @@ -102,16 +128,22 @@ class WSClient onmessage(event) { try { let data = JSON.parse(event.data) - console.log('got message', data) + this.emit(data.type, data.payload) } catch (err) { console.error(err) } } } const client = new WSClient() +let encodingStatus = {} + +client.on('status', function(newStatus) { + encodingStatus = newStatus + m.redraw() +}) + class Header { view(vnode) { - console.log(client.connecting) return [ m('h1', 'Fíladelfíu streymi'), m('div.status.green', { hidden: true }, 'No errors'), @@ -125,7 +157,9 @@ class Header { : this.viewWaitingCircle(), ]), m('span', 'Live:'), - m('div.led'), + m('div.led', { + class: encodingStatus.encoding ? 'led-green' : '', + }), ] } viewConnectingBar() { @@ -233,7 +267,8 @@ class Nav { class Status { view(vnode) { return [ - m('span', 'Hello world') + m('div.text', 'Some text here'), + m('span', 'Hello world'), ] } } diff --git a/public/assets/favicon - Copy.ico b/public/assets/favicon - Copy.ico new file mode 100644 index 0000000000000000000000000000000000000000..7823b8b6ac6e20cae31b6795602b6a06ca00d780 GIT binary patch literal 22382 zcmeHPX>b%p6dp?a?;rp3lPav@6cH3x!9YQwKnRx*As0lHLnYi01dEbW5kUom;sFQ< zC>jq6h#XoFZU{%X_PUJ-Fd!mW_!~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x z0kQuGi8Ap2GUt`AlLi%rCFShDC(hf*bz8;F?Ut__ z6aOXlp+wuiUEx>Zqdcf1T|xVbmiYAaShhf1{AV6*{IhaHk$z)8U@zRT_WS0dnlo%N z4=d*xHZl7Fheq|#j+vj^WXAu_FpV(3qkqMDHyJzPIRA!sP2^eqK|r>x^?k}@#{cDq zhMkAC-|Xir^YGgi!xn)5yOe$o`;?4d12@Sy{!8~8?>oPQ&q_+zWSlgAe2pz2eB(vl z6Qv%XF*f}Fd%srHX%#l~`iJwbI9GwTFMKy*7e?Wh+i`){G34F!Mf5y@F@f}*+r6G8 zQv)aX9m8k!{`=;D*zf+BS7d$WxWJFS74yA#*C>NF%J$ESxyHPPxe>nh@#@&{sj*I6 zI2*lA2>hr&mcX`*$3d(%OdM?Ne-&>s&h^I1YrcmvSl_URChlR~hh4Ltaf!58;iMtf z`qwS@>w90ABTb^+;WGiuuLk~4A9WMX@|f2T`8t;VB)%v1Yj4U}t>Q_HF_AH(pZ^>5 zG+na7jVQf0a zG|B^JV7GrZ12zLT12zLT12zLT12zLT12zMx!$4jCAJ9 { + this.emit('stdout', data.toString()) + }) + this.processor.stderr.on('data', (data) => { + this.emit('stderr', data.toString()) + }) + + this.processor.on('error', (err) => { + this.processor = null + this.encoding = false + this.emit('error', err) + this.emit('status', this.status()) + }) + this.processor.on('exit', (code) => { + this.processor = null + this.encoding = false + this.emit('exit', { code: code }) + this.emit('status', this.status()) + }) + } + + stop() { + if(os.platform() === 'win32'){ + try { + execSync('taskkill /pid ' + this.processor.pid + ' /T /F') + } catch {} + } else { + this.processor.kill(); + } + this.encoding = false + this.processor = null + } + + status() { + return { + encoding: this.encoding, + } + } +} \ No newline at end of file diff --git a/server/ffmpeg/monitor.mjs b/server/ffmpeg/monitor.mjs new file mode 100644 index 0000000..3544561 --- /dev/null +++ b/server/ffmpeg/monitor.mjs @@ -0,0 +1,27 @@ +import { EventEmitter } from 'events' + +export default class Monitor extends EventEmitter { + constructor(wss, db, encoder, opts = {}) { + super() + this.wss = wss + this.db = db + this.encoder = encoder + this.encoder.on('stdout', (data) => { + console.log('stdout', { data }) + }) + this.encoder.on('stderr', (data) => { + console.log('stderr', { data }) + }) + this.encoder.on('status', (status) => { + this.emit('status', status) + }) + } + + start() { + this.encoder.start() + } + + status() { + return this.encoder.status() + } +} \ No newline at end of file diff --git a/server/ffmpeg/startup.mjs b/server/ffmpeg/startup.mjs new file mode 100644 index 0000000..52e587c --- /dev/null +++ b/server/ffmpeg/startup.mjs @@ -0,0 +1,12 @@ +import Encoder from './encoder.mjs' + +export function startup(core) { + core.db.data.ffmpeg = core.db.data.ffmpeg || {} + core.db.data.ffmpeg.program = 'ffmpeg.exe' + core.db.data.ffmpeg.options = ['--help'] + core.db.write() + return new Encoder({ + program: core.db.data.ffmpeg.program, + options: core.db.data.ffmpeg.options, + }) +} \ No newline at end of file diff --git a/server/server.mjs b/server/server.mjs index 37381fd..1b59c90 100644 --- a/server/server.mjs +++ b/server/server.mjs @@ -1,6 +1,9 @@ +import crypto from 'crypto' import { Flaska, QueryHandler } from 'flaska' import { WebSocket, WebSocketServer } from 'ws' +import { startup } from './ffmpeg/startup.mjs' +import Monitor from './ffmpeg/monitor.mjs' import ServeHandler from './serve.mjs' export function run(http, port, core) { @@ -46,12 +49,34 @@ export function run(http, port, core) { const wss = new WebSocketServer({ server: flaska.server }) + const encoder = startup(core) + const monitor = new Monitor(wss, core.db, encoder) + monitor.start() + + monitor.on('status', (status) => { + wss.clients.forEach(function each(client) { + if (!client.readyState === WebSocket.OPEN) { + console.log('closed', client) + } + client.sendevent('status', status); + }) + }) + wss.on('connection', function(ws) { - console.log('new connection') + ws.id = crypto.randomBytes(6).toString('base64') ws.isAlive = true + core.log.info({ id: ws.id, ip: ws._socket.remoteAddress }, 'New connection') ws.on('pong', function() { ws.isAlive = true }) + ws.sendevent = function(type, data) { + ws.send(JSON.stringify({ + type: type, + payload: data, + })) + } + + ws.sendevent('status', monitor.status()) ws.on('message', function message(data, isBinary) { if (isBinary) { @@ -64,19 +89,20 @@ export function run(http, port, core) { core.log.error(err) return } - console.log('got', payload) - wss.clients.forEach(function each(client) { + if (!payload.type || typeof(payload.type) !== 'string') { + core.log.error(new Error('Got payload but it was missing type: ' + data.toString())) + return + } + console.log('got', payload.type, payload.payload) + /*wss.clients.forEach(function each(client) { if (client.readyState === WebSocket.OPEN) { client.send(JSON.stringify(payload)); } - }) + })*/ }) }) const interval = setInterval(function() { - if (wss.clients.length > 0) { - core.log.info('Connected clients: ' + wss.clients.length) - } wss.clients.forEach(function(ws) { if (ws.isAlive === false) { return ws.terminate() @@ -85,9 +111,10 @@ export function run(http, port, core) { ws.isAlive = false ws.ping() }) - }, 5000) + }, 15000) wss.on('close', function() { + console.log('closing') clearInterval(interval) }) })