Created
August 21, 2011 15:27
-
-
Save tommedema/1160744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//handles audio information of clients, eg. codecs they can play | |
module.exports = function(availClients, unavailClients, io) { | |
var util = require('util'); | |
//for each connection | |
io.sockets.on('connection', handleConnection); | |
function handleConnection (socket) { | |
//fired when the client discovered it's codec capabilities | |
socket.on('codecCapability', function (mp3, mp4, ogg) { | |
//validate input (can be either 'probably', 'maybe' or '' | |
if ( (mp3 !== 'probably' && mp3 !== 'maybe' && mp3 !== '') | |
|| (mp4 !== 'probably' && mp4 !== 'maybe' && mp4 !== '') | |
|| (ogg !== 'probably' && ogg !== 'maybe' && ogg !== '')) { | |
return; | |
} | |
//get the name of this socket and continue | |
var name = socket.get('name', function (err, name) { | |
if (err) { | |
util.debug('Error: could not get name of socket'); | |
return; | |
} | |
//get this client | |
var thisClient = unavailClients[name]; | |
if (!thisClient) thisClient = availClients[name]; | |
if (!thisClient) { | |
util.debug('Error: client could not be located.'); | |
return; | |
} | |
//update client's capability list | |
thisClient.audioCapabilityList = { | |
mp3: mp3 | |
, mp4: mp4 | |
, ogg: ogg | |
}; | |
//debug | |
util.debug('set capability list of client to: ' + util.inspect(thisClient.audioCapabilityList)); | |
}); | |
}); | |
} | |
}; |
This file contains hidden or 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
module.exports = function(io) { | |
var util = require('util'), | |
Step = require('step'); | |
//for each connection | |
io.sockets.on('connection', function (socket) { | |
//fired when the client discovered it's codec capabilities | |
socket.on('codecCapability', function (mp3, mp4, ogg) { | |
//validate input | |
//get the name of this socket and continue | |
var name = socket.get('name', function (err, name) { | |
//update capability list | |
}); | |
}); | |
} | |
}; |
This file contains hidden or 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
module.exports = function(io) { | |
var util = require('util'), | |
Step = require('step'); | |
Step( | |
function onConnection() { | |
io.sockets.on('connection', this); | |
}, | |
function handleConnection(socket) { | |
socket.on('codecCapability', this); | |
}, | |
function setCodecCapabilityForSocket(mp3, mp4, ogg) { | |
//validate input | |
socket.get('name', function(err, name) { | |
this(err, name, mp3, mp4, ogg); | |
}); | |
}, | |
function setCodecCapabilityForName(err, name, mp3, mp4, ogg) { | |
//update client's capability list | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment