pubsub

package module
v0.0.0-...-0cff4e4 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Authorized bool            `json:"authorized"`
	Closed     bool            `json:"-"`
	Id         string          `json:"id"`
	Topics     []string        `json:"topics"`
	Connection *websocket.Conn `json:"-"`
	Mutex      sync.Mutex      `json:"-"`
}

func (*Client) SendMessage

func (client *Client) SendMessage(msg []byte)

type PubSub

type PubSub struct {
	TotalClients int                  `json:"totalClients"`
	TotalTopics  int                  `json:"totalTopics"`
	Clients      []*Client            `json:"clients"`
	Topics       map[string][]*Client `json:"topics"`
}

func New

func New() PubSub

func (*PubSub) AddClient

func (ps *PubSub) AddClient(client *Client) *PubSub

func (*PubSub) PublishBytes

func (ps *PubSub) PublishBytes(topic string, msg []byte)

func (*PubSub) PublishJSON

func (ps *PubSub) PublishJSON(topic string, msg any)

func (*PubSub) PublishString

func (ps *PubSub) PublishString(topic string, msg string)

func (*PubSub) RemoveClient

func (ps *PubSub) RemoveClient(client *Client) *PubSub

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(client *Client, topic string) *Client

func (*PubSub) Unsubscribe

func (ps *PubSub) Unsubscribe(client *Client, topic string)

type PubSubMessage

type PubSubMessage struct {
	Command string                 `json:"command,omitonempty"`
	Room    string                 `json:"room,omitonempty"`
	Message string                 `json:"data,omitonempty"`
	Params  map[string]interface{} `json:"params,omitonempty"`
}

Jump to

Keyboard shortcuts

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