Answer the question
In order to leave comments, you need to log in
How to correctly implement rooms using sockets?
I am writing an online lottery, I want to create various rooms with a limit on rates and participants. Question. How to implement rooms correctly?
Actually here is the GameController.js game class:
class GameController {
constructor(timer, minBetPrice, maxBetPrice, maxAmount, room, port, socket) {
this.bets = {}
this.users = {}
this.room = room
this.timer = timer
this.minBetPrice = minBetPrice
this.maxBetPrice = maxBetPrice
this.maxAmount = maxAmount
this.amount = null
this.io = socket
this.io.listen(port)
this.initConnect()
}
initConnect () {
try {
this.io.on('connection', (socket => {
this.users[socket.id] = {
id: socket.id
}
console.log(this.users)
this.connectInRoom(socket)
socket.on('disconnect', data => {
console.log(`${socket.id} disconnected`)
delete this.users[socket.id]
})
}))
} catch (e) {
console.error(e)
}
}
connectInRoom(socket) {
socket.on('event', data => {
socket.join(data.room)
console.log(`${socket.id} - Joined in ${data.room} room`)
socket.emit('event', {
success: true,
message: `UserID - ${socket.id}`,
room: data.room
})
})
}
}
const smallRoom = new GameController(10, 10, 20, 20, 'smallRoom', 4040, io)
const highRoom = new GameController(5, 0, 10, 20, 'highRoom', 4045, io)
Answer the question
In order to leave comments, you need to log in
For infosites , it doesn't matter which . In Yandex, just regionality affects, and if you are sharpened only for the audience of the Russian Federation, then it is better to take .ru. Plus, people looking at the domain will understand that the site is already suitable for them (relevant). For example, if you want to know “where is it better to fly on vacation”, then choose the .ru website, as it will talk about the most convenient conditions for you as a citizen of the Russian Federation (about visa-free countries, for example).
Do not even hesitate, definitely RU. It is shorter, everyone knows how to write with a voice, it clearly speaks about the region. If you sell links, you are more likely to receive orders. Selling a domain in such a zone is also easier.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question