     monitor = watchr.watch
       path: filename
       listener: sendText
+      catchupDelay: 400
     onExit.push -> monitor.close()
 
     child = child_process.exec getEditCommand filename

# Set the environment variable below, and the server will refuse to serve clients who don't know the secret.
secret = process.env.TEXT_AID_TOO_SECRET

# These must be installed via "npm".
watchr = require "watchr"
optimist = require "optimist"

fs = require "fs"
child_process = require "child_process"

config =
  port: "9293"
  host: "localhost"
  editor: "urxvt -T textaid -geometry 100x30+80+20 -e vim"

args = optimist.usage("Usage: $0 [--port PORT] [--editor EDITOR-COMMAND]")
  .alias("h", "help")
  .default("port", config.port)
  .default("editor", config.editor)
  .argv

console.log args.editor

if args.help
  optimist.showHelp()
  process.exit(0)

console.log "Listening on: ws://#{config.host}:#{args.port}."
WSS  = require("ws").Server
wss  = new WSS port: args.port, host: config.host
wss.on "connection", (ws) -> ws.on "message", handler ws

  timestamp = process.hrtime().join "-"
  suffix = if request.isContentEditable then "html" else "txt"
  filename = "#{directory}/#{username}-text-aid-too-#{timestamp}.#{suffix}"
  console.log "edit:", filename

  fs.writeFile filename, request.text, (error) ->
    return exit() if error
