Add 'gather:archive:refresh' client and server APIs

This commit is contained in:
Chris Blanchard 2015-09-26 12:16:12 +01:00
parent f8557bb073
commit a01a3e0216

View file

@ -5,8 +5,7 @@
*
* Server API
* gather:refresh - Refreshes active gather
* gather:select - Selects a player for team
* gather:notification - Creates a notification
* gather:archive:refresh - Refreshes gather archive
*
* Client API
* gather:join - Assigns user to gather
@ -14,14 +13,15 @@
* gather:leave - Leave gather
* gather:select - Select player for team
* gather:refresh - Refresh gather for client
*
* gather:reset - Resets gather (ADMIN)
*
*/
var Map = require("./map");
var Server = require("./server");
var mongoose = require("mongoose");
var Gather = require("./gather_singleton");
var ArchivedGather = mongoose.model("ArchivedGather");
var _ = require("lodash");
var winston = require("winston");
@ -41,6 +41,15 @@ module.exports = function (namespace) {
trailing: true
});
var refreshArchive = () => {
ArchivedGather.recent((error, recentGathers) => {
if (error) return winston.error(error);
socket.emit("gather:archive:refresh", {
archive: recentGathers
});
});
};
Gather.registerCallback('onDone', refreshGather);
Gather.registerCallback('onEvent', refreshGather);
Gather.restart();
@ -52,6 +61,13 @@ module.exports = function (namespace) {
}
namespace.on("connection", function (socket) {
ArchivedGather.recent((error, recentGathers) => {
if (error) return winston.error(error);
socket.emit("gather:archive:refresh", {
archive: recentGathers
});
});
socket.on("gather:join", function (data) {
let gather = Gather.current;
if (gather.can("addGatherer")) gather.addGatherer(socket._user);