Game Sockets - Nul-led/wwo GitHub Wiki
Description
The websockets used for communicating between game client and server are provided by Socket.io. In order to communicate with the socket a special client is needed called "[email protected]". To establish the connection we do need to add a few querys too.
Queries
- "firebaseToken" - Accesstoken used for authentication
- "gameMode" - Gamemode to connect to (eg "en")
- "spectate" - Boolean, Used to specify if the player should join as a spectator
- "gameId" - GameId to connect to
- "playWithFriends" - Boolean, Is the game you want to join a friends lobby?
- "reconnect" - Boolean, Used for reconnecting
- "password" - Used to connect to password protected lobbys
How to connect
const io = require('socket.io-client') // import socket.io-client
const params = {
query: {
firebaseToken: 'token',
//... your querys ...
},
transports: ['websocket'] // we dont want to use slow http long polling
}
const socket = io.connect('https://api-games.werewolf-apps.com', params) // Open socket on games api
socket.on('game-joined', data => console.log(JSON.parse(data))) // example listener
socket.emit('game:chat-public:msg', JSON.stringify({ msg: 'some text' })) // sample event
References
- https://socket.io/
- https://socket.io/docs/v4/client-api/
- https://datatracker.ietf.org/doc/html/rfc6455