class Padrino::WebSockets::SpiderGazelle::EventManager
Public Class Methods
new(channel, user, ws, event_context, &block)
click to toggle source
Calls superclass method
Padrino::WebSockets::BaseEventManager::new
# File lib/padrino-websockets/spider-gazelle/event-manager.rb, line 5 def initialize(channel, user, ws, event_context, &block) ws.progress method(:on_message) ws.finally method(:on_shutdown) ws.on_open method(:on_open) super channel, user, ws, event_context, &block end
write(message, ws)
click to toggle source
Write a message to the WebSocket.
# File lib/padrino-websockets/spider-gazelle/event-manager.rb, line 24 def self.write(message, ws) ws.text ::Oj.dump(message) end
Public Instance Methods
on_shutdown()
click to toggle source
Manage the WebSocket’s connection being closed.
Calls superclass method
Padrino::WebSockets::BaseEventManager#on_shutdown
# File lib/padrino-websockets/spider-gazelle/event-manager.rb, line 16 def on_shutdown @pinger.cancel if @pinger super end
Protected Instance Methods
do_ping(time1, time2)
click to toggle source
Ping the WebSocket connection
# File lib/padrino-websockets/spider-gazelle/event-manager.rb, line 44 def do_ping(time1, time2) @ws.ping 'pong' end
on_open(event)
click to toggle source
Maintain the connection if ping frames are supported
Calls superclass method
Padrino::WebSockets::BaseEventManager#on_open
# File lib/padrino-websockets/spider-gazelle/event-manager.rb, line 32 def on_open(event) super event if @ws.ping('pong') variation = 1 + rand(20000) @pinger = @ws.loop.scheduler.every 40000 + variation, method(:do_ping) end end