2017-11-07 10:03:40 +00:00
|
|
|
package websocket_fasthttp
|
|
|
|
|
|
|
|
import (
|
2017-11-08 10:15:09 +00:00
|
|
|
"time"
|
|
|
|
|
2017-11-07 10:03:40 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SocketHandler interface {
|
2017-11-10 08:33:40 +00:00
|
|
|
// Init invoked when server is stated
|
|
|
|
// If you override ths method, must call
|
|
|
|
Init() error
|
2017-11-09 09:10:19 +00:00
|
|
|
// Handshake do handshake client and server
|
2017-11-10 08:33:40 +00:00
|
|
|
// id is identity of client socket. if id is "", disallow connection
|
|
|
|
Handshake(ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader)
|
|
|
|
// OnConnect invoked when client is connected
|
|
|
|
// If you override ths method, must call
|
2017-11-09 09:47:30 +00:00
|
|
|
OnConnect(soc *Socket)
|
2017-11-08 10:15:09 +00:00
|
|
|
Handle(soc *Socket, stopChan <-chan struct{}, doneChan chan<- struct{})
|
2017-11-10 08:33:40 +00:00
|
|
|
// OnDisconnect invoked when client is disconnected
|
|
|
|
// If you override ths method, must call
|
2017-11-09 09:47:30 +00:00
|
|
|
OnDisconnect(soc *Socket)
|
2017-11-10 08:33:40 +00:00
|
|
|
// Destroy invoked when server is stopped
|
|
|
|
// If you override ths method, must call
|
|
|
|
Destroy()
|
|
|
|
|
|
|
|
GetSocket(id string) *Socket
|
|
|
|
GetSockets() map[string]*Socket
|
2017-11-08 10:15:09 +00:00
|
|
|
|
|
|
|
GetMaxMessageSize() int64
|
|
|
|
GetWriteTimeout() time.Duration
|
|
|
|
GetReadTimeout() time.Duration
|
|
|
|
GetPongTimeout() time.Duration
|
|
|
|
GetPingTimeout() time.Duration
|
|
|
|
GetPingPeriod() time.Duration
|
|
|
|
|
2017-11-10 08:33:40 +00:00
|
|
|
// Validate is check handler value
|
|
|
|
// If you override ths method, must call
|
2017-11-08 10:15:09 +00:00
|
|
|
Validate()
|
2017-11-07 10:03:40 +00:00
|
|
|
}
|