guard-livereload 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/guard/livereload/reactor.rb +26 -18
- data/lib/guard/livereload/version.rb +1 -1
- metadata +2 -2
| @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            require 'em-websocket'
         | 
| 2 2 | 
             
            require 'multi_json'
         | 
| 3 | 
            +
            require 'thread'
         | 
| 3 4 |  | 
| 4 5 | 
             
            module Guard
         | 
| 5 6 | 
             
              class LiveReload
         | 
| @@ -8,6 +9,7 @@ module Guard | |
| 8 9 | 
             
                  attr_reader :thread, :web_sockets
         | 
| 9 10 |  | 
| 10 11 | 
             
                  def initialize(options)
         | 
| 12 | 
            +
                    @mutex = Mutex.new
         | 
| 11 13 | 
             
                    @web_sockets = []
         | 
| 12 14 | 
             
                    @options     = options
         | 
| 13 15 | 
             
                    @thread      = start_threaded_reactor(options)
         | 
| @@ -18,15 +20,17 @@ module Guard | |
| 18 20 | 
             
                  end
         | 
| 19 21 |  | 
| 20 22 | 
             
                  def reload_browser(paths = [])
         | 
| 21 | 
            -
                     | 
| 22 | 
            -
             | 
| 23 | 
            -
                       | 
| 24 | 
            -
                         | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 29 | 
            -
             | 
| 23 | 
            +
                    @mutex.synchronize do
         | 
| 24 | 
            +
                      UI.info "Reloading browser: #{paths.join(' ')}"
         | 
| 25 | 
            +
                      paths.each do |path|
         | 
| 26 | 
            +
                        data = MultiJson.encode(['refresh', {
         | 
| 27 | 
            +
                          :path           => "#{Dir.pwd}/#{path}",
         | 
| 28 | 
            +
                          :apply_js_live  => @options[:apply_js_live],
         | 
| 29 | 
            +
                          :apply_css_live => @options[:apply_css_live]
         | 
| 30 | 
            +
                        }])
         | 
| 31 | 
            +
                        UI.debug data
         | 
| 32 | 
            +
                        @web_sockets.each { |ws| ws.send(data) }
         | 
| 33 | 
            +
                      end
         | 
| 30 34 | 
             
                    end
         | 
| 31 35 | 
             
                  end
         | 
| 32 36 |  | 
| @@ -38,13 +42,15 @@ module Guard | |
| 38 42 | 
             
                        UI.info "LiveReload #{options[:api_version]} is waiting for a browser to connect."
         | 
| 39 43 | 
             
                        EventMachine.start_server(options[:host], options[:port], EventMachine::WebSocket::Connection, {}) do |ws|
         | 
| 40 44 | 
             
                          ws.onopen do
         | 
| 41 | 
            -
                             | 
| 42 | 
            -
                               | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
                               | 
| 47 | 
            -
             | 
| 45 | 
            +
                            @mutex.synchronize do
         | 
| 46 | 
            +
                              begin
         | 
| 47 | 
            +
                                UI.info "Browser connected."
         | 
| 48 | 
            +
                                ws.send "!!ver:#{options[:api_version]}"
         | 
| 49 | 
            +
                                @web_sockets << ws
         | 
| 50 | 
            +
                              rescue
         | 
| 51 | 
            +
                                UI.errror $!
         | 
| 52 | 
            +
                                UI.errror $!.backtrace
         | 
| 53 | 
            +
                              end
         | 
| 48 54 | 
             
                            end
         | 
| 49 55 | 
             
                          end
         | 
| 50 56 |  | 
| @@ -53,8 +59,10 @@ module Guard | |
| 53 59 | 
             
                          end
         | 
| 54 60 |  | 
| 55 61 | 
             
                          ws.onclose do
         | 
| 56 | 
            -
                            @ | 
| 57 | 
            -
             | 
| 62 | 
            +
                            @mutex.synchronize do
         | 
| 63 | 
            +
                              @web_sockets.delete ws
         | 
| 64 | 
            +
                              UI.info "Browser disconnected."
         | 
| 65 | 
            +
                            end
         | 
| 58 66 | 
             
                          end
         | 
| 59 67 | 
             
                        end
         | 
| 60 68 | 
             
                      end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: guard-livereload
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012- | 
| 12 | 
            +
            date: 2012-10-22 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: guard
         |