class Utopia::WebSocket::Connection
Constants
- READ_BUFFER_SIZE
Attributes
env[R]
url[R]
Public Class Methods
new(env, io)
click to toggle source
# File lib/utopia/websocket.rb, line 35 def initialize(env, io) @env = env @io = io scheme = Rack::Request.new(env).ssl? ? 'wss:' : 'ws:' @url = scheme + '//' + env['HTTP_HOST'] + env['REQUEST_URI'] @driver = ::WebSocket::Driver.rack(self) @running = false end
Public Instance Methods
read()
click to toggle source
# File lib/utopia/websocket.rb, line 50 def read @driver.parse(@io.readpartial(READ_BUFFER_SIZE)) end
run() { |driver| ... }
click to toggle source
# File lib/utopia/websocket.rb, line 54 def run(&handler) @running = true @driver.on(:close) do @running = false end @driver.on(:open) do yield @driver if block_given? end @driver.start while @running self.read end ensure @io.close end
write(string)
click to toggle source
# File lib/utopia/websocket.rb, line 46 def write(string) @io.write(string) end