hub

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

*

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HubSessions

func HubSessions(hub *Hub, w http.ResponseWriter, r *http.Request)

func ServeUDP

func ServeUDP(hub *Hub, conn *kcp.UDPSession)

func ServeWs

func ServeWs(hub *Hub, w http.ResponseWriter, r *http.Request)

serveWs handles websocket requests from the peer.

Types

type AvailableSession

type AvailableSession struct {
	ID              string `json:"id"`
	SessionHostName string `json:"name"`
	Size            int    `json:"size"`
}

type Client

type Client struct {
	Hub     *Hub
	Session *string
	Id      string
	Name    *string

	Socket ISocket
	Events map[string]*signals.Signal[[]byte]

	Ready bool
	// contains filtered or unexported fields
}

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

func (*Client) Close

func (c *Client) Close()

type ClientHandler

type ClientHandler interface {
	Close() error
	Write(p []byte) error
}

type ClientHubUDPWrapper

type ClientHubUDPWrapper struct {
	LastPing time.Time
	// contains filtered or unexported fields
}

func (ClientHubUDPWrapper) Close

func (c ClientHubUDPWrapper) Close() error

func (ClientHubUDPWrapper) Write

func (c ClientHubUDPWrapper) Write(p []byte) error

type ClientHubWSWrapper

type ClientHubWSWrapper struct {
	Conn *websocket.Conn
}

func (ClientHubWSWrapper) Close

func (c ClientHubWSWrapper) Close() error

func (ClientHubWSWrapper) Write

func (c ClientHubWSWrapper) Write(p []byte) error

type ClosedMessage

type ClosedMessage struct {
	Session string
}

type ConnectionOptions

type ConnectionOptions struct {
	UseCompression bool
	UseSSL         bool
	Proxy          func(*http.Request) (*url.URL, error)
	Subprotocols   []string
}

type Empty

type Empty struct {
}

type HostJoinMessage

type HostJoinMessage struct {
	Id      string
	Name    string
	Session string
}

type Hub

type Hub struct {
	// Registered clients.
	Clients        map[*Client]bool
	IdClients      map[string]*Client
	SessionManager *SessionManager

	// Register requests from the clients.
	Register chan *Client

	// Unregister requests from clients.
	Unregister chan *Client
	// contains filtered or unexported fields
}

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

func NewHub

func NewHub() *Hub

func (*Hub) Handle

func (h *Hub) Handle(message *SessionMessage, reply *string) error

func (*Hub) Run

func (h *Hub) Run()

type ISocket

type ISocket interface {
	SocketHandler() *SocketHandler
	Connect()
	Close()
	SendBinary(messageType int, data []byte)
	IsConnected() bool
}

func NewKcpSocket

func NewKcpSocket(mutex *sync.Mutex, conn *kcp.UDPSession) ISocket

func NewWebSocket

func NewWebSocket(mutex *sync.Mutex, conn websocket.Conn) ISocket

type KcpSocket

type KcpSocket struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

func (KcpSocket) Close

func (socket KcpSocket) Close()

func (KcpSocket) Connect

func (socket KcpSocket) Connect()

func (KcpSocket) IsConnected

func (socket KcpSocket) IsConnected() bool

func (KcpSocket) SendBinary

func (socket KcpSocket) SendBinary(messageType int, data []byte)

func (KcpSocket) SocketHandler

func (socket KcpSocket) SocketHandler() *SocketHandler

type LeavingMessage

type LeavingMessage struct {
	Id string
}

type MembersMessage

type MembersMessage struct {
	Session string
}

type MembersMessageResponse

type MembersMessageResponse struct {
	Members map[string]*string
	Host    string
}

type ReconnectionOptions

type ReconnectionOptions struct {
}

todo Yet to be done

type RegisteredMessage

type RegisteredMessage struct {
	Id string
}

type Session

type Session struct {
	Id           string
	Host         *Client
	Participants map[*Client]bool
}

func NewSession

func NewSession(id string, host *Client) *Session

type SessionManager

type SessionManager struct {
	Sessions map[string]*Session
	// contains filtered or unexported fields
}

func NewSessionManager

func NewSessionManager(h *Hub) *SessionManager

func (*SessionManager) CloseSession

func (sessionManager *SessionManager) CloseSession(targetSession string)

func (*SessionManager) Host

func (sessionManager *SessionManager) Host(message *HostJoinMessage, reply *string) error

func (*SessionManager) Join

func (sessionManager *SessionManager) Join(message *HostJoinMessage, reply *string) error

func (*SessionManager) LeaveSession

func (sessionManager *SessionManager) LeaveSession(targetParticipantId string, targetSession string)

func (*SessionManager) Members

func (sessionManager *SessionManager) Members(message *MembersMessage, reply *MembersMessageResponse) error

type SessionMessage

type SessionMessage struct {
	Session string
	Sender  string
	Channel string
	Target  *string
	Message string
}

type Socket

type Socket struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

func (Socket) Close

func (socket Socket) Close()

func (Socket) Connect

func (socket Socket) Connect()

func (Socket) EnableLogging

func (socket Socket) EnableLogging()

func (Socket) GetLogger

func (socket Socket) GetLogger() logging.Logger

func (Socket) IsConnected

func (socket Socket) IsConnected() bool

func (Socket) SendBinary

func (socket Socket) SendBinary(messageType int, data []byte)

func (Socket) SocketHandler

func (socket Socket) SocketHandler() *SocketHandler

type SocketHandler

type SocketHandler struct {
	OnConnected     func(socket interface{})
	OnTextMessage   func(message string, socket interface{})
	OnBinaryMessage func(data []byte, socket interface{})
	OnConnectError  func(err error, socket interface{})
	OnDisconnected  func(err error, socket interface{})
	OnPingReceived  func(data string, socket interface{})
	OnPongReceived  func(data string, socket interface{})
}

Jump to

Keyboard shortcuts

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