K
K
Kagtaviy2016-09-02 01:14:06
go
Kagtaviy, 2016-09-02 01:14:06

Why don't rooms work?

Hello, I don't understand what is the problem. I want to create rooms, but nothing comes out. I do it like this:

r := mux.NewRouter()
r.Handle("/socket.io/", controllers.CreateSocketIoServer())

CreateSocketIoServer() function:
var server *socketio.Server

func CreateSocketIoServer() *socketio.Server {
    server, _ = socketio.NewServer(nil)
    log.Println("Socket.io - запущен")
    return server
}

Then when the user enters mydomain.ru/room/name, the router
r.HandleFunc("/room/name", controllers.MainRoomHandle)

MainRoomHandle function
func MainRoomHandle(w http.ResponseWriter, r *http.Request) {
...
Chat(w, r)
}

chat function
func Chat(w http.ResponseWriter, r *http.Request) {
    server.On("connection", func(so socketio.Socket) {
        so.Join("1")
        log.Println("connect 1")
        so.On("disconnection", func() {
        })
    })

    server.On("connection", func(so socketio.Socket) {
        so.Join("2")
        log.Println("connect 2")
        so.On("disconnection", func() {
        })
    })
}

JS
var room = io('')
room.on('connection', function(){
  room.join('1');
});

When I go to maindomain.ru/room/name Then in the
connect 2 console
, no matter how hard the connection tries, it goes to the second room. Everything works fine with the default room. Please help, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Grabko, 2016-09-03
@VGrabko

What were you smoking before you thought of using this library in Go? I want that too. Use gorilla web sockets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question