Skip to content

Instantly share code, notes, and snippets.

@NuriYuri
Created November 29, 2018 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NuriYuri/eac0c3ab3fe55eac7a2bfa4d0f1eb4b0 to your computer and use it in GitHub Desktop.
Save NuriYuri/eac0c3ab3fe55eac7a2bfa4d0f1eb4b0 to your computer and use it in GitHub Desktop.
Cast PSDK screen to a webbrowser
# Demo : https://www.youtube.com/watch?v=a3IF8Yu0BWM
require "webrick"
class ImageReturn < WEBrick::HTTPServlet::AbstractServlet
def do_GET request, response
response.status = 200
response['Content-Type'] = 'image/png'
response.body = $GraphicsImage.to_s
end
end
class BasePage < WEBrick::HTTPServlet::AbstractServlet
PAGE_RESPONSE = <<-EOF
<!doctype html>
<html>
<head>
<title>PSDK output</title>
</head>
<body>
<img id="test" src="http://127.0.0.1/image/0.png"/>
<script>
setInterval(function(){
document.getElementById("test").src = "http://127.0.0.1/image/" + Math.random() + ".png"
}, 500);
</script>
</html>
EOF
def do_GET request, response
response.status = 200
response['Content-Type'] = 'text/html'
response.body = PAGE_RESPONSE
end
end
Scheduler.add_proc(:on_update, :any, "Screenshot", 1000,
proc {
if Graphics.frame_count % 30 == 0
bmp = Graphics.snap_to_bitmap
$GraphicsImage = bmp.to_png
bmp.dispose
end
}
)
$web_server = WEBrick::HTTPServer.new
$web_server.mount '/pokemonsdk', BasePage
$web_server.mount '/image', ImageReturn
$web_thread = Thread.new { $web_server.start }
# require "Tests/test_image.rb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment