websocket

package
v0.0.0-...-360c0eb Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddClient

func AddClient(app string, client *melody.Session, clientID string, token string, data map[string]any)

AddClient 添加客户端

func EventOffline

func EventOffline(clientId string) error

EventOffline 客户端离线

func EventOnline

func EventOnline(clientId string) error

EventOnline 客户端在线

func EventPing

func EventPing(clientId string) error

EventPing ping客户端

func Init

func Init()

func Push

func Push(channels []string, data map[string]any)

Push 发布频道消息

func RemoveClient

func RemoveClient(clientID string)

RemoveClient 移除客户端

func RemoveConnClient

func RemoveConnClient(conn *melody.Session)

RemoveConnClient 移除客户端

func SendClient

func SendClient(clientID string, message map[string]any) error

SendClient 给客户端发消息

Types

type Agent

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

type Channel

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

Channel 频道映射

type Client

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

Client 客户端映射

func GetClient

func GetClient(clientID string) (*Client, error)

GetClient 获取客户端

func (*Client) Send

func (p *Client) Send(data map[string]any)

Send 发布频道消息

func (*Client) Sub

func (p *Client) Sub(channels ...string) error

Sub 订阅频道

func (*Client) Unsub

func (p *Client) Unsub(args ...string)

Unsub 取消订阅频道

type Message

type Message struct {
	Id      string `json:"id"`
	Type    string `json:"type"`
	Client  string `json:"client,omitempty"`
	Channel string `json:"channel"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
	Meta    any    `json:"meta,omitempty"`
}

type ServiceT

type ServiceT struct {
	Websocket *melody.Melody
	Clients   *sync.Map
	Channels  *sync.Map
	Agents    map[string]*Agent
}
var Service *ServiceT

func New

func New() *ServiceT

func (*ServiceT) RegisterAgents

func (t *ServiceT) RegisterAgents(name string, agent *Agent)

func (*ServiceT) Run

func (t *ServiceT) Run()

Jump to

Keyboard shortcuts

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