s2

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultProtocol

type DefaultProtocol struct{}

Simple, but working binary codec

func NewDefaultProtocol

func NewDefaultProtocol() DefaultProtocol

func (DefaultProtocol) ReadMessage

func (DefaultProtocol) ReadMessage(dest *Message, r io.Reader) error

func (DefaultProtocol) WriteMessage

func (DefaultProtocol) WriteMessage(w io.Writer, src Message) error

type IncomingMessage

type IncomingMessage struct {
	Sender *Session
	Path   string
	Data   []byte
}

type Message

type Message struct {
	IsRoom bool
	Room   string
	Path   string
	Data   []byte
}

type MessageHandler

type MessageHandler func(ctx context.Context, msg IncomingMessage)

type MessageProtocol

type MessageProtocol interface {
	ReadMessage(dest *Message, r io.Reader) error
	WriteMessage(w io.Writer, src Message) error
}

type Room

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

func (*Room) Assign

func (r *Room) Assign(s *Session)

func (*Room) Broadcast

func (r *Room) Broadcast(path string, data []byte) error

func (*Room) BroadcastExcept

func (r *Room) BroadcastExcept(path string, data []byte, exceptions []string) error

func (*Room) Destroy

func (r *Room) Destroy()

func (*Room) GetMember

func (r *Room) GetMember(sessionId string) (*Session, bool)

func (*Room) HasMember

func (r *Room) HasMember(sessionId string) bool

func (*Room) ID

func (r *Room) ID() string

func (*Room) MemberCount

func (r *Room) MemberCount() int

func (*Room) MemberIDs

func (r *Room) MemberIDs() []string

func (*Room) Members

func (r *Room) Members() []*Session

func (*Room) MembersIter

func (r *Room) MembersIter() iter.Seq2[string, *Session]

func (*Room) OnCreate

func (r *Room) OnCreate(f func(ctx context.Context))

func (*Room) OnDestroy

func (r *Room) OnDestroy(f func())

func (*Room) OnJoin

func (r *Room) OnJoin(f func(s *Session))

func (*Room) OnLeave

func (r *Room) OnLeave(f func(s *Session))

func (*Room) SetRouter

func (r *Room) SetRouter(router *Router)

func (*Room) Unassign

func (r *Room) Unassign(s *Session)

type RoomFactory

type RoomFactory func(r *Room)

type Router

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

func NewRouter

func NewRouter() *Router

func NewRouterWithSep

func NewRouterWithSep(sep string) *Router

func (*Router) Handle

func (r *Router) Handle(route string, handler MessageHandler)

func (*Router) HandleFallback

func (r *Router) HandleFallback(handler MessageHandler)

type Server

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

func NewServer

func NewServer(addres string, tlsCfg *tls.Config, quicCfg *quic.Config, idGenerator func() string, protocol MessageProtocol) *Server

func (*Server) Close

func (s *Server) Close() error

func (*Server) CreateRoom

func (s *Server) CreateRoom(ctx context.Context, typ string) (*Room, error)

func (*Server) RegisterRoomFactory

func (s *Server) RegisterRoomFactory(typ string, f RoomFactory)

func (*Server) SetRouter

func (s *Server) SetRouter(r *Router)

func (*Server) Start

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

type Session

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

func (*Session) Close

func (s *Session) Close(code quic.ApplicationErrorCode, reason string) error

func (*Session) ID

func (s *Session) ID() string

func (*Session) Send

func (s *Session) Send(path string, data []byte) error

Directories

Path Synopsis
example
client command
server command

Jump to

Keyboard shortcuts

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