Client Events

Your client should listen to these events.

Connected

When this is emitted, we recommend saving the player's UID to handle the kick feature gracefully.

Automatically sent when a user connects using socket.connect().

socket.on('connected', data => {
 // Do stuff to set up the game, like hiding host only buttons
if(sessionStorage.getItem('uid') == uid) {
    if(!document.getElementsByClassName('hostOnly')) return
    for(const el of document.getElementsByClassName('hostOnly')){
    el.style.display = 'inline-block'
    }
}
sessionStorage.setItem('uid', data.user.uid)
})

Parameters

Name
Type
About

data

Object

Object with game and user info. See structure below.

{
        gameType: 'wyr/nhie/etc',
        gameId: 'ID',
        user: {
            name:'Display Name',
            picture: 'https://example.com/pfp.png',
            uid:'UID',
            host: true || false
        },
        host: 'HOST UID'
    }

Player Join

Parameters

Name
Type
About

data

Object

Object with player information.

Player Leave

Parameters

Name
Type
About

uid

String

The UID of the disconnecting player.

Votes

Get the votes sent from get_votes

Parameters

Name
Type
About

votes

Array

The votes, which are object containing the user's name & their answer.

New Question

Get the new data from next

Parameters

Name
Type
About

question

String or object

The modes with one question will return the card content as a string. The ones with more than one will return an object, where opt1 is the first option and opt2 is the second.

Error

Listen for errors.

Receive a Chat Message

Receive a chat message on the client.

Parameters

Name
Type
About

data

Object

An object containing the message (content) and author. See the structure below.

Players

Get an array of players from get_players

Parameters

Name
Type
About

data

Array

See structure below.

Kicking a User

Additional Word Wreck Events

Since Word Wreck has more components to it, it has a few extra events.

Vote

This will emit when everyone has submitted an answer to vote on.

Parameters

Name
Type
About

voteOptions

Array

The answers to vote for. See structure below.

Winner

When everyone has voted, this event will emit with the winner.

Parameters

Name
Type
About

winner

Object

The name of the winner and their answer. See structure below.

New Host

If a new host is assigned, reflect that in your app.

Last updated

Was this helpful?