kahoot.js-latest
Version:
Answer, Join Kahoot Quizzes with nodejs
102 lines (82 loc) • 4.72 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: modules/reconnect.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: modules/reconnect.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const sleep = require("../util/sleep.js");
const LiveReconnectPacket = require("../assets/LiveReconnectPacket.js");
/**
* @fileinfo This is the reconnect module
* - Loads the reconnect method
*/
module.exports = function(){
/**
* reconnect to a game
* @function Client#reconnect
* @param {(Number|String)} [pin] The gameid to connect to
* @param {String<Number>|Number} [cid] The client id to reconnect as
*/
this.reconnect = async (pin,cid)=>{
if(this.socket && this.socket.readyState === 1){
throw "Already connected! If there is an issue, close the connection!";
}
pin = pin || this.gameid;
cid = cid || this.cid;
if(pin[0] === "0"){
throw "Cannot reconnect to a Challenge.";
}
const settings = await this._createHandshake();
this.settings = settings;
// reconnect
await sleep(0.5);
await this._send(new LiveReconnectPacket(this,pin,cid));
return new Promise((resolve, reject)=>{
if(this.handlers.recovery){
this.reconnectRecovery = true;
}
this.handlers.ReconnectFinish = async (message)=>{
if(message.channel === "/service/controller" && message.data && message.data.type === "loginResponse"){
if(message.data.error){
reject(message.data);
this.disconnectReason = message.description;
this.leave(true);
}else{
this.cid = message.data.cid || cid;
this.emit("Joined",settings);
this.connected = true;
resolve(settings);
}
delete this.handlers.ReconnectFinish;
}
};
});
};
};
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="Client_data.html">data</a></li><li><a href="Client_defaults.html">defaults</a></li><li><a href="Client_defaults.modules.html">modules</a></li><li><a href="Client_defaults.options.html">options</a></li><li><a href="Client_defaults.wsproxy.WsProxyReturn.html">WsProxyReturn</a></li><li><a href="Client_quiz.html">quiz</a></li><li><a href="Client_quiz.currentQuestion.html">currentQuestion</a></li><li><a href="LiveEventTimetrack.html">LiveEventTimetrack</a></li><li><a href="Nemesis.html">Nemesis</a></li><li><a href="PointsData.html">PointsData</a></li><li><a href="StreakPoints.html">StreakPoints</a></li></ul><h3>Classes</h3><ul><li><a href="Client.html">Client</a></li></ul><h3>Events</h3><ul><li><a href="Client.html#event:Disconnect">Disconnect</a></li><li><a href="Client.html#event:Feedback">Feedback</a></li><li><a href="Client.html#event:GameReset">GameReset</a></li><li><a href="Client.html#event:Joined">Joined</a></li><li><a href="Client.html#event:NameAccept">NameAccept</a></li><li><a href="Client.html#event:Podium">Podium</a></li><li><a href="Client.html#event:QuestionEnd">QuestionEnd</a></li><li><a href="Client.html#event:QuestionReady">QuestionReady</a></li><li><a href="Client.html#event:QuestionStart">QuestionStart</a></li><li><a href="Client.html#event:QuizEnd">QuizEnd</a></li><li><a href="Client.html#event:QuizStart">QuizStart</a></li><li><a href="Client.html#event:RecoveryData">RecoveryData</a></li><li><a href="Client.html#event:TeamAccept">TeamAccept</a></li><li><a href="Client.html#event:TeamTalk">TeamTalk</a></li><li><a href="Client.html#event:TimeOver">TimeOver</a></li><li><a href="Client.html#event:TwoFactorCorrect">TwoFactorCorrect</a></li><li><a href="Client.html#event:TwoFactorReset">TwoFactorReset</a></li><li><a href="Client.html#event:TwoFactorWrong">TwoFactorWrong</a></li></ul><h3>Global</h3><ul><li><a href="global.html#EventEmitter">EventEmitter</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.5</a> on Sun Oct 11 2020 19:45:43 GMT-0700 (Pacific Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>