mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 11:27:06 +00:00
This commit is contained in:
16
websocket.go
16
websocket.go
@@ -332,6 +332,9 @@ type (
|
|||||||
Join(string)
|
Join(string)
|
||||||
// Leave removes a websocketConnection from a room
|
// Leave removes a websocketConnection from a room
|
||||||
Leave(string)
|
Leave(string)
|
||||||
|
// Disconnect disconnects the client, close the underline websocket conn and removes it from the conn list
|
||||||
|
// returns the error, if any, from the underline connection
|
||||||
|
Disconnect() error
|
||||||
}
|
}
|
||||||
|
|
||||||
websocketConnection struct {
|
websocketConnection struct {
|
||||||
@@ -381,7 +384,7 @@ func (c *websocketConnection) writer() {
|
|||||||
ticker := time.NewTicker(c.websocketServer.config.PingPeriod)
|
ticker := time.NewTicker(c.websocketServer.config.PingPeriod)
|
||||||
defer func() {
|
defer func() {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
c.underline.Close()
|
c.Disconnect()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -400,8 +403,7 @@ func (c *websocketConnection) writer() {
|
|||||||
//
|
//
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
c.websocketServer.free <- c
|
c.Disconnect()
|
||||||
c.underline.Close()
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
c.write(websocket.CloseMessage, []byte{})
|
c.write(websocket.CloseMessage, []byte{})
|
||||||
@@ -438,8 +440,7 @@ func (c *websocketConnection) writer() {
|
|||||||
|
|
||||||
func (c *websocketConnection) reader() {
|
func (c *websocketConnection) reader() {
|
||||||
defer func() {
|
defer func() {
|
||||||
c.websocketServer.free <- c
|
c.Disconnect()
|
||||||
c.underline.Close()
|
|
||||||
}()
|
}()
|
||||||
conn := c.underline
|
conn := c.underline
|
||||||
|
|
||||||
@@ -577,6 +578,11 @@ func (c *websocketConnection) Leave(roomName string) {
|
|||||||
c.websocketServer.leave <- payload
|
c.websocketServer.leave <- payload
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *websocketConnection) Disconnect() error {
|
||||||
|
c.websocketServer.free <- c // leaves from all rooms, fires the disconnect listeners and finally remove from conn list
|
||||||
|
return c.underline.Close()
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
// -------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------
|
||||||
// -----------------websocket messages and de/serialization implementation--------------
|
// -----------------websocket messages and de/serialization implementation--------------
|
||||||
|
|||||||
Reference in New Issue
Block a user