Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Connection
- type ConnectionFunc
- type ConnectionValues
- type DisconnectFunc
- type Emitter
- type ErrorFunc
- type LeaveRoomFunc
- type MessageFunc
- type NativeMessageFunc
- type PingFunc
- type PongFunc
- type Server
- func (s *Server) Disconnect(connID string) (err error)
- func (s *Server) GetConnection(connID string) Connection
- func (s *Server) GetConnections() []Connection
- func (s *Server) GetConnectionsByRoom(roomName string) []Connection
- func (s *Server) GetTotalConnections() (n int)
- func (s *Server) Handler() func(ctx *gin.Context)
- func (s *Server) IsConnected(connID string) bool
- func (s *Server) IsJoined(roomName string, connID string) bool
- func (s *Server) Join(roomName string, connID string)
- func (s *Server) Leave(roomName string, connID string) bool
- func (s *Server) LeaveAll(connID string)
- func (s *Server) OnConnection(cb ConnectionFunc)
- func (s *Server) Upgrade(ctx *gin.Context) Connection
- type UnderlineConnection
Constants ¶
View Source
const ( DefaultWebsocketWriteTimeout = 0 DefaultWebsocketReadTimeout = 0 DefaultWebsocketPongTimeout = 60 * time.Second DefaultWebsocketPingPeriod = (DefaultWebsocketPongTimeout * 9) / 10 DefaultWebsocketMaxMessageSize = 1024 DefaultWebsocketReadBufferSize = 4096 DefaultWebsocketWriterBufferSize = 4096 DefaultEvtMessageKey = "gin-websocket-message:" )
View Source
const ( All = "" Broadcast = ";to;all;except;me;" )
View Source
const CloseMessage = websocket.CloseMessage
View Source
const WriteWait = 1 * time.Second
Variables ¶
View Source
var ClientSource []byte
View Source
var ( DefaultIDGenerator = func(*gin.Context) string { id, err := uuid.NewV4() if err != nil { return randomString(64) } return id.String() } )
View Source
var ErrAlreadyDisconnected = errors.New("already disconnected")
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { IDGenerator func(ctx *gin.Context) string EvtMessagePrefix []byte Error func(w http.ResponseWriter, r *http.Request, status int, reason error) CheckOrigin func(r *http.Request) bool HandshakeTimeout time.Duration WriteTimeout time.Duration ReadTimeout time.Duration PongTimeout time.Duration PingPeriod time.Duration MaxMessageSize int64 BinaryMessages bool ReadBufferSize int WriteBufferSize int EnableCompression bool Subprotocols []string }
type Connection ¶
type Connection interface { Emitter Err() error ID() string Server() *Server Write(websocketMessageType int, data []byte) error Context() *gin.Context OnDisconnect(DisconnectFunc) OnError(ErrorFunc) OnPing(PingFunc) OnPong(PongFunc) FireOnError(err error) To(string) Emitter OnMessage(NativeMessageFunc) On(string, MessageFunc) Join(string) IsJoined(roomName string) bool Leave(string) bool OnLeave(roomLeaveCb LeaveRoomFunc) Wait() Disconnect() error SetValue(key string, value any) GetValue(key string) any GetValueArrString(key string) []string GetValueString(key string) string GetValueInt(key string) int }
Connection 接口
type ConnectionFunc ¶
type ConnectionFunc func(Connection)
type ConnectionValues ¶
type ConnectionValues []connectionValue
func (*ConnectionValues) Get ¶
func (r *ConnectionValues) Get(key string) any
func (*ConnectionValues) Reset ¶
func (r *ConnectionValues) Reset()
func (*ConnectionValues) Set ¶
func (r *ConnectionValues) Set(key string, value any)
type DisconnectFunc ¶
type DisconnectFunc func()
type LeaveRoomFunc ¶
type LeaveRoomFunc func(roomName string)
type MessageFunc ¶
type MessageFunc any
type NativeMessageFunc ¶
type NativeMessageFunc func([]byte)
type Server ¶
type Server struct { ClientSource []byte // contains filtered or unexported fields }
func NewWSServer ¶
func (*Server) Disconnect ¶
func (*Server) GetConnection ¶
func (s *Server) GetConnection(connID string) Connection
func (*Server) GetConnections ¶
func (s *Server) GetConnections() []Connection
func (*Server) GetConnectionsByRoom ¶
func (s *Server) GetConnectionsByRoom(roomName string) []Connection
func (*Server) GetTotalConnections ¶
func (*Server) IsConnected ¶
func (*Server) OnConnection ¶
func (s *Server) OnConnection(cb ConnectionFunc)
type UnderlineConnection ¶
type UnderlineConnection interface { SetWriteDeadline(t time.Time) error SetReadDeadline(t time.Time) error SetReadLimit(limit int64) SetPongHandler(h func(appData string) error) SetPingHandler(h func(appData string) error) WriteControl(messageType int, data []byte, deadline time.Time) error WriteMessage(messageType int, data []byte) error ReadMessage() (messageType int, p []byte, err error) NextWriter(messageType int) (io.WriteCloser, error) Close() error }
Click to show internal directories.
Click to hide internal directories.