@towercg2/server
Version:
The server runtime for the TowerCG2 video graphics system.
33 lines (32 loc) • 1.11 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const client_1 = require("@towercg2/client");
const ServerPlugin_1 = require("../../ServerPlugin");
const reducer_1 = require("./reducer");
const utils_1 = require("../../utils");
const actions_1 = require("./actions");
class RosterPlugin extends ServerPlugin_1.ServerPlugin {
buildDefaultConfig() {
return {};
}
buildDefaultState() {
return {};
}
buildReducer() {
return reducer_1.reducer;
}
async initialize(http) {
this.interval = setInterval(() => this.updateRoster(), 250);
this.client.handleEvent(client_1.ProtocolNames.NEW_CLIENT_CONNECTED, () => this.updateRoster());
}
async cleanup() {
clearInterval(this.interval);
}
updateRoster() {
const sockets = this.server.authenticatedSockets;
const clients = sockets.map((s) => utils_1.socketToClientInfo(s));
this.store.dispatch(actions_1.updateClients(clients));
}
}
RosterPlugin.pluginName = client_1.RosterPluginName;
exports.RosterPlugin = RosterPlugin;