server

package
v0.0.0-...-9cd51db Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn is a middleman between the connection and the hub.

func (*Conn) AddCloseHandler

func (c *Conn) AddCloseHandler(handler func())

AddCloseHandler adds the close handler, they will be triggered when the conn was closed.

func (*Conn) BroadcastMessage

func (c *Conn) BroadcastMessage(msg []byte, room string)

BroadcastMessage broadcast the message to clients in the specified room.

func (*Conn) Close

func (c *Conn) Close()

Close the connection.

func (*Conn) JoinRoom

func (c *Conn) JoinRoom(newRoom string)

JoinRoom joins the client into a new room

func (*Conn) Room

func (c *Conn) Room() string

Room returns the name of room in current connection.

func (*Conn) SendMessage

func (c *Conn) SendMessage(msg []byte)

SendMessage sends a message to current client.

func (*Conn) SetOfflineHandler

func (c *Conn) SetOfflineHandler(handler func())

SetOfflineHandler sets the offline handler when will be triggered when the client is offline.

func (*Conn) SetUserID

func (c *Conn) SetUserID(userID string)

SetUserID sets the UserID to current connection.

func (*Conn) UserID

func (c *Conn) UserID() string

UserID returns the UserID in current connection.

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the client connections.

type Response

type Response struct {
	Success bool        `json:"success"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

Response represents the response of REST API.

func NewErrorResponse

func NewErrorResponse(message string) Response

NewErrorResponse creates an error response.

func NewSuccessResponse

func NewSuccessResponse(message string, data interface{}) Response

NewSuccessResponse creates a success response.

type Server

type Server interface {
	// ListenAndServe listens on the specified address and serves the Presence Server.
	ListenAndServe(addr string, certFile string, keyFile string) error

	// SetReadMessageHandler sets the handler when receiving the messages.
	SetReadMessageHandler(handler func(c *Conn, msg []byte))

	// BroadcastMessage broadcast the message to clients in the specified room.
	BroadcastMessage(msg []byte, room string)
}

Server is an interface for Presence Server.

func NewServer

func NewServer(defaultRoom string) Server

NewServer creates a new Presence Server.

type WebSocketConn

type WebSocketConn struct {
	*Conn
	// contains filtered or unexported fields
}

WebSocketConn is a middleman between the websocket connection and the hub.

type WebTransportConn

type WebTransportConn struct {
	*Conn
	// contains filtered or unexported fields
}

WebTransportConn is a middleman between the webtransport connection and the hub.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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