channels

package
v0.0.0-...-eec4d16 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WebSocket        = "WS"
	ServerSentEvents = "SSE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

type Channel struct {
	ID     string         `json:"id"`
	Config *ChannelConfig `json:"config"`
	Type   string         `json:"type"`
	// contains filtered or unexported fields
}

func NewChannel

func NewChannel(dto *dtos.CreateChannelDTO, consumer ConsumerAdapter, producer ProducerAdapter) (*Channel, error)

func (*Channel) AddClient

func (c *Channel) AddClient(client *Client)

func (*Channel) BroadcastMessage

func (c *Channel) BroadcastMessage(m *Message) error

func (*Channel) DeleteClient

func (c *Channel) DeleteClient(client *Client)

func (*Channel) HasClient

func (c *Channel) HasClient(client *Client) bool

func (*Channel) IsMaxOfConnections

func (c *Channel) IsMaxOfConnections() bool

func (*Channel) Subscribe

func (c *Channel) Subscribe(client *Client) error

type ChannelConfig

type ChannelConfig struct {
	MaxOfChannelConnections int `json:"maxOfChannelConnections"`
}

type Client

type Client struct {
	ID        string `json:"id"`
	ChannelID string `json:"channelId"`
	UserAgent string `json:"userAgent"`
	IPAddress string `json:"ipAddress"`
	// contains filtered or unexported fields
}

func NewClient

func NewClient(dto *dtos.CreateClientDTO) *Client

func (*Client) MessageChan

func (c *Client) MessageChan() chan *Message

type ConsumerAdapter

type ConsumerAdapter interface {
	Subscribe(client *Client) error
}

type Message

type Message struct {
	ID        string    `json:"id"`
	ChannelID string    `json:"channelId"`
	ClientID  string    `json:"clientId"`
	Payload   string    `json:"payload"`
	CreatedAt time.Time `json:"createdAt"`
}

func MessageFromJSON

func MessageFromJSON(message string) (*Message, error)

func NewMessage

func NewMessage(channelID string, clientID string, payload string) *Message

func (*Message) MessageToJSON

func (m *Message) MessageToJSON() (string, error)

type ProducerAdapter

type ProducerAdapter interface {
	Send(message *Message) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳