You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
38 lines
1.3 KiB
3 years ago
|
package websocket
|
||
|
|
||
|
import (
|
||
|
"github.com/gorilla/websocket"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
// ReadTimeLimit is the maximum time the server is willing to wait after receiving a message before receiving another one.
|
||
|
ReadTimeLimit = 60 * time.Second
|
||
|
// WriteTimeLimit is the maximum time the server is willing to wait to send a message.
|
||
|
WriteTimeLimit = 10 * time.Second
|
||
|
// ControlTimeLimit is the maximum time the server is willing to wait to send a control message like Ping or Close.
|
||
|
ControlTimeLimit = (WriteTimeLimit * 5) / 10
|
||
|
// PingDelay is the time between pings.
|
||
|
// It must be less than ReadTimeLimit to account for latency and delays on either side.
|
||
|
PingDelay = (ReadTimeLimit * 7) / 10
|
||
|
)
|
||
|
|
||
|
// A Connection corresponds to a pair of actors.
|
||
|
type Connection struct {
|
||
|
conn *websocket.Conn
|
||
|
r reader
|
||
|
w writer
|
||
|
}
|
||
|
|
||
|
// ReadChannel returns the channel that can be used to read client messages from the connection.
|
||
|
// After receiving SocketClosed, the reader will close its channel.
|
||
|
func (c *Connection) ReadChannel() <-chan ClientMessage {
|
||
|
return c.r.channel
|
||
|
}
|
||
|
|
||
|
// WriteChannel returns the channel that can be used to send server messages on the connection.
|
||
|
// After sending SocketClosed, the writer will close its channel; do not send any further messages on the channel.
|
||
|
func (c *Connection) WriteChannel() chan<- ServerMessage {
|
||
|
return c.w.channel
|
||
|
}
|