-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added engine.io for websocket communication and a small demo with it
- Loading branch information
Manuel Alabor
committed
Sep 1, 2013
1 parent
7f0379e
commit ef1327d
Showing
9 changed files
with
132 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
{ | ||
"name": "kaffeeundkuchen", | ||
"version": "0.0.1", | ||
"description": "kaffeeundkuchen - coffee and pi: Rock your party with this crowd driven spotify player.", | ||
"keywords": [ | ||
"raspberrypi", | ||
"pi", | ||
"raspberry", | ||
"airtunes", | ||
"airplay", | ||
"spotify", | ||
"sound", | ||
"audio", | ||
"music", | ||
"party" | ||
], | ||
"main": "app.js", | ||
"repository": "http://github.com/swissmanu/kaffeeundkuchen", | ||
"author": "Manuel Alabor", | ||
"license": "MIT", | ||
"dependencies": { | ||
"airtunes": "~0.1.3", | ||
"optimist": "~0.3.5", | ||
"express": "~3.0.6", | ||
"libspotify": "~0.1.0", | ||
"igneous": "0.1.6", | ||
"debug": "0.7.2" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.8.2", | ||
"chai": "~1.5.0", | ||
"jshint": "~1.1.0", | ||
"mocha-lcov-reporter": "~0.0.1", | ||
"coveralls": "~2.0.7" | ||
}, | ||
"scripts": { | ||
"start": "node src/app.js", | ||
"test": "make test" | ||
} | ||
"name": "kaffeeundkuchen", | ||
"version": "0.0.1", | ||
"description": "kaffeeundkuchen - coffee and pi: Rock your party with this crowd driven spotify player.", | ||
"keywords": [ | ||
"raspberrypi", | ||
"pi", | ||
"raspberry", | ||
"airtunes", | ||
"airplay", | ||
"spotify", | ||
"sound", | ||
"audio", | ||
"music", | ||
"party" | ||
], | ||
"main": "app.js", | ||
"repository": "http://github.com/swissmanu/kaffeeundkuchen", | ||
"author": "Manuel Alabor", | ||
"license": "MIT", | ||
"dependencies": { | ||
"airtunes": "~0.1.3", | ||
"express": "~3.0.6", | ||
"libspotify": "~0.1.0", | ||
"debug": "0.7.2", | ||
"engine.io": "0.7.9", | ||
"engine.io-client": "0.7.9" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.8.2", | ||
"chai": "~1.5.0", | ||
"jshint": "~1.1.0", | ||
"mocha-lcov-reporter": "~0.0.1", | ||
"coveralls": "~2.0.7" | ||
}, | ||
"scripts": { | ||
"start": "node src/app.js", | ||
"test": "make test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,16 @@ | ||
|
||
var debug = require('debug')('kaffeeundkuchen') | ||
, express = require('express') | ||
, config = require('../config/config') | ||
, Playlist = require('./models/playlist') | ||
, SpotifyWrapper = require('./utils').SpotifyWrapper | ||
|
||
, playlist = new Playlist() | ||
, spotifyWrapper = new SpotifyWrapper(config); | ||
|
||
|
||
function createExpressApp(config, spotifyWrapper, playlist) { | ||
debug('create express app'); | ||
|
||
var app = express() | ||
, api = require('./api')() | ||
, client = require('./client')(); | ||
|
||
app.set('config', config); | ||
app.set('spotifyWrapper', spotifyWrapper); | ||
app.set('playlist', playlist); | ||
|
||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(express.static(__dirname + '/client/public')); | ||
|
||
app.use(api); | ||
app.use(client); | ||
|
||
return app; | ||
} | ||
, spotifyWrapper = new SpotifyWrapper(config) | ||
|
||
var app = createExpressApp(config, spotifyWrapper, playlist); | ||
, webSocket = require('./websocket') | ||
, appFactory = require('./factory') | ||
, app = appFactory(config, spotifyWrapper, playlist) | ||
, httpServer; | ||
|
||
debug('Starting KaffeeUndKuchen on port ' + config.server.port); | ||
app.listen(config.server.port); | ||
httpServer = app.listen(config.server.port); | ||
webSocket(httpServer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var debug = require('debug')('kaffeeundkuchen.factory') | ||
, express = require('express'); | ||
|
||
function createExpressApp(config, spotifyWrapper, playlist) { | ||
debug('create express app'); | ||
|
||
var app = express() | ||
, api = require('./api')() | ||
, client = require('./client')(); | ||
|
||
app.set('config', config); | ||
app.set('spotifyWrapper', spotifyWrapper); | ||
app.set('playlist', playlist); | ||
|
||
app.use(express.bodyParser()); | ||
app.use(express.methodOverride()); | ||
app.use(express.static(__dirname + '/client/public')); | ||
|
||
app.use(api); | ||
app.use(client); | ||
|
||
return app; | ||
} | ||
|
||
module.exports = createExpressApp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var debug = require('debug')('kaffeeundkuchen.websocket') | ||
, engine = require('engine.io'); | ||
|
||
|
||
function handleMessage(data) { | ||
debug('received websocket message'); | ||
console.log(data); | ||
} | ||
|
||
function handleClose() { | ||
debug('closed websocket connection'); | ||
} | ||
|
||
function handleNewConnection(socket) { | ||
debug('new websocket connection'); | ||
socket.on('message', handleMessage); | ||
socket.on('close', handleClose); | ||
|
||
socket.send('hi there!'); | ||
} | ||
|
||
/** Function: initWebSocket | ||
* Attaches the Engine.IO WebSocket abstraction to any passed httpServer | ||
* instance. | ||
* | ||
* Parameters: | ||
* (http.Server) httpServer - Node.JS HTTP Server instance | ||
*/ | ||
function initWebSocket(httpServer) { | ||
debug('inititialize websocket module'); | ||
|
||
var websocketServer = engine.attach(httpServer); | ||
websocketServer.on('connection', handleNewConnection); | ||
} | ||
|
||
module.exports = initWebSocket; |