chat

package
v0.0.0-...-f5c9fec Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 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 struct {
	// The clients of *Server.
	Server *Server

	// The unique id of the successfully bound business.
	ClientId string
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the Server.

func (*Client) Send

func (s *Client) Send(msg *Message)

type Message

type Message struct {
	Type    int    // message type
	Content []byte // message content, used to accept or send
}

type Server

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

Server maintains the set of active clients and broadcasts messages to the clients.

func NewServer

func NewServer(
	upgrade *websocket.Upgrader,
	slg *slog.Logger,
	handleMessage func(client *Client, msg *Message),
) *Server

func (*Server) Broadcast

func (s *Server) Broadcast(messageType int, message []byte)

func (*Server) CallBind

func (s *Server) CallBind(client *Client)

func (*Server) CallUnbind

func (s *Server) CallUnbind(client *Client)

func (*Server) GetClientById

func (s *Server) GetClientById(id string) (client *Client)

func (*Server) PushByIds

func (s *Server) PushByIds(messageType int, message []byte, ids ...string)

PushByIds send a message to the client (the client needs to bind a client-id)

func (*Server) Start

func (s *Server) Start(ctx context.Context)

Start the service starts

func (*Server) Upgrade

func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header, callback func(client *Client))

Upgrade connectivity upgrades

Jump to

Keyboard shortcuts

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