-
Notifications
You must be signed in to change notification settings - Fork 2
Game Sockets
Nulled edited this page Jun 19, 2021
·
5 revisions
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 "socket.io-client@2.0.0". To establish the connection we do need to add a few querys too.
- "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
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