websockets

package
v0.0.0-...-4da28bb Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	READSIZE  = 1024
	WRITESIZE = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Author  string `json:"author"`
	Content string `json:"content"`
}

type Room

type Room struct {
	Members []string
	Lock    sync.Mutex
}

type WSServer

type WSServer struct {
	Upgrader    websocket.Upgrader
	Connections map[string]*websocket.Conn
	Rooms       map[string][]string
}

func NewWSServer

func NewWSServer() *WSServer

func (*WSServer) Broadcast

func (ws *WSServer) Broadcast(user, room string, msg []byte)

func (*WSServer) Close

func (ws *WSServer) Close()

func (*WSServer) ConnectToRoom

func (ws *WSServer) ConnectToRoom(c echo.Context) error

func (*WSServer) GetRoom

func (ws *WSServer) GetRoom(c echo.Context) error

getroom is a function that takes a websocket connection and handles it

func (*WSServer) GracefulDisconnect

func (ws *WSServer) GracefulDisconnect(room, user string, conn *websocket.Conn)

func (*WSServer) SendError

func (ws *WSServer) SendError(user string, err error)

SendError is a function that takes a websocket connection and sends an error message

func (*WSServer) SubscribeNewUser

func (ws *WSServer) SubscribeNewUser(room string) uuid.UUID

Subscribe returns a unique id for the client to use to subscribe to the websocket

func (*WSServer) Unsubscribe

func (ws *WSServer) Unsubscribe(id uuid.UUID, room string)

Unsubscribe removes the client from the list of connections

func (*WSServer) WSHandler

func (ws *WSServer) WSHandler(c echo.Context) error

WSHandler is a function that takes a websocket connection and handles it

Jump to

Keyboard shortcuts

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