JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
puttin' it all together
[watch-my-terminal.git] / publish-my-session.coffee
diff --git a/publish-my-session.coffee b/publish-my-session.coffee
new file mode 100644 (file)
index 0000000..bd2cd30
--- /dev/null
@@ -0,0 +1,35 @@
+handler = (req, res) ->
+       fs.readFile __dirname + '/index.html', (err, data) ->
+               if err
+                       res.writeHead(500)
+                       return res.end('Error loading index.html')
+
+               res.writeHead(200)
+               res.end(data)
+
+app = require('http').createServer(handler)
+io = require('socket.io').listen(app)
+fs = require('fs')
+terminal = require('./terminal.coffee')
+
+# SETTINGS
+app.listen(9293)
+term = terminal.new(105, 66)
+
+io.sockets.on 'connection', (socket) ->
+       # FIXME socket.emit 'write', term.getState()
+       term.on 'sequence', (data) ->
+               socket.emit 'write', "sequence: #{data}"
+       term.on 'text', (data) ->
+               socket.emit 'write', data
+       socket.on 'disconnect', ->
+               # FIXME stop term update callback
+               console.log 'client disconnected'
+
+process.stdin.resume()
+process.stdin.setEncoding 'utf8'
+
+process.stdin.on 'data', (data) ->
+       term.update data
+
+process.stdin.on 'end', -> process.exit()