Skip to content

Instantly share code, notes, and snippets.

@ilyabrin
Forked from emad-elsaid/share-screen.rb
Created April 5, 2014 12:24
Show Gist options
  • Save ilyabrin/9991323 to your computer and use it in GitHub Desktop.
Save ilyabrin/9991323 to your computer and use it in GitHub Desktop.
require 'socket'
require 'base64'
Refresh = 1 # seconds to refresh image on server
screen_capture_command = 'screencapture -C -x tmp.png'
image = ''
latest = Time.now
server = TCPServer.new 3000
loop do
Thread.start(server.accept) do |client|
if Time.now-latest>=Refresh
system(screen_capture_command)
latest = Time.now
File.open('tmp.png', 'rb') do |file|
image = 'data:image/png;base64,'+Base64.encode64(file.read)
end
end
client.puts '<html><head>'+
"<script>setTimeout(function(){document.location.reload();},#{Refresh*1000});</script>"+
'</head><body style="padding:0px;margin:0px;">'+
"<img src=\"#{image}\" style=\"height:100%;\"/>"+
'</body></html>'
client.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment