lib/guard/livereload/reactor.rb in guard-livereload-2.1.1 vs lib/guard/livereload/reactor.rb in guard-livereload-2.1.2

- old
+ new

@@ -1,16 +1,17 @@ require 'multi_json' module Guard class LiveReload class Reactor - attr_reader :web_sockets, :thread, :options + attr_reader :web_sockets, :thread, :options, :connections_count def initialize(options) - @web_sockets = [] - @options = options - @thread = Thread.new { _start_reactor } + @web_sockets = [] + @options = options + @thread = Thread.new { _start_reactor } + @connections_count = 0 end def stop thread.kill end @@ -49,11 +50,13 @@ UI.info "LiveReload is waiting for a browser to connect." end end def _connect(ws) - UI.info "Browser connected." + @connections_count += 1 + UI.info "Browser connected." if connections_count == 1 + ws.send MultiJson.encode( command: 'hello', protocols: ['http://livereload.com/protocols/official-7'], serverName: 'guard-livereload' ) @@ -62,10 +65,9 @@ UI.error $! UI.error $!.backtrace end def _disconnect(ws) - UI.info "Browser disconnected." @web_sockets.delete(ws) end def _print_message(message) message = MultiJson.decode(message)