lib/sinatra/websocketio/client.rb in sinatra-websocketio-0.2.9 vs lib/sinatra/websocketio/client.rb in sinatra-websocketio-0.3.0
- old
+ new
@@ -29,11 +29,11 @@
on :connect do
@thread_heartbeat = Thread.new do
while @connecting
push :__heartbeat, {:time => Time.now.to_i}
- sleep 10
+ sleep 5
end
end
end
end
@@ -42,14 +42,17 @@
this = self
@running = true
url = @session ? "#{@url}/session=#{@session}" : @url
@websocket = nil
begin
- @websocket = WebSocket::Client::Simple::Client.new url
+ Timeout::timeout @timeout do
+ @websocket = WebSocket::Client::Simple::Client.new url
+ end
rescue StandardError, Timeout::Error => e
+ this.emit :error, e
Thread.new do
- sleep 5
+ sleep 5
connect
end
end
return self unless @websocket
@@ -66,13 +69,11 @@
if this.connecting
this.connecting = false
this.emit :disconnect, e
end
if this.running
- Thread.new do
- sleep 5
- this.connect
- end
+ sleep 1
+ this.connect
end
end
@websocket.on :open do
this.connecting = true