Only send EventSource ping messages if the user specifies an interval, for symmetry with WebSocket.

This commit is contained in:
James Coglan
2012-02-12 23:53:32 +00:00
parent 183e56c770
commit 840a118cd5
2 changed files with 10 additions and 11 deletions
+6 -6
View File
@@ -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
+4 -5
View File
@@ -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