server

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const WebSocketConnUUIDCTXKey = "WebSocketConnUUIDCTXKey"

Variables

This section is empty.

Functions

func WebSocketMonitor

func WebSocketMonitor(m *Manager) (err error)

Types

type BaseTextMessageController

type BaseTextMessageController struct {
	Client       *Client
	Action       string
	ActionParams map[string]interface{}
}

func (*BaseTextMessageController) Init

func (*BaseTextMessageController) ParsePayload

func (b *BaseTextMessageController) ParsePayload(client *Client, message ReceiveMessage) (err error)

type Client

type Client struct {
	Ctx *gin.Context

	Conn *websocket.Conn

	// 客户端状态信息
	State State

	Logger *logit.Helper
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx *gin.Context, conn *websocket.Conn, r *WebSocketRouter, uuid string) *Client

func (*Client) Close

func (c *Client) Close()

func (*Client) DebugLog

func (c *Client) DebugLog(action string, messageType int, message []byte, err error, keyValues ...interface{})

func (*Client) ErrorLog

func (c *Client) ErrorLog(action string, messageType int, message []byte, err error, keyValues ...interface{})

func (*Client) InfoLog

func (c *Client) InfoLog(action string, messageType int, message []byte, err error, keyValues ...interface{})

func (*Client) ReadMessage

func (c *Client) ReadMessage() (messageType int, message []byte, err error)

func (*Client) WarnLog

func (c *Client) WarnLog(action string, messageType int, message []byte, err error, keyValues ...interface{})

func (*Client) WriteTextMessage

func (c *Client) WriteTextMessage(message []byte) (err error)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) Delete

func (m *Manager) Delete(uuid string)

func (*Manager) IsExist

func (m *Manager) IsExist(uuid string) bool

func (*Manager) Len

func (m *Manager) Len() int

func (*Manager) Range

func (m *Manager) Range(f func(key, value any) bool)

func (*Manager) Store

func (m *Manager) Store(uuid string, c *Client)

type ReceiveMessage

type ReceiveMessage struct {
	Scene        string                 `json:"scene"`
	SceneParams  map[string]interface{} `json:"sceneParams"`
	Action       string                 `json:"action"`
	ActionParams map[string]interface{} `json:"actionParams"`
}
{
	"scene": "test",
	"sceneParams": {
		"key1": 1234,
		"key2": "value"
	},
	"action": "test",
	"actionParams": {
		"key1": 1234,
		"key2": "value"
	}
}

type State

type State struct {
	Scene       string
	SceneParams map[string]interface{}
}

type Task

type Task func(*Manager) (err error)

type TextMessageController

type TextMessageController interface {
	Init(base TextMessageController)
	ParsePayload(c *Client, message ReceiveMessage) error
	Process() error
}

type WebSocketRouter

type WebSocketRouter struct {
	ClientManager *Manager
	// contains filtered or unexported fields
}

func NewWebSocketRouter

func NewWebSocketRouter(path string) *WebSocketRouter

func (*WebSocketRouter) AddMiddleware

func (r *WebSocketRouter) AddMiddleware(m gin.HandlerFunc)

func (*WebSocketRouter) AddTask

func (r *WebSocketRouter) AddTask(t Task)

func (*WebSocketRouter) GetTasks

func (r *WebSocketRouter) GetTasks() []func(context.Context) func() error

func (*WebSocketRouter) GetTextMessageController

func (r *WebSocketRouter) GetTextMessageController(scene string) (controller TextMessageController, err error)

func (*WebSocketRouter) OnTextMessageController

func (r *WebSocketRouter) OnTextMessageController(scene string, controller TextMessageController)

func (*WebSocketRouter) RegisterHandler

func (r *WebSocketRouter) RegisterHandler(s *server.Server)

func (*WebSocketRouter) SetAuthorization

func (r *WebSocketRouter) SetAuthorization(f func(ctx *gin.Context) bool)

func (*WebSocketRouter) SetClientCloseFunc

func (r *WebSocketRouter) SetClientCloseFunc(f func(uuidStr string))

Jump to

Keyboard shortcuts

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