mirror of
https://github.com/faye/websocket-driver-ruby.git
synced 2025-11-01 13:59:38 +00:00
Only send EventSource ping messages if the user specifies an interval, for symmetry with WebSocket.
This commit is contained in:
@@ -2,7 +2,6 @@ require File.expand_path('../websocket', __FILE__) unless defined?(Faye::WebSock
|
||||
|
||||
module Faye
|
||||
class EventSource
|
||||
DEFAULT_PING = 10
|
||||
DEFAULT_RETRY = 5
|
||||
|
||||
include WebSocket::API
|
||||
@@ -26,12 +25,14 @@ module Faye
|
||||
|
||||
def initialize(env, options = {})
|
||||
@env = env
|
||||
@ping = options[:ping] || DEFAULT_PING
|
||||
@ping = options[:ping]
|
||||
@retry = (options[:retry] || DEFAULT_RETRY).to_f
|
||||
@url = EventSource.determine_url(env)
|
||||
@stream = Stream.new(self)
|
||||
|
||||
@ready_state = CONNECTING
|
||||
@send_buffer = []
|
||||
EventMachine.next_tick { open }
|
||||
|
||||
callback = @env['async.callback']
|
||||
callback.call([101, {}, @stream])
|
||||
@@ -42,10 +43,9 @@ module Faye
|
||||
"\r\n\r\n" +
|
||||
"retry: #{ (@retry * 1000).floor }\r\n\r\n")
|
||||
|
||||
@send_buffer = []
|
||||
EventMachine.next_tick { open }
|
||||
|
||||
@ping_timer = EventMachine.add_periodic_timer(@ping) { ping }
|
||||
if @ping
|
||||
@ping_timer = EventMachine.add_periodic_timer(@ping) { ping }
|
||||
end
|
||||
end
|
||||
|
||||
def last_event_id
|
||||
|
||||
@@ -92,8 +92,10 @@ module Faye
|
||||
include API
|
||||
|
||||
def initialize(env, supported_protos = nil, options = {})
|
||||
@env = env
|
||||
@stream = Stream.new(self)
|
||||
@env = env
|
||||
@stream = Stream.new(self)
|
||||
@ping = options[:ping]
|
||||
@ping_id = 0
|
||||
|
||||
@url = WebSocket.determine_url(@env)
|
||||
@ready_state = CONNECTING
|
||||
@@ -110,9 +112,6 @@ module Faye
|
||||
|
||||
@ready_state = OPEN if @parser.open?
|
||||
|
||||
@ping = options[:ping]
|
||||
@ping_id = 0
|
||||
|
||||
if @ping
|
||||
@ping_timer = EventMachine.add_periodic_timer(@ping) do
|
||||
@ping_id += 1
|
||||
|
||||
Reference in New Issue
Block a user