Class: DRb::WebSocket::Server
- Inherits:
-
Object
- Object
- DRb::WebSocket::Server
- Defined in:
- lib/opal/drb/websocket.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #accept(&block) ⇒ Object
- #close ⇒ Object
-
#initialize(uri, config) ⇒ Server
constructor
A new instance of Server.
- #reconnect ⇒ Object
Constructor Details
#initialize(uri, config) ⇒ Server
Returns a new instance of Server.
181 182 183 184 185 |
# File 'lib/opal/drb/websocket.rb', line 181 def initialize(uri, config) @uri = "#{uri}/#{SecureRandom.uuid}" @config = config reconnect end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
179 180 181 |
# File 'lib/opal/drb/websocket.rb', line 179 def uri @uri end |
Instance Method Details
#accept(&block) ⇒ Object
214 215 216 |
# File 'lib/opal/drb/websocket.rb', line 214 def accept(&block) @accepter = block end |
#close ⇒ Object
187 188 189 |
# File 'lib/opal/drb/websocket.rb', line 187 def close @ws.close end |
#reconnect ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/opal/drb/websocket.rb', line 191 def reconnect @ws.close if @ws @ws = ::WebSocket.new(@uri) @ws.onclose do |event| reconnect end @ws. do |event| = event.data.to_s sender_id = .slice(0, 36) = .slice(36, .length - 36) stream = StrStream.new() server_side = ServerSide.new(stream, @config, uri) @accepter.call server_side send_data = sender_id.bytes.each_slice(2).map(&:first) send_data += server_side.reply.bytes.each_slice(2).map(&:first) @ws.send(`new Uint8Array(#{send_data}).buffer`) end end |