Method: Wands::JavaScript::WebSocket::ClassMethods#open

Defined in:
lib/wands/java_script/web_socket.rb

#open(host, port) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/wands/java_script/web_socket.rb', line 17

def open(host, port)
  uri = URI::HTTP.build(host:, port:)
  ws = JS.global[:WebSocket].new(uri.to_s)
  ws[:binaryType] = "arraybuffer"

  instance = new(ws)
  ws.addEventListener("message") { instance << it }
  wait_until_ready ws
  instance
end