diff --git a/.gitignore b/.gitignore index 3bbb21f..e1c0ba3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1 @@ -partybeat2.pro.user -build/ -*.pyc -mpc/conf.py +public/app.js diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..05e7b6e --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +.PHONY: build clean + +build: + coffee -j public/app.js -c src/ + +clean: + rm -f public/app.js + diff --git a/README b/README index f8cfce5..60da62e 100644 --- a/README +++ b/README @@ -15,7 +15,22 @@ coffee-script mpd -== To run the server == +== Installation == - coffee server.coffee + 1. Install and configure mpd + + (TODO write docs for this) + + 2. Compile and install: + + $ make + $ sudo make install (TODO) + + 3. (TODO) You can now run `groovebasind` to start the server. + +== Developing == + + Compile upon save: + + $ coffee -w -j public/app.js -c src/ diff --git a/server.coffee b/groovebasind old mode 100644 new mode 100755 similarity index 57% rename from server.coffee rename to groovebasind index bc143a1..676ee72 --- a/server.coffee +++ b/groovebasind @@ -1,3 +1,5 @@ +#!/usr/bin/env coffee + http = require 'http' net = require 'net' socketio = require 'socket.io' @@ -11,19 +13,6 @@ config = host: 'localhost' port: 6600 -client = null -onMpdData = null -connectMpdClient = -> - client = net.connect config.mpd.port, config.mpd.host, -> - console.log 'client connected' - client.on 'data', onMpdData if onMpdData? - client.on 'end', -> - console.log 'client disconnected, reconnecting' - connectMpdClient() - -connectMpdClient() - - fileServer = new (static.Server) './public' app = http.createServer((request, response) -> request.addListener 'end', -> @@ -34,11 +23,21 @@ app = http.createServer((request, response) -> io = socketio.listen(app) io.set 'log level', config.log_level io.sockets.on 'connection', (socket) -> + client = null + connectClient = -> + client = net.connect config.mpd.port, config.mpd.host, -> + console.log 'client connected' + client.on 'data', (data) -> + socket.emit 'FromMpd', data.toString() + client.on 'end', -> + console.log 'client disconnected, reconnecting' + connectClient() + connectClient() + socket.on 'ToMpd', (data) -> console.log "[in] " + data client.write data - onMpdData = (data) -> - socket.emit 'FromMpd', data.toString() - - client.on 'data', onMpdData + socket.on 'disconnect', -> + client.removeAllListeners 'end' + client.end() diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..dd874b1 --- /dev/null +++ b/public/index.html @@ -0,0 +1,10 @@ + + +
+