-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
99 lines (79 loc) · 2 KB
/
server.js
File metadata and controls
99 lines (79 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"use strict"
require('use-strict')
require('dotenv').load()
var http = require('http')
var spawn = require('child_process').spawn
var _ = require('lodash')
var express = require('express')
var app = express()
var server = http.Server(app)
module.exports = server
app.set('port', process.env.PORT)
app.get('/', function (req, res) {
var grab = spawn('ffmpeg', [
'-f', 'x11grab',
'-r', '25',
'-s', '1366x768',
'-i', ':0.0',
'-vframes', '1',
'-f', 'mjpeg',
'-'
])
grab.stdout.pipe(res)
})
if (process.env.VIDEO) {
app.get('/video', function (req, res) {
var grab = spawn('ffmpeg', [
'-f', 'x11grab',
'-r', '30',
'-s', '1366x768',
'-i', ':0.0',
'-f', 'matroska',
'-c:v', 'libx264',
'-tune', 'zerolatency',
'-preset', 'ultrafast',
'-'
])
req.on('close', function () {
grab.kill()
})
grab.stdout.pipe(res)
grab.stderr.pipe(process.stdout)
})
}
var curDesktop = '0'
function changescreenPrivate (id) {
curDesktop = id
// spawn('wmctrl', ['-s', id])
spawn('notify-send', ['Switch screen', id])
}
var changescreen = _.throttle(changescreenPrivate, 1000)
app.get('/desktop', function (req, res) {
res.send(curDesktop).end()
})
app.get('/switch/:id', function (req, res) {
changescreen(req.params.id)
res.json({ok: true})
})
server.listen(9999)
console.log('Listening on tcp...')
var dgram = require('dgram')
var udpSocket = dgram.createSocket('udp4')
var udpReply = new Buffer('asdf')
udpSocket.on('error', (err) => {
console.log(`udpSocket error:\n${err.stack}`)
udpSocket.close()
})
udpSocket.on('message', (msg, rinfo) => {
console.log(`udpSocket got: ${msg} from ${rinfo.address}:${rinfo.port}`)
udpSocket.send(udpReply, 0, udpReply.length, rinfo.port, rinfo.address, (err) => {
if (err) {
console.log(err)
}
})
})
udpSocket.on('listening', () => {
var address = udpSocket.address()
console.log(`udpSocket listening ${address.address}:${address.port}`)
})
udpSocket.bind(9997)