Sha256: 043e4ba07a7b9c18152feb70e61f89235d02b497d0e5edd9d5d128a62c0d03eb
Contents?: true
Size: 1.31 KB
Versions: 38
Compression:
Stored size: 1.31 KB
Contents
# most of this code is based on https://github.com/livereload/livereload-js/blob/master/src/protocol.coffee # class @ProtocolError constructor: (reason, data) -> @message = "LiveReload protocol error (#{reason}) after receiving data: \"#{data}\"." class @ProtocolParser constructor: (@handler) -> @reset() reset: -> @send_hello = false process: (data) -> try if not @send_hello message = @_parseMessage(data, ['hello']) @send_hello = true @handler.connected(message) else message = @_parseMessage(data, ['heartbeat', 'styles', 'reload', 'compile_start', 'compile_end']) @handler.message(message) catch e if e instanceof ProtocolError @handler.error e else throw e _parseMessage: (data, validNames) -> try message = JSON.parse(data) catch e throw new ProtocolError('unparsable JSON', data) unless message.name throw new ProtocolError('missing "name" key', data) unless message.name in validNames throw new ProtocolError("invalid command '#{message.name}', only valid commands are: #{validNames.join(', ')})", data) return message
Version data entries
38 entries across 38 versions & 1 rubygems