S
S
Senbonzakuraa2020-04-10 17:14:35
Domain name market
Senbonzakuraa, 2020-04-10 17:14:35

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
            })
        })
    }
}


Here is the content of app.js:

const smallRoom = new GameController(10, 10, 20, 20, 'smallRoom', 4040, io)
const highRoom = new GameController(5, 0, 10, 20, 'highRoom', 4045, io)


From the client, on the event event, I get the name of the room and connect to it. As far as I understand it is not necessary to create 2 class instances for different rooms in app.js? Because now I have 2 connections at once.

In the future, when creating a bet in a certain room, will I need to send the bet and the name of the room it will go to?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Irina Shvets, 2019-10-16
@nsmilyk

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).

W
WebReklamist, 2019-10-29
@WebReklamist

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 question

Ask a Question

731 491 924 answers to any question