lib/guard/livereload/reactor.rb in guard-livereload-2.4.0 vs lib/guard/livereload/reactor.rb in guard-livereload-2.5.0
- old
+ new
@@ -16,23 +16,23 @@
thread.kill
end
def reload_browser(paths = [])
msg = "Reloading browser: #{paths.join(' ')}"
- UI.info msg
+ Compat::UI.info msg
if options[:notify]
- Notifier.notify(msg, title: 'Reloading browser', image: :success)
+ Compat::UI.notify(msg, title: 'Reloading browser', image: :success)
end
paths.each do |path|
data = _data(path)
- UI.debug(data)
+ Compat::UI.debug(data)
web_sockets.each { |ws| ws.send(MultiJson.encode(data)) }
end
end
- private
+ private
def _data(path)
data = {
command: 'reload',
path: "#{Dir.pwd}/#{path}",
@@ -43,43 +43,48 @@
end
data
end
def _start_reactor
- EventMachine.epoll
+ EventMachine.epoll if EventMachine.epoll?
+ EventMachine.kqueue if EventMachine.kqueue?
EventMachine.run do
- EventMachine.start_server(options[:host], options[:port], WebSocket, {}) do |ws|
+ EventMachine.start_server(
+ options[:host],
+ options[:port],
+ WebSocket,
+ options
+ ) do |ws|
ws.onopen { _connect(ws) }
ws.onclose { _disconnect(ws) }
ws.onmessage { |msg| _print_message(msg) }
end
- UI.info "LiveReload is waiting for a browser to connect."
+ Compat::UI.info 'LiveReload is waiting for a browser to connect.'
end
end
def _connect(ws)
@connections_count += 1
- UI.info "Browser connected." if connections_count == 1
+ Compat::UI.info 'Browser connected.' if connections_count == 1
ws.send MultiJson.encode(
command: 'hello',
protocols: ['http://livereload.com/protocols/official-7'],
serverName: 'guard-livereload'
)
@web_sockets << ws
rescue
- UI.error $!
- UI.error $!.backtrace
+ Compat::UI.error $!
+ Compat::UI.error $!.backtrace
end
def _disconnect(ws)
@web_sockets.delete(ws)
end
def _print_message(message)
message = MultiJson.decode(message)
- UI.info "Browser URL: #{message['url']}" if message['command'] == 'url'
+ Compat::UI.info "Browser URL: #{message['url']}" if message['command'] == 'url'
end
-
end
end
end