class XRBP::WebSocket::Plugins::AutoConnect
Automatically connects on instantiation and reconnects on close events.
@example autoconnecting
connection = WebSocket::Connection.new "wss://s1.ripple.com:443" connection.add_plugin :autoconnect connection.open? # => true
Attributes
reconnect_delay[RW]
Public Class Methods
new(connection)
click to toggle source
Calls superclass method
XRBP::PluginBase::new
# File lib/xrbp/websocket/plugins/autoconnect.rb, line 14 def initialize(connection) super(connection) @reconnect_delay = nil end
Public Instance Methods
added()
click to toggle source
# File lib/xrbp/websocket/plugins/autoconnect.rb, line 19 def added plugin = self connection.define_instance_method(:reconnect_delay=) do |d| plugin.reconnect_delay = d connections.each{ |c| c.plugin(AutoConnect) .reconnect_delay = d } if self.kind_of?(MultiConnection) end return if connection.kind_of?(MultiConnection) conn = connection connection.on :completed do connected = false until conn.force_quit? || connected conn.rsleep(plugin.reconnect_delay) if plugin.reconnect_delay next if conn.force_quit? begin conn.connect connected = true rescue conn.rsleep(3) end end end until connection.force_quit? || connection.open? begin connection.connect rescue connection.rsleep(3) end end end