websocket_fasthttp/socket_handler.go

76 lines
1.9 KiB
Go
Raw Normal View History

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-12-01 08:02:47 +00:00
SocketContext(serverCTX ServerContext) SocketContext
2017-11-10 08:33:40 +00:00
// Init invoked when server is stated
// If you override ths method, must call
2017-11-10 08:43:11 +00:00
//
// func (sh *SocketHandler) Init() error {
// if err := sh.SocketHandlers.Init(); nil != err {
// return err
// }
// ...
2017-11-14 03:50:56 +00:00
// ...
2017-11-10 08:43:11 +00:00
// return nil
// }
2017-11-27 11:19:19 +00:00
Init(serverCTX ServerContext) 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
2017-12-01 08:02:47 +00:00
Handshake(socketCTX SocketContext, ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader)
2017-11-10 08:33:40 +00:00
// OnConnect invoked when client is connected
// If you override ths method, must call
2017-11-10 08:43:11 +00:00
//
2017-11-10 16:49:00 +00:00
// func (sh *SocketHandler) OnConnect(soc cwf.Socket) cwf.Socket {
2017-11-14 05:21:09 +00:00
// soc = sh.SocketHandlers.OnConnect(newSoc)
2017-11-10 16:49:00 +00:00
// newSoc := ...
2017-11-14 05:21:09 +00:00
// return newSoc
2017-11-10 08:43:11 +00:00
// }
2017-11-27 15:42:27 +00:00
OnConnect(soc Socket)
2017-11-28 09:41:00 +00:00
Handle(soc Socket, stopChan <-chan struct{}, doneChan chan<- error)
2017-11-10 08:33:40 +00:00
// OnDisconnect invoked when client is disconnected
// If you override ths method, must call
2017-11-10 08:43:11 +00:00
//
2017-11-10 16:49:00 +00:00
// func (sh *SocketHandler) OnDisconnect(soc cwf.Socket) {
2017-11-10 08:43:11 +00:00
// ...
// sh.SocketHandlers.OnDisconnect(soc)
// }
2017-11-10 16:49:00 +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
2017-11-10 08:43:11 +00:00
//
// func (sh *SocketHandler) Destroy() {
// ...
// sh.SocketHandlers.Destroy()
// }
2017-11-10 08:33:40 +00:00
Destroy()
2017-11-10 16:49:00 +00:00
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-10 08:43:11 +00:00
//
// func (sh *SocketHandlers) Validate() {
// sh.SocketHandlers.Validate()
// ...
// }
2017-11-08 10:15:09 +00:00
Validate()
2017-11-14 05:21:09 +00:00
addSocket(soc Socket)
removeSocket(soc Socket)
2017-11-07 10:03:40 +00:00
}