Created
February 2, 2017 11:16
-
-
Save alissonbrunosa/5ebe4256ba5915376423131011e3342b to your computer and use it in GitHub Desktop.
This file contains 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
require 'sinatra' | |
require 'securerandom' | |
module OS | |
class << self | |
def get | |
linux || mac || windows | |
end | |
private | |
def linux | |
return :linux if /linux/ =~ RUBY_PLATFORM | |
end | |
def mac | |
return :mac if /darwin/ =~ RUBY_PLATFORM | |
end | |
def windows | |
return :windows if /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM | |
end | |
end | |
end | |
COMMANDS = { | |
linux: "xxxxxxxx", | |
mac: "screencapture -x", | |
windows: "xxxxxxx" | |
} | |
set :server, :thin | |
set :bind, '0.0.0.0' | |
get '/' do | |
boundary = "shit" | |
response['Content-Type'] = "multipart/x-mixed-replace; boundary=#{boundary}" | |
stream(:keep_open) do |out| | |
loop do | |
name = SecureRandom.hex(10) | |
`#{COMMANDS[OS.get]} #{name}.jpeg` | |
out << "--#{boundary}\n" | |
out << "Content-type: image/jpeg\n\n" | |
out << File.open("#{name}.jpeg", 'rb') { |f| f.read } | |
# `rm #{name}.jpeg` | |
# sleep(0.5) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment