Top Level Namespace
Defined Under Namespace
Classes: SubstrateClient
Instance Method Summary collapse
Instance Method Details
#ws_request(url, payload) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/substrate_client.rb', line 12 def ws_request(url, payload) result = nil EM.run do ws = Faye::WebSocket::Client.new(url) ws.on :open do |event| # p [:open] ws.send(payload.to_json) end ws.on :message do |event| # p [:message, event.data] if event.data.include?("jsonrpc") result = JSON.parse event.data ws.close(3001, "data received") EM.stop end end ws.on :close do |event| # p [:close, event.code, event.reason] ws = nil end end result end |