room

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager manages multiple rooms.

func NewManager

func NewManager() *Manager

NewManager creates a new room Manager.

func (*Manager) Create

func (m *Manager) Create(id, name string) *Room

Create creates a new room.

func (*Manager) Delete

func (m *Manager) Delete(id string)

Delete removes a room.

func (*Manager) Get

func (m *Manager) Get(id string) (*Room, error)

Get retrieves a room by ID.

func (*Manager) Join

func (m *Manager) Join(roomID string, user core.User, conn ws.Conn) error

Join adds a user to a room, creating the room if it doesn't exist.

func (*Manager) JoinSession

func (m *Manager) JoinSession(roomID, sessionID string, user core.User, conn ws.Conn) error

JoinSession adds a specific session to a room, creating the room if it doesn't exist.

func (*Manager) Leave

func (m *Manager) Leave(roomID, userID string) error

Leave removes a user from a room.

func (*Manager) List

func (m *Manager) List() []core.RoomInfo

List returns all room infos.

type Room

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

Room represents a communication room with members.

func NewRoom

func NewRoom(id, name string) *Room

NewRoom creates a new room with the given ID and name.

func (*Room) AddMember

func (r *Room) AddMember(user core.User, conn ws.Conn) error

AddMember adds a user to the room.

func (*Room) AddMemberSession

func (r *Room) AddMemberSession(sessionID string, user core.User, conn ws.Conn) error

AddMemberSession adds a device/session to the room while keeping room member metadata unique by user.

func (*Room) Broadcast

func (r *Room) Broadcast(ctx context.Context, senderSessionID string, data []byte) error

Broadcast sends a message to all members except the sender.

func (*Room) ID

func (r *Room) ID() string

ID returns the room identifier.

func (*Room) MemberCount

func (r *Room) MemberCount() int

MemberCount returns the number of members in the room.

func (*Room) Members

func (r *Room) Members() []core.User

Members returns a copy of the room member list.

func (*Room) Name

func (r *Room) Name() string

Name returns the room name.

func (*Room) RemoveMember

func (r *Room) RemoveMember(sessionID string) error

RemoveMember removes a user from the room.

func (*Room) Send

func (r *Room) Send(ctx context.Context, userID string, data []byte) error

Send sends a message to a specific member.

type UserSession

type UserSession struct {
	SessionID string
	UserID    string
	Username  string
	DeviceID  string
	Conn      ws.Conn
	Rooms     map[string]bool
	Connected time.Time
	// contains filtered or unexported fields
}

UserSession tracks a user's connection and joined rooms.

func NewDeviceSession

func NewDeviceSession(sessionID, userID, username, deviceID string, conn ws.Conn) *UserSession

NewDeviceSession creates a new user session bound to a specific device/session identifier.

func NewUserSession

func NewUserSession(userID, username string, conn ws.Conn) *UserSession

NewUserSession creates a new user session.

func (*UserSession) AddRoom

func (s *UserSession) AddRoom(roomID string)

AddRoom tracks that the user joined a room.

func (*UserSession) RemoveRoom

func (s *UserSession) RemoveRoom(roomID string)

RemoveRoom tracks that the user left a room.

func (*UserSession) RoomIDs

func (s *UserSession) RoomIDs() []string

RoomIDs returns the list of rooms the user has joined.

Jump to

Keyboard shortcuts

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