room

package
v0.0.0-...-0db0fbe Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastError

type BroadcastError struct {
	//Err raw error.
	Err error
	//Conn connections in which error raised.
	Conn connections.OutputConnection
	//Room room in which error raised.
	Room *Room
}

BroadcastError room broadcast error

func (*BroadcastError) Error

func (e *BroadcastError) Error() string

type Joinable

type Joinable interface {
	Join(roomid string, conn connections.OutputConnection)
	Leave(roomid string, conn connections.OutputConnection)
}

Joinable interfacer for which can joined as room manager.

type Location

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

Location room data of user.

func NewLocation

func NewLocation(conn connections.OutputConnection, rooms Joinable) *Location

NewLocation create new loction with given connection and rooms.

func (*Location) Join

func (l *Location) Join(roomid string)

Join join user to given room

func (*Location) Leave

func (l *Location) Leave(roomid string)

Leave leave from given room.

func (*Location) LeaveAll

func (l *Location) LeaveAll()

LeaveAll Leave from all rooms.

func (*Location) Rooms

func (l *Location) Rooms() []string

Rooms list all rooms user joined.

type Room

type Room struct {
	ID    string
	Lock  sync.Mutex
	Conns *list.List
}

Room connection room in which all connections will receive broadcast.

func NewRoom

func NewRoom() *Room

NewRoom create new room.

func (*Room) Broadcast

func (r *Room) Broadcast(msg []byte, errHandler func(error))

Broadcast broadcast message to all connection in room. Return BroadcastError if any error raised.

func (*Room) Join

func (r *Room) Join(conn connections.OutputConnection) bool

Join join connection to room.

func (*Room) Leave

func (r *Room) Leave(conn connections.OutputConnection) bool

Leave leave connection from room.

func (*Room) Members

func (r *Room) Members() []connections.OutputConnection

Members list room connections.

type Rooms

type Rooms struct {
	Rooms sync.Map
	Lock  sync.Mutex
}

Rooms rooms manager

func NewRooms

func NewRooms() *Rooms

NewRooms create new rooms manager.

func (*Rooms) Broadcast

func (r *Rooms) Broadcast(roomid string, msg []byte, errHandler func(err error))

Broadcast brodcat message to give room. BroadcastError will be sent to Error chan if any error raised.

func (*Rooms) Join

func (r *Rooms) Join(roomid string, conn connections.OutputConnection)

Join join connection to room by given room id. Auto create room if not exists.

func (*Rooms) Leave

func (r *Rooms) Leave(roomid string, conn connections.OutputConnection)

Leave leave connection form room by give room id. Auto remove room if root empty.

func (*Rooms) Members

func (r *Rooms) Members(roomid string) []connections.OutputConnection

Members list connections in room by given room id.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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