mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-02-17 01:12:20 +00:00
Add 'gather:archive:refresh' client and server APIs
This commit is contained in:
parent
f8557bb073
commit
a01a3e0216
1 changed files with 19 additions and 3 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue