class Rubame::Client
Attributes
closed[RW]
frame[RW]
handshake[RW]
messaged[RW]
opened[RW]
socket[RW]
Public Class Methods
new(socket, handshake, server)
click to toggle source
# File lib/vendor/rubame.rb, line 99 def initialize(socket, handshake, server) @socket = socket @handshake = handshake @frame = WebSocket::Frame::Incoming::Server.new(:version => @handshake.version) @opened = false @messaged = [] @closed = false @server = server end
Public Instance Methods
onclose(&blk)
click to toggle source
# File lib/vendor/rubame.rb, line 145 def onclose(&blk) if @closed begin blk.call end end end
onmessage(&blk)
click to toggle source
# File lib/vendor/rubame.rb, line 133 def onmessage(&blk) if @messaged.size > 0 begin @messaged.each do |x| blk.call(x.to_s) end ensure @messaged = [] end end end
onopen(&blk)
click to toggle source
# File lib/vendor/rubame.rb, line 123 def onopen(&blk) if @opened begin blk.call ensure @opened = false end end end
send(data)
click to toggle source
# File lib/vendor/rubame.rb, line 113 def send(data) frame = WebSocket::Frame::Outgoing::Server.new(:version => @handshake.version, :data => data, :type => :text) begin @socket.write frame @socket.flush rescue @server.close(self) unless @closed end end
write(data)
click to toggle source
# File lib/vendor/rubame.rb, line 109 def write(data) @socket.write data end