new Client(options)
constructor - Creates the Client
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | An object containing settings, controlling things such as team mode, two factor auth
Properties
|
Example
// This example demonstrates proxying
new Client({
proxy: (type, url) => {
// type is "http" or "ws"
// url is the request url or got request options
// should return a url or got request options, though 'ws' must return a url
return url;
}
});
Members
cometd :CometDClient
The CometD client. https://docs.cometd.org/current7/reference/
Type:
- CometDClient
controllers :Object.<Player>
The controllers, mapped by id
Type:
- Object.<Player>
currentQuestionIndex :Number
The current question index
Type:
- Number
currentQuizIndex :Number
The current quiz index, used in playlists
Type:
- Number
feedback :Array.<Object>
The feedback received.
Type:
- Array.<Object>
- Source:
- See:
gameid :String
The game pin of the game
Type:
- String
getReadyTime :Number
The time the QuestionReady started
Type:
- Number
jumbleSteps :Array.<Number>
The shuffled steps of the jumble question
Type:
- Array.<Number>
mainEventTimer :Number
A number from setTimeout used for autoPlay and question ending
Type:
- Number
questionStartTime :Number
The time the quesiton started
Type:
- Number
questionStartTime
The game options
quiz :Quiz
The current quiz being played
Type:
- Quiz
quizPlaylist :Array.<String>|Array.<Quiz>
The list of quizzes or ids
Type:
- Array.<String> | Array.<Quiz>
quizQuestionAnswers
get quizQuestionAnswers - The number of choices per question
recoveryData :Object
The recovery data
Type:
- Object
- Source:
- See:
startTime :Number
The time the quiz started
Type:
- Number
state :String
The current state of the game
- "lobby"
- "start"
- "getready"
- "teamtalk"
- "question"
- "timeover"
- "questionend"
- "podium"
- "quizend"
Type:
- String
status :String
The current status of the game. Either "ACTIVE" or "LOCKED"
Type:
- String
twoFactorInterval :Number
A number from setInterval for use in two-factor auth resets
Type:
- Number
twoFactorSteps :Array.<Number>
A shuffled list of numbers representing the current pattern for the two-factor steps
Type:
- Array.<Number>
Methods
_createHandshake() → {Promise}
_createHandshake - Creates the connection to the server
Returns:
- Resolves if successful, rejects if an error occurs
- Type
- Promise
checkAllAnswered()
checkAllAnswered - Checks if all players have answered. If yes, ends the question.
(async) closeGame()
async closeGame - Closes the game, disconnects from Kahoot
endGame() → {Promise.<Boolean>}
endGame - Ends the quiz. Sends the final data to all players
Returns:
Resolves if successful, rejects if not
- Type
- Promise.<Boolean>
getPlayer(cid) → {Player}
getPlayer - Gets the player by cid
Parameters:
Name | Type | Description |
---|---|---|
cid |
String | The cid of the player to get |
Returns:
A player
- Type
- Player
(async) initialize(quizId) → {Promise.<Client>}
async initialize - Downloads the quiz information for the game
Parameters:
Name | Type | Description |
---|---|---|
quizId |
String | Quiz | Array | The quiz id/url to use, or a Quiz object. |
Returns:
The client.
- Type
- Promise.<Client>
kickPlayer(player) → {Promise.<Boolean>}
kickPlayer - Kicks a player from a game
Parameters:
Name | Type | Description |
---|---|---|
player |
String | Player | The cid or player to kick |
Returns:
Resolves if the kick is successful or not
- Type
- Promise.<Boolean>
lock() → {Promise}
lock - Locks the game
Returns:
Resolves if successful, rejects if not
- Type
- Promise
message(message)
message - Handles messages from the server
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
message |
Object | The CometD message from the server
Properties
|
next() → {Promise.<Boolean>}
next - Manages transitions between certain events
Returns:
Successful or not
- Type
- Promise.<Boolean>
readyQuestion() → {Promise.<Boolean>}
readyQuestion - Starts the question
Returns:
Whether successful or not
- Type
- Promise.<Boolean>
(async) replayGame() → {Promise.<Boolean>}
async replayGame - Plays the game again
Returns:
Whether the replay message was successful
- Type
- Promise.<Boolean>
requestFeedback() → {Promise.<Boolean>}
requestFeedback - Requests feedback from the user
Returns:
Whether the request was successful or not
- Type
- Promise.<Boolean>
(async) resetGame() → {Promise.<Boolean>}
resetGame - Resets the game, removes all players
Returns:
Resolves whether successful or not
- Type
- Promise.<Boolean>
resetTwoFactorAuth() → {Promise.<Boolean>}
resetTwoFactorAuth - Resets the two-factor auth and notifies clients
Returns:
Successful or not
- Type
- Promise.<Boolean>
send(channel, message, shouldReject) → {Promise.<Boolean>}
send - Wrapper for publishing data to the cometd server
Parameters:
Name | Type | Description |
---|---|---|
channel |
String | The channel to publish the data to |
message |
Object | The data to send |
shouldReject |
Boolean | Whether the function should reject if the message fails to send. |
Returns:
Whether the message was successful
- Type
- Promise.<Boolean>
sendQuestionResults() → {Promise.<Array.<Boolean>>}
sendQuestionResults - Sends the question results to the players
Returns:
Whether the message was successfully sent
- Type
- Promise.<Array.<Boolean>>
(async) sendRankings() → {Promise.<Boolean>}
async sendRankings - Sends the medals to players (podium)
Used before endGame
Returns:
Resolves if successful, rejects if not
- Type
- Promise.<Boolean>
(async) start() → {Promise.<String>}
async start - Starts the game
Returns:
The game pin.
- Type
- Promise.<String>
startGame() → {Promise.<Boolean>}
startGame - Starts the game
Returns:
Whether successful or not
- Type
- Promise.<Boolean>
(async) startQuestion() → {Promise}
async startQuestion - Starts the question
Returns:
Resolves when question is started.
- Type
- Promise
startTeamTalk() → {Promise.<Boolean>}
startTeamTalk - Starts team talk
Returns:
Whether successful or not
- Type
- Promise.<Boolean>
(async) timeOver() → {Promise}
timeOver - Ends the question
Returns:
@see {Client.sendQuestionResults}
- Type
- Promise
unlock() → {Promise}
unlock - Unlocks the game
Returns:
Resolves if successful, rejects if not
- Type
- Promise