A websocket server sending screenshot as base64 encoded blob
// Requires ws and screenshot-desktop | |
const WebSocket = require('ws'); | |
const screenshot = require('screenshot-desktop') | |
const wss = new WebSocket.Server({ port: 8889 }); | |
wss.on('connection', function connection(ws) { | |
ws.on('message', function incoming(message) { | |
console.log('received: %s', message); | |
}); | |
ws.on('close', ()=>{ | |
clearInterval(interval); | |
console.log("disconnect") | |
}) | |
console.log("connect") | |
const interval = setInterval(()=>{ | |
screenshot({ | |
format: 'jpg' | |
}).then(img => { | |
ws.send(img); | |
}) | |
}, 500) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment