Sha256: 14618e2a31e2af99f051fa35a84baa4a42ac4c8ff40bbb5dc28fe4e3efeaa518
Contents?: true
Size: 647 Bytes
Versions: 1
Compression:
Stored size: 647 Bytes
Contents
require 'sinatra/base' require 'rack/handler/puma' require 'sinatra/hijacker' class App < Sinatra::Base register Sinatra::Hijacker get '/' do index_html end websocket '/ws' do ws.onmessage do |msg| ws.send_data "Hello, #{msg}" end end helpers do def index_html <<-EOS <html> <body> <script> var ws = new WebSocket('ws://#{env["HTTP_HOST"]}/ws'); ws.onmessage = function(msg){console.log(msg.data)}; ws.onopen = function(){ws.send("Minoritea")}; </script> </body> <html> EOS end end end Rack::Handler::Puma.run App if __FILE__ == $0
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sinatra-hijacker-0.0.2 | sample/sinatra.rb |