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