const Player = require("../util/player"),
LiveEventNameAccept = require("../classes/LiveEventNameAccept");
/**
* PlayerJoined - Handles players joining
*
* @param {Object} data The information about the player {@link https://kahoot.js.org/enum/LiveEventPlayerJoined}
*/
function PlayerJoined(data) {
const {cid} = data;
if(this.controllers[cid]) {
if(this.controllers[cid].hasLeft) {
this.controllers[cid].hasLeft = false;
}
} else {
this.controllers[cid] = new Player(data, this);
}
if(this.state === "lobby" && this.options.autoPlay && this.controllers[cid].active) {
clearTimeout(this.mainEventTimer);
this.mainEventTimer = setTimeout(() => {
this.startGame();
}, 15e3);
}
this.send("/service/player", new LiveEventNameAccept(data, this));
/**
* Emitted when a player joins the game
*
* @event PlayerJoined
* @type Object
* @see {@link https://kahoot.js.org/enum/LiveEventPlayerJoined}
*/
this.emit("PlayerJoined", data);
}
module.exports = PlayerJoined;