Class: DRb::WebSocket::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/opal/drb/websocket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, config) ⇒ Server

Returns a new instance of Server.



102
103
104
105
# File 'lib/opal/drb/websocket.rb', line 102

def initialize(uri, config)
  @uri = "#{uri}/#{SecureRandom.uuid}"
  @config = config
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



100
101
102
# File 'lib/opal/drb/websocket.rb', line 100

def uri
  @uri
end

Instance Method Details

#acceptObject



111
112
113
114
115
116
117
118
119
# File 'lib/opal/drb/websocket.rb', line 111

def accept
  ws = ::WebSocket.new(@uri)
  ws.onmessage do |event|
    stream = StrStream.new(event.data.to_s)
    server_side = ServerSide.new(stream, @config, uri)
    yield server_side
    ws.send(`new Uint8Array(#{server_side.reply.bytes.each_slice(2).map(&:first)}).buffer`)
  end
end

#closeObject



107
108
109
# File 'lib/opal/drb/websocket.rb', line 107

def close
  @ws.close
end