websocket

package
v0.0.0-...-4165e32 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 7 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 map[string]*websocket.Conn

Client is a type that describe the clients' ID and their connection

type Handler

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

func NewHandler

func NewHandler(server *Server) *Handler

func (*Handler) HandleWS

func (handler *Handler) HandleWS(w http.ResponseWriter, r *http.Request)

type Message

type Message struct {
	Action  string `json:"action"`
	Topic   string `json:"topic"`
	Message string `json:"message"`
}

Message is a struct for message to be sent by the client

type Server

type Server struct {
	Subscriptions Subscription
}

Server is the struct to handle the Server functions & manage the Subscriptions

func (*Server) ProcessMessage

func (s *Server) ProcessMessage(conn *websocket.Conn, clientID string, msg []byte) *Server

ProcessMessage handle message according to the action type

func (*Server) Publish

func (s *Server) Publish(topic string, message []byte)

Publish sends a message to all subscribing clients of a topic

func (*Server) RemoveClient

func (s *Server) RemoveClient(clientID string)

RemoveClient removes the clients from the server subscription map

func (*Server) Send

func (s *Server) Send(conn *websocket.Conn, message string)

Send simply sends message to the websocket client

func (*Server) SendWithWait

func (s *Server) SendWithWait(conn *websocket.Conn, message string, wg *sync.WaitGroup)

SendWithWait sends message to the websocket client using wait group, allowing usage with goroutines

func (*Server) Subscribe

func (s *Server) Subscribe(conn *websocket.Conn, clientID string, topic string)

Subscribe adds a client to a topic's client map

func (*Server) Unsubscribe

func (s *Server) Unsubscribe(clientID string, topic string)

Unsubscribe removes a clients from a topic's client map

type Subscription

type Subscription map[string]Client

Subscription is a type for each string of topic and the clients that subscribe to it

Jump to

Keyboard shortcuts

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