Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Send 'info' client-to-server command with page info collected from pl…

…ugins
  • Loading branch information...
commit 65f31de1e297d4492173f7ae6a215e10fc8fdd63 1 parent 0b09531
@andreyvit andreyvit authored
Showing with 37 additions and 2 deletions.
  1. +3 −1 src/connector.coffee
  2. +1 −0  src/less.coffee
  3. +33 −1 src/livereload.coffee
View
4 src/connector.coffee
@@ -8,9 +8,10 @@ exports.Connector = class Connector
@_uri = "ws://#{@options.host}:#{@options.port}/livereload"
@_nextDelay = @options.mindelay
@_connectionDesired = no
+ @protocol = 0
@protocolParser = new Parser
- connected: (protocol) =>
+ connected: (@protocol) =>
@_handshakeTimeout.stop()
@_nextDelay = @options.mindelay
@_disconnectionReason = 'broken'
@@ -93,6 +94,7 @@ exports.Connector = class Connector
@_handshakeTimeout.start(@options.handshake_timeout)
_onclose: (e) ->
+ @protocol = 0
@handlers.disconnected @_disconnectionReason, @_nextDelay
@_scheduleReconnection()
View
1  src/less.coffee
@@ -1,6 +1,7 @@
module.exports = class LessPlugin
@identifier = 'less'
+ @version = '1.0'
constructor: (@window, @host) ->
View
34 src/livereload.coffee
@@ -38,6 +38,7 @@ exports.LiveReload = class LiveReload
connected: (protocol) =>
@listeners.connect?()
@log "LiveReload is connected to #{@options.host}:#{@options.port} (protocol v#{protocol})."
+ @analyze()
error: (e) =>
if e instanceof ProtocolError
@@ -90,13 +91,44 @@ exports.LiveReload = class LiveReload
plugin = new pluginClass @window,
# expose internal objects for those who know what they're doing
- # (note that these are private APIs and subject to change!)
+ # (note that these are private APIs and subject to change at any time!)
_livereload: this
_reloader: @reloader
_connector: @connector
# official API
+ Timer: Timer
generateCacheBustUrl: (url) -> @reloader.generateCacheBustUrl(url)
+ # API that pluginClass can/must provide:
+ #
+ # string pluginClass.identifier
+ # -- required, globally-unique name of this plugin
+ #
+ # string pluginClass.version
+ # -- required, plugin version number (format %d.%d or %d.%d.%d)
+ #
+ # plugin = new pluginClass(window, officialLiveReloadAPI)
+ # -- required, plugin constructor
+ #
+ # bool plugin.reload(string path, { bool liveCSS, bool liveImg })
+ # -- optional, attemp to reload the given path, return true if handled
+ #
+ # object plugin.analyze()
+ # -- optional, returns plugin-specific information about the current document (to send to the connected server)
+ # (LiveReload 2 server currently only defines 'disable' key in this object; return {disable:true} to disable server-side
+ # compilation of a matching plugin's files)
+
@plugins.push plugin
return
+
+ analyze: ->
+ return unless @connector.protocol >= 7
+
+ pluginsData = {}
+ for plugin in @plugins
+ pluginsData[plugin.constructor.identifier] = pluginData = plugin.analyze?() || {}
+ pluginData.version = plugin.constructor.version
+
+ @connector.sendCommand { command: 'info', plugins: pluginsData, url: @window.location.href }
+ return
Please sign in to comment.
Something went wrong with that request. Please try again.