kahoot.js-latest
Version:
Answer, Join Kahoot Quizzes with nodejs
107 lines (85 loc) • 4.85 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: modules/feedback.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/feedback.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>const sleep = require("../util/sleep.js");
const LiveFeedbackPacket = require("../assets/LiveFeedbackPacket.js");
/**
* @fileinfo This is the feedback module
* - Loads the Feedback event and the sendFeedback method
*/
module.exports = function(){
/**
* feedback - Handles the Feedback event
* @param {Object} message The websocket message
*/
this.handlers.feedback = (message)=>{
if(message.channel === "/service/player" && message.data && message.data.id === 12){
/**
* Emitted when the host requests for feedback
*
* @event Client#Feedback
* @type {Object}
* @property {String} quizType
*/
this.feedbackTime = Date.now();
this._emit("Feedback",JSON.parse(message.data.content));
}
};
/**
* Send feedback to the host
* @function Client#sendFeedback
* @param {Number} fun 1-5. Rating for how fun the quiz was
* @param {Number} learn 0/1. Whether the client learned anything from the quiz
* @param {Number} recommend 0/1. Whether the client would recommend the quiz
* @param {Number} overall -1 - 1. The overall feeling of the client.
* @returns {Promise<LiveEventTimetrack>} Resolves when the feedback has been sent.
*/
this.sendFeedback = async (fun,learn,recommend,overall)=>{
if(this.gameid[0] === "0"){
throw "Cannot send feedback in Challenges";
}
const wait = Date.now() - this.feedbackTime;
if(wait < 500){
await sleep((500 - wait) / 1000);
}
return new Promise((resolve, reject)=>{
this._send(new LiveFeedbackPacket(this,fun,learn,recommend,overall),(result)=>{
if(!result || !result.successful){
reject(result);
}else{
resolve(result);
}
});
});
};
};
</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>