lib/isomorfeus/transport.rb in isomorfeus-transport-23.7.0.rc5 vs lib/isomorfeus/transport.rb in isomorfeus-transport-23.8.0.rc1
- old
+ new
@@ -1,10 +1,12 @@
+# backtick_javascript: true
+
module Isomorfeus
module Transport
class << self
if RUBY_ENGINE == 'opal'
- PING = `JSON.stringify({iso_ping: true})`
+ PING = { iso_ping: true }.to_json
attr_accessor :socket
def init
@socket = nil
@@ -23,12 +25,11 @@
window_protocol = `window.location.protocol`
ws_protocol = window_protocol == 'https:' ? 'wss:' : 'ws:'
ws_url = "#{ws_protocol}//#{`window.location.host`}#{Isomorfeus.api_websocket_path}"
- headers = (session_id.nil? || session_id.empty?) ? nil : { 'Cookie': "session=#{session_id}" }
- @socket = Isomorfeus::Transport::WebsocketClient.new(ws_url, nil, headers)
+ @socket = Isomorfeus::Transport::WebsocketClient.new(ws_url, nil)
@socket.on_error do |error|
`console.warn('Isomorfeus::Transport: Will try again, but so far error connecting:', error)`
@socket.close
after 1000 do
Isomorfeus::Transport.promise_connect(session_id, promise)
@@ -137,11 +138,11 @@
agent.promise
end
def send_message(channel_class, channel, message)
Isomorfeus.raise_error(message: 'No socket!') unless @socket
- @socket.send(`JSON.stringify(#{{ notification: { class: channel_class.name, channel: channel, message: message }}.to_n})`)
+ @socket.send({ notification: { class: channel_class.name, channel: channel, message: message }}.to_json)
true
end
def promise_subscribe(channel_class_name, channel)
request = { subscribe: true, class: channel_class_name, channel: channel }
@@ -149,11 +150,11 @@
agent = get_agent_for_request_in_progress(request)
else
agent = Isomorfeus::Transport::RequestAgent.new(request)
register_request_in_progress(request, agent.id)
Isomorfeus.raise_error(message: 'No socket!') unless @socket
- @socket.send(`JSON.stringify(#{{ subscribe: { agent_ids: { agent.id => request }}}.to_n})`)
+ @socket.send({ subscribe: { agent_ids: { agent.id => request }}}.to_json)
end
result_promise = agent.promise.then do |agent|
agent.response
end
result_promise
@@ -165,10 +166,10 @@
agent = get_agent_for_request_in_progress(request)
else
agent = Isomorfeus::Transport::RequestAgent.new(request)
register_request_in_progress(request, agent.id)
Isomorfeus.raise_error(message: 'No socket!') unless @socket
- @socket.send(`JSON.stringify(#{{ unsubscribe: { agent_ids: { agent.id => request }}}.to_n})`)
+ @socket.send({ unsubscribe: { agent_ids: { agent.id => request }}}.to_json)
end
result_promise = agent.promise.then do |agent|
agent.response
end
result_promise