websocket

package
v1.2.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OnConnectHandlers = make([]Handler2, 0)
	OnCloseHandlers   = make([]Handler2, 0)

	Byte2Pb  = make([]PbType, 0)
	Pb2Bytes = make([]PbType2, 0)
)

路由器的处理映射

Functions

This section is empty.

Types

type Handler

type Handler func(conn *WebsocketData, req any) (err error)

定义一个处理方法的类型

type Handler2 added in v1.2.11

type Handler2 func(conn *WebsocketData)

type HandlerMessage added in v1.2.11

type HandlerMessage func(conn *WebsocketData, req any)

type PbType added in v1.2.11

type PbType func(cmd int32, data []byte, code int32, msg string) proto.Message

type PbType2 added in v1.2.11

type PbType2 func(data []byte) (int, []byte)

type SocketInterface

type SocketInterface interface {
	Load(serv *ghttp.Server, prefix string)
	OnConnect(ctx context.Context, conn *websocket.Conn)
	OnMessage(conn *WebsocketData, req []byte, msgType int)
	Send(cmd int32, uid int64, req proto.Message)
	SendAll(cmd int32, req proto.Message)
	OnClose(conn *WebsocketData)
}

type SocketV1

type SocketV1 struct {
	Type int `json:"type"`
}

func NewV1

func NewV1() *SocketV1

func (*SocketV1) BindUid added in v1.2.11

func (s *SocketV1) BindUid(conn *WebsocketData, uid int64)

绑定用户编号

func (*SocketV1) IsOnline added in v1.2.11

func (s *SocketV1) IsOnline(uid int64) bool

是否在线

func (*SocketV1) Load

func (s *SocketV1) Load(serv *ghttp.Server, prefix string)

func (*SocketV1) OnClose

func (s *SocketV1) OnClose(conn *WebsocketData)

OnClose

@Description:
@receiver s
@param conn

func (*SocketV1) OnConnect

func (s *SocketV1) OnConnect(ctx context.Context, conn *websocket.Conn)

OnConnect

@Description:
@receiver s
@param conn

func (*SocketV1) OnMessage

func (s *SocketV1) OnMessage(conn *WebsocketData, req []byte, msgType int)

OnMessage

@Description:
@receiver s
@param msg
@param msgType

func (*SocketV1) RegisterByte2Pb added in v1.2.11

func (s *SocketV1) RegisterByte2Pb(_func PbType)

func (*SocketV1) RegisterMessage added in v1.2.11

func (s *SocketV1) RegisterMessage(_func HandlerMessage)

注册方法长连接消息体

func (*SocketV1) RegisterOnClose added in v1.2.10

func (s *SocketV1) RegisterOnClose(_func Handler2)

func (*SocketV1) RegisterOnConnect added in v1.2.10

func (s *SocketV1) RegisterOnConnect(_func Handler2)

注册方法,讲长连接登陆方法进行注册

func (*SocketV1) RegisterPb2Byte added in v1.2.11

func (s *SocketV1) RegisterPb2Byte(_func PbType2)

func (*SocketV1) RegisterRouter

func (s *SocketV1) RegisterRouter(cmd int, handler Handler)

注册方法,将某个消息路由器ID和对应的处理方法关联起来

func (*SocketV1) Send

func (s *SocketV1) Send(cmd int32, uid int64, req proto.Message)

Send

@Description:
@receiver s
@param uid
@param data

func (*SocketV1) SendAll

func (s *SocketV1) SendAll(cmd int32, req proto.Message)

批量发送

func (*SocketV1) SendUuid added in v1.2.11

func (s *SocketV1) SendUuid(cmd int32, id uuid.UUID, req proto.Message)

SendUuid

@Description:
@receiver s
@param uid
@param data

func (*SocketV1) Uid2Uuid added in v1.2.11

func (s *SocketV1) Uid2Uuid(uid int64) (uuid string)

Uid2Uuid 用户编号转uuid唯一标识

func (*SocketV1) UnBindUid added in v1.2.11

func (s *SocketV1) UnBindUid(uid int64)

解绑用户

type WebsocketData

type WebsocketData struct {
	Ws     *websocket.Conn
	Uuid   string
	Uid    int64
	Ctx    context.Context
	RoomId int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL