2017-08-31 08:58:29 +00:00
|
|
|
package overflow_gateway_websocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
uuid "github.com/satori/go.uuid"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
)
|
|
|
|
|
2017-08-31 10:08:14 +00:00
|
|
|
const (
|
|
|
|
// DefaultHandshakeTimeout is default value of websocket handshake Timeout
|
|
|
|
DefaultHandshakeTimeout = 0
|
|
|
|
// DefaultReadBufferSize is default value of Read Buffer Size
|
|
|
|
DefaultReadBufferSize = 4096
|
|
|
|
// DefaultWriteBufferSize is default value of Write Buffer Size
|
|
|
|
DefaultWriteBufferSize = 4096
|
|
|
|
// DefaultEnableCompression is default value of support compression
|
|
|
|
DefaultEnableCompression = false
|
|
|
|
)
|
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
// ServerHandlers is implementation of the Server handler interface
|
|
|
|
type ServerHandlers struct {
|
|
|
|
HandshakeTimeout time.Duration
|
|
|
|
ReadBufferSize int
|
|
|
|
WriteBufferSize int
|
|
|
|
EnableCompression bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sh *ServerHandlers) GetHandshakeTimeout() time.Duration {
|
|
|
|
return sh.HandshakeTimeout
|
|
|
|
}
|
2017-09-20 03:53:06 +00:00
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
func (sh *ServerHandlers) GetReadBufferSize() int {
|
|
|
|
return sh.ReadBufferSize
|
|
|
|
}
|
2017-09-20 03:53:06 +00:00
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
func (sh *ServerHandlers) GetWriteBufferSize() int {
|
|
|
|
return sh.WriteBufferSize
|
|
|
|
}
|
2017-09-20 03:53:06 +00:00
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
func (sh *ServerHandlers) GetEnableCompression() bool {
|
|
|
|
return sh.EnableCompression
|
|
|
|
}
|
|
|
|
|
2017-09-20 03:53:06 +00:00
|
|
|
func (sh *ServerHandlers) OnConnection(ctx *fasthttp.RequestCtx) bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sh *ServerHandlers) OnConnected(soc Socket) {
|
2017-08-31 08:58:29 +00:00
|
|
|
|
|
|
|
}
|
2017-09-20 03:53:06 +00:00
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
func (sh *ServerHandlers) OnDisconnected(soc Socket) {
|
|
|
|
|
|
|
|
}
|
2017-09-20 03:53:06 +00:00
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
func (sh *ServerHandlers) OnCheckOrigin(ctx *fasthttp.RequestCtx) bool {
|
|
|
|
return true
|
|
|
|
}
|
2017-09-20 03:53:06 +00:00
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
func (sh *ServerHandlers) OnError(ctx *fasthttp.RequestCtx, status int, reason error) {
|
|
|
|
|
|
|
|
}
|
2017-09-20 03:53:06 +00:00
|
|
|
|
2017-08-31 08:58:29 +00:00
|
|
|
func (sh *ServerHandlers) OnIDGenerate(ctx *fasthttp.RequestCtx) string {
|
|
|
|
return uuid.NewV4().String()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates the configuration
|
|
|
|
func (sh *ServerHandlers) Validate() {
|
|
|
|
if sh.ReadBufferSize <= 0 {
|
|
|
|
sh.ReadBufferSize = DefaultReadBufferSize
|
|
|
|
}
|
|
|
|
|
|
|
|
if sh.WriteBufferSize <= 0 {
|
|
|
|
sh.WriteBufferSize = DefaultWriteBufferSize
|
|
|
|
}
|
|
|
|
}
|