Created
October 1, 2019 22:44
-
-
Save HalfdanJ/32b7891aff8017a27dd36ba1f3b12130 to your computer and use it in GitHub Desktop.
A websocket server sending screenshot as base64 encoded blob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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