var onAuthenticate = function(socket, easyrtcid, appName, username, credential, easyrtcAuthMessage, next) {
// TODO : Verify authentication information
var previousConn = false;
app.getConnectionEasyrtcids(function(error, id_list) {
console.log('Ids connected now :', id_list);
async.each(id_list, function(id, cb) {
app.connection(id, function(er, cObj){
if (er) {
cb(er);
} else {
if (cObj.getUsername() == username && cObj.getEasyrtcid() != easyrtcid) {
previousConn = cObj;
}
cb();
}
});
}, function(err) {
if (err) {
next(err);
} else {
if (previousConn != false) {
previousConn.removeConnection(function(e){
console.log('Removed previous connection.');
next();
});
} else {
easyrtc.events.emitDefault("authenticate", socket, easyrtcid, appName, username, credential, easyrtcAuthMessage, next);
}
}
});
});
});