Skip to content

Commit

Permalink
Send 'info' client-to-server command with page info collected from pl…
Browse files Browse the repository at this point in the history
…ugins
  • Loading branch information
andreyvit committed Nov 18, 2011
1 parent 0b09531 commit 65f31de
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/connector.coffee
Expand Up @@ -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'
Expand Down Expand Up @@ -93,6 +94,7 @@ exports.Connector = class Connector
@_handshakeTimeout.start(@options.handshake_timeout)

_onclose: (e) ->
@protocol = 0
@handlers.disconnected @_disconnectionReason, @_nextDelay
@_scheduleReconnection()

Expand Down
1 change: 1 addition & 0 deletions src/less.coffee
@@ -1,6 +1,7 @@

module.exports = class LessPlugin
@identifier = 'less'
@version = '1.0'

constructor: (@window, @host) ->

Expand Down
34 changes: 33 additions & 1 deletion src/livereload.coffee
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 65f31de

Please sign in to comment.