Class: Client

Client(options)

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
Name Type Attributes Default Description
autoPlay Boolean Whether to automatically start, move through questions, and replay games
gameMode String <optional>
classic The game mode of the game. Can be "classic" or "team"
twoFactorAuth Boolean Whether to enable two-factor auth in the game
namerator Boolbea Whether to enable the friendly nickname generator
twoFactorInterval Number The time in seconds between two-factor resets
proxy function A function to handle options for http requests and websockets.
Source:
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

Type:
  • CometDClient
Source:

controllers :Object.<Player>

The controllers, mapped by id
Type:
Source:

currentQuestionIndex :Number

The current question index
Type:
  • Number
Source:

currentQuizIndex :Number

The current quiz index, used in playlists
Type:
  • Number
Source:

feedback :Array.<Object>

The feedback received.
Type:
  • Array.<Object>
Source:
See:

gameid :String

The game pin of the game
Type:
  • String
Source:

getReadyTime :Number

The time the QuestionReady started
Type:
  • Number
Source:

jumbleSteps :Array.<Number>

The shuffled steps of the jumble question
Type:
  • Array.<Number>
Source:

mainEventTimer :Number

A number from setTimeout used for autoPlay and question ending
Type:
  • Number
Source:

questionStartTime :Number

The time the quesiton started
Type:
  • Number
Source:

questionStartTime

The game options
Source:
See:

quiz :Quiz

The current quiz being played
Type:
  • Quiz
Source:

quizPlaylist :Array.<String>|Array.<Quiz>

The list of quizzes or ids
Type:
  • Array.<String> | Array.<Quiz>
Source:

quizQuestionAnswers

get quizQuestionAnswers - The number of choices per question
Source:

recoveryData :Object

The recovery data
Type:
  • Object
Source:
See:

startTime :Number

The time the quiz started
Type:
  • Number
Source:

state :String

The current state of the game - "lobby" - "start" - "getready" - "teamtalk" - "question" - "timeover" - "questionend" - "podium" - "quizend"
Type:
  • String
Source:

status :String

The current status of the game. Either "ACTIVE" or "LOCKED"
Type:
  • String
Source:

twoFactorInterval :Number

A number from setInterval for use in two-factor auth resets
Type:
  • Number
Source:

twoFactorSteps :Array.<Number>

A shuffled list of numbers representing the current pattern for the two-factor steps
Type:
  • Array.<Number>
Source:

Methods

_createHandshake() → {Promise}

_createHandshake - Creates the connection to the server
Source:
Returns:
- Resolves if successful, rejects if an error occurs
Type
Promise

checkAllAnswered()

checkAllAnswered - Checks if all players have answered. If yes, ends the question.
Source:

(async) closeGame()

async closeGame - Closes the game, disconnects from Kahoot
Source:

endGame() → {Promise.<Boolean>}

endGame - Ends the quiz. Sends the final data to all players
Source:
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
Source:
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.
Source:
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
Source:
Returns:
Resolves if the kick is successful or not
Type
Promise.<Boolean>

lock() → {Promise}

lock - Locks the game
Source:
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
Name Type Description
data Object The data sent from the server
channel String The channel the message is in
Source:

next() → {Promise.<Boolean>}

next - Manages transitions between certain events
Source:
Returns:
Successful or not
Type
Promise.<Boolean>

readyQuestion() → {Promise.<Boolean>}

readyQuestion - Starts the question
Source:
Returns:
Whether successful or not
Type
Promise.<Boolean>

(async) replayGame() → {Promise.<Boolean>}

async replayGame - Plays the game again
Source:
Returns:
Whether the replay message was successful
Type
Promise.<Boolean>

requestFeedback() → {Promise.<Boolean>}

requestFeedback - Requests feedback from the user
Source:
Returns:
Whether the request was successful or not
Type
Promise.<Boolean>

(async) resetGame() → {Promise.<Boolean>}

resetGame - Resets the game, removes all players
Source:
Returns:
Resolves whether successful or not
Type
Promise.<Boolean>

resetTwoFactorAuth() → {Promise.<Boolean>}

resetTwoFactorAuth - Resets the two-factor auth and notifies clients
Source:
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.
Source:
Returns:
Whether the message was successful
Type
Promise.<Boolean>

sendQuestionResults() → {Promise.<Array.<Boolean>>}

sendQuestionResults - Sends the question results to the players
Source:
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
Source:
Returns:
Resolves if successful, rejects if not
Type
Promise.<Boolean>

(async) start() → {Promise.<String>}

async start - Starts the game
Source:
Returns:
The game pin.
Type
Promise.<String>

startGame() → {Promise.<Boolean>}

startGame - Starts the game
Source:
Returns:
Whether successful or not
Type
Promise.<Boolean>

(async) startQuestion() → {Promise}

async startQuestion - Starts the question
Source:
Returns:
Resolves when question is started.
Type
Promise

startTeamTalk() → {Promise.<Boolean>}

startTeamTalk - Starts team talk
Source:
Returns:
Whether successful or not
Type
Promise.<Boolean>

(async) timeOver() → {Promise}

timeOver - Ends the question
Source:
Returns:
@see {Client.sendQuestionResults}
Type
Promise

unlock() → {Promise}

unlock - Unlocks the game
Source:
Returns:
Resolves if successful, rejects if not
Type
Promise