require File.expand_path('../websocket', __FILE__) unless defined?(Faye::WebSocket) #可以把路径转换成绝对路径
module Faye
class EventSource
include WebSocket::API::EventTarget
attr_reader :env, :url, :ready_state
DEFAULT_RETRY = 5
def initialize(env, options = {})
WebSocket.ensure_reactor_running
super()
@env = env
@ping = options[:ping]
@retry = (options[:retry] || DEFAULT_RETRY).to_f
@url = EventSource.determine_url(env)
@stream = Stream.new(self)
@ready_state = WebSocket::API::CONNECTING
headers = ::WebSocket::Driver::Headers.new
if options[:headers]
options[:headers].each { |k,v| headers[k] = v }
end
if callback = @env['async.callback']
callback.call([101, {}, @stream])
end
@stream.write("HTTP/1.1 200 OK\r\n" +
"Content-Type: text/event-stream\r\n" +
"Cache-Control: no-cache, no-store\r\n" +
"Connection: close\r\n" +
headers.to_s +
"\r\n" +
"retry: #{ (@retry * 1000).floor }\r\n\r\n")
EventMachine.next_tick { open }
if @ping
@ping_timer = EventMachine.add_periodic_timer(@ping) { ping }
end
end
end
end
这里的headers = ::WebSocket::Driver::Headers.new
中的::表示什么?
他和headers = WebSocket::Driver::Headers.new
这样写有什么区别?
谢谢