lib/isomorfeus/transport.rb in isomorfeus-transport-2.2.11 vs lib/isomorfeus/transport.rb in isomorfeus-transport-2.3.0
- old
+ new
@@ -1,9 +1,11 @@
module Isomorfeus
module Transport
class << self
if RUBY_ENGINE == 'opal'
+ PING = `JSON.stringify({iso_ping: true})`
+
attr_accessor :socket
def init
@socket = nil
promise_connect if Isomorfeus.on_browser? || Isomorfeus.on_mobile?
@@ -55,11 +57,19 @@
requests_in_progress[:requests].each_key do |request|
agent = get_agent_for_request_in_progress(request)
open_promise.then { promise_send_request(request) } if agent && !agent.sent
end
open_promise.then { promise.resolve(true) }
+ keep_session_alive if on_browser?
end
promise
+ end
+
+ def keep_session_alive
+ after 480000 do
+ @socket.send(PING)
+ keep_session_alive
+ end
end
def disconnect
@socket.close if @socket
@socket = nil