Skip to content

Instantly share code, notes, and snippets.

@HalfdanJ
Created October 1, 2019 22:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HalfdanJ/32b7891aff8017a27dd36ba1f3b12130 to your computer and use it in GitHub Desktop.
Save HalfdanJ/32b7891aff8017a27dd36ba1f3b12130 to your computer and use it in GitHub Desktop.
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