mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-03-04 00:10:53 +00:00
54 lines
1 KiB
JavaScript
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();
|
|
});
|
|
};
|