go-siris / siris

DEPRECATED: The community driven fork of Iris. The fastest web framework for Golang!
Other
142 stars 16 forks source link

Websocket examples #21

Closed Dexus closed 7 years ago

Dexus commented 7 years ago

https://github.com/go-siris/siris/blob/master/_examples/intermediate/websockets/connectionlist/main.go#L73

Need to be close (delete(Conn,c)) the connection, else you get all the message...

Andersbiha commented 7 years ago

Isn't this exactly what is supposed to happen?

Since you're leaving a room and not totally disconnecting the web-socket connection should still be kept alive.

Dexus commented 7 years ago

yeah, I was first thinking that was the bug, but it must a bit deeper in the source. Maybe you can find it if you like to watch into it. Else I will do it later.

Andersbiha commented 7 years ago

Il'l look into it when i get off work.

Dexus commented 7 years ago

To fix this bug we need to change only:

https://github.com/go-siris/siris/blob/master/websocket/emitter.go#L47 add this

if e.conn.server.rooms[e.to] == nil {
    return nil
}

https://github.com/go-siris/siris/blob/master/websocket/server.go#L304-305

s.rooms[name] = append(s.rooms[name][:i], s.rooms[name][i+1:]...)

https://github.com/go-siris/siris/blob/master/websocket/server.go#L331-332

s.rooms[roomName] = append(s.rooms[roomName][:i], s.rooms[roomName][i+1:]...)

Sorry if I just steal you the fun to look into it 😀

Andersbiha commented 7 years ago

Should be fixed in the latest commit to the devel branch https://github.com/go-siris/siris/commit/c5fd6787fba149bb5e20fb69fc4e8828db866370