ensl_gathers/lib/gather/controller.js
Chris Blanchard 5401e021ad Tidy up
2015-07-24 18:05:12 +01:00

54 lines
1 KiB
JavaScript

"use strict";
/*
* Gather Controller
*
* Server API
* gather:refresh - Refreshes active gather
* gather:notification - Creates a notification
*
* Client API
* gather:join - Assigns user to gather
* gather:vote - Assigns vote to map, leader or server
*
*/
var Gather = require("./gather");
var gather = new Gather();
module.exports = function (namespace) {
var refreshGather = function () {
namespace.sockets.forEach(function (socket) {
socket.emit("gather:refresh", {
gather: gather.toJson(),
user: socket._user
});
});
};
namespace.on("connection", function (socket) {
socket.on("gather:join", function (data) {
if (gather.can("addGatherer")) {
gather.addGatherer(socket._user);
refreshGather();
}
});
socket.on("gather:leave", function (data) {
if (gather.can("removeGatherer")) {
gather.removeGatherer(socket._user);
refreshGather();
}
});
socket.on("disconnect", function () {
});
socket.on("gather:vote", function (data) {
});
refreshGather();
});
};