Class: Rubame::Client
- Inherits:
-
Object
- Object
- Rubame::Client
- Defined in:
- lib/rubame.rb
Instance Attribute Summary collapse
-
#closed ⇒ Object
Returns the value of attribute closed.
-
#frame ⇒ Object
Returns the value of attribute frame.
-
#handshake ⇒ Object
Returns the value of attribute handshake.
-
#messaged ⇒ Object
Returns the value of attribute messaged.
-
#opened ⇒ Object
Returns the value of attribute opened.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(socket, handshake, server) ⇒ Client
constructor
A new instance of Client.
- #onclose(&blk) ⇒ Object
- #onmessage(&blk) ⇒ Object
- #onopen(&blk) ⇒ Object
- #send(data) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(socket, handshake, server) ⇒ Client
Returns a new instance of Client.
102 103 104 105 106 107 108 109 110 |
# File 'lib/rubame.rb', line 102 def initialize(socket, handshake, server) @socket = socket @handshake = handshake @frame = WebSocket::Frame::Incoming::Server.new(:version => @handshake.version) @opened = false = [] @closed = false @server = server end |
Instance Attribute Details
#closed ⇒ Object
Returns the value of attribute closed.
100 101 102 |
# File 'lib/rubame.rb', line 100 def closed @closed end |
#frame ⇒ Object
Returns the value of attribute frame.
100 101 102 |
# File 'lib/rubame.rb', line 100 def frame @frame end |
#handshake ⇒ Object
Returns the value of attribute handshake.
100 101 102 |
# File 'lib/rubame.rb', line 100 def handshake @handshake end |
#messaged ⇒ Object
Returns the value of attribute messaged.
100 101 102 |
# File 'lib/rubame.rb', line 100 def end |
#opened ⇒ Object
Returns the value of attribute opened.
100 101 102 |
# File 'lib/rubame.rb', line 100 def opened @opened end |
#socket ⇒ Object
Returns the value of attribute socket.
100 101 102 |
# File 'lib/rubame.rb', line 100 def socket @socket end |
Instance Method Details
#onclose(&blk) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/rubame.rb', line 148 def onclose(&blk) if @closed begin blk.call end end end |
#onmessage(&blk) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/rubame.rb', line 136 def (&blk) if .size > 0 begin .each do |x| blk.call(x.to_s) end ensure = [] end end end |
#onopen(&blk) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/rubame.rb', line 126 def onopen(&blk) if @opened begin blk.call ensure @opened = false end end end |
#send(data) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/rubame.rb', line 116 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) ⇒ Object
112 113 114 |
# File 'lib/rubame.rb', line 112 def write(data) @socket.write data end |