room

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoomIDEmpty        = errors.New("roomid is empty")
	ErrAdminPassWordEmpty = errors.New("admin password is empty")
)
View Source
var (
	ErrUsernameEmpty     = errors.New("user name is empty")
	ErrUserPasswordEmpty = errors.New("user password is empty")
)
View Source
var (
	ErrAlreadyClosed = fmt.Errorf("already closed")
)

Functions

This section is empty.

Types

type BaseMovie

type BaseMovie struct {
	Url        string              `json:"url"`
	Name       string              `json:"name"`
	Live       bool                `json:"live"`
	Proxy      bool                `json:"proxy"`
	RtmpSource bool                `json:"rtmpSource"`
	Type       string              `json:"type"`
	Headers    map[string][]string `json:"headers"`
}

type BroadcastConf

type BroadcastConf func(*broadcastMessage)

func WithIgnoreID

func WithIgnoreID(id ...string) BroadcastConf

func WithSendToSelf

func WithSendToSelf() BroadcastConf

func WithSender

func WithSender(sender string) BroadcastConf

type Client

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

func NewClient

func NewClient(user *User, conn *websocket.Conn) (*Client, error)

func (*Client) Broadcast

func (c *Client) Broadcast(msg Message, conf ...BroadcastConf)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Closed

func (c *Client) Closed() bool

func (*Client) GetReadChan

func (c *Client) GetReadChan() <-chan Message

func (*Client) NextReader

func (c *Client) NextReader() (int, io.Reader, error)

func (*Client) NextWriter

func (c *Client) NextWriter(messageType int) (io.WriteCloser, error)

func (*Client) Room

func (c *Client) Room() *Room

func (*Client) Send

func (c *Client) Send(msg Message) error

func (*Client) Unregister

func (c *Client) Unregister() error

func (*Client) User

func (c *Client) User() *User

func (*Client) Username

func (c *Client) Username() string

type Current

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

func (*Current) MarshalJSON

func (c *Current) MarshalJSON() ([]byte, error)

func (*Current) Movie

func (c *Current) Movie() MovieInfo

func (*Current) SetMovie

func (c *Current) SetMovie(movie MovieInfo)

func (*Current) SetSeek added in v0.2.0

func (c *Current) SetSeek(seek, timeDiff float64) Status

func (*Current) SetSeekRate

func (c *Current) SetSeekRate(seek, rate, timeDiff float64) Status

func (*Current) SetStatus

func (c *Current) SetStatus(playing bool, seek, rate, timeDiff float64) Status

func (*Current) Status

func (c *Current) Status() Status

type ElementMessage

type ElementMessage struct {
	Type      ElementMessageType `json:"type" yaml:"type"`
	Sender    string             `json:"sender,omitempty" yaml:"sender,omitempty"`
	Message   string             `json:"message,omitempty" yaml:"message,omitempty"`
	Seek      float64            `json:"seek,omitempty" yaml:"seek,omitempty"`
	Rate      float64            `json:"rate,omitempty" yaml:"rate,omitempty"`
	Current   *Current           `json:"current,omitempty" yaml:"current,omitempty"`
	PeopleNum int64              `json:"peopleNum,omitempty" yaml:"peopleNum,omitempty"`
	Time      int64              `json:"time,omitempty" yaml:"time,omitempty"`
}

func (*ElementMessage) Encode

func (em *ElementMessage) Encode(wc io.Writer) error

func (*ElementMessage) MessageType

func (em *ElementMessage) MessageType() int

func (*ElementMessage) String

func (em *ElementMessage) String() string

type ElementMessageType

type ElementMessageType int
const (
	Error ElementMessageType = iota + 1
	ChatMessage
	Play
	Pause
	CheckSeek
	TooFast
	TooSlow
	ChangeRate
	ChangeSeek
	ChangeCurrent
	ChangeMovieList
	ChangePeopleNum
)

type FormatErrMovieAlreadyExist

type FormatErrMovieAlreadyExist uint64

func (FormatErrMovieAlreadyExist) Error

type FormatErrMovieNotFound

type FormatErrMovieNotFound uint64

func (FormatErrMovieNotFound) Error

func (e FormatErrMovieNotFound) Error() string

type Message

type Message interface {
	MessageType() int
	String() string
	Encode(wc io.Writer) error
}

type Movie

type Movie struct {
	BaseMovie
	PullKey    string `json:"pullKey"`
	CreateAt   int64  `json:"createAt"`
	LastEditAt int64  `json:"lastEditAt"`
	// contains filtered or unexported fields
}

Url will be `PullKey` when Live and Proxy are true

func NewMovie

func NewMovie(id uint64, url, name, type_ string, live, proxy, rtmpSource bool, headers map[string][]string, conf ...MovieConf) (*Movie, error)

func NewMovieWithBaseMovie

func NewMovieWithBaseMovie(id uint64, baseMovie BaseMovie, conf ...MovieConf) (*Movie, error)

func (*Movie) Channel

func (m *Movie) Channel() *rtmps.Channel

func (*Movie) Check

func (m *Movie) Check() error

func (*Movie) Creator

func (m *Movie) Creator() *User

func (*Movie) Id

func (m *Movie) Id() uint64

func (*Movie) Init

func (m *Movie) Init(conf ...MovieConf)

func (*Movie) SetChannel

func (m *Movie) SetChannel(channel *rtmps.Channel)

func (*Movie) SetCreator

func (m *Movie) SetCreator(creator *User)

type MovieConf

type MovieConf func(m *Movie)

func WithChannel

func WithChannel(channel *rtmps.Channel) MovieConf

func WithCreator

func WithCreator(creator *User) MovieConf

func WithPullKey

func WithPullKey(PullKey string) MovieConf

type MovieInfo

type MovieInfo struct {
	Id         uint64              `json:"id"`
	Url        string              `json:"url"`
	Name       string              `json:"name"`
	Live       bool                `json:"live"`
	Proxy      bool                `json:"proxy"`
	RtmpSource bool                `json:"rtmpSource"`
	Type       string              `json:"type"`
	Headers    map[string][]string `json:"headers"`
	PullKey    string              `json:"pullKey"`
	CreateAt   int64               `json:"createAt"`
	LastEditAt int64               `json:"lastEditAt"`
	Creator    string              `json:"creator"`
}

type PingMessage

type PingMessage struct{}

func (*PingMessage) Encode

func (pm *PingMessage) Encode(wc io.Writer) error

func (*PingMessage) MessageType

func (pm *PingMessage) MessageType() int

func (*PingMessage) String

func (pm *PingMessage) String() string

type Room

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

func NewRoom

func NewRoom(RoomID string, Password string, rtmps *rtmps.Server, conf ...RoomConf) (*Room, error)

Version cant is 0

func (*Room) AddUser

func (r *Room) AddUser(u *User) error

func (*Room) Broadcast

func (r *Room) Broadcast(msg Message, conf ...BroadcastConf) error

func (*Room) ChangeCurrentMovie

func (r *Room) ChangeCurrentMovie(id uint64) error

Seek will be set to 0

func (*Room) CheckPassword

func (r *Room) CheckPassword(password string) (ok bool)

func (*Room) CheckVersion

func (r *Room) CheckVersion(version uint64) bool

func (Room) Clear

func (m Room) Clear() error

func (*Room) ClearMovies

func (r *Room) ClearMovies() (err error)

func (Room) ClientNum

func (h Room) ClientNum() int64

func (*Room) Close

func (r *Room) Close() error

func (Room) Closed

func (h Room) Closed() bool

func (*Room) CreateAt

func (r *Room) CreateAt() time.Time

func (*Room) Current

func (r *Room) Current() *Current

func (*Room) DelMovie

func (r *Room) DelMovie(id ...uint64) error

func (*Room) DelUser

func (r *Room) DelUser(id string) error

func (Room) GetAndClear

func (m Room) GetAndClear() (movies []*Movie)

func (Room) GetAndDelMovie

func (m Room) GetAndDelMovie(id ...uint64) (movies []*Movie, err error)

func (*Room) GetAndDelUser

func (r *Room) GetAndDelUser(id string) (u *User, ok bool)

func (Room) GetMovie

func (m Room) GetMovie(id uint64) (movie *Movie, err error)

func (Room) GetMovieWithPullKey

func (m Room) GetMovieWithPullKey(pullKey string) (movie *Movie, err error)

func (*Room) GetOrNewUser

func (r *Room) GetOrNewUser(id string, password string, conf ...UserConf) (*User, error)

func (*Room) GetUser

func (r *Room) GetUser(id string) (*User, error)

func (Room) HasMovie

func (m Room) HasMovie(id uint64) bool

func (*Room) Hidden

func (r *Room) Hidden() bool

func (*Room) ID

func (r *Room) ID() string

func (*Room) LateActiveTime

func (r *Room) LateActiveTime() time.Time

func (Room) MovieList

func (m Room) MovieList() (movies []MovieInfo)

func (*Room) NeedPassword

func (r *Room) NeedPassword() bool

func (*Room) NewLiveChannel

func (r *Room) NewLiveChannel(channel string) (*rtmps.Channel, error)

func (*Room) NewUser

func (r *Room) NewUser(id string, password string, conf ...UserConf) (*User, error)

func (*Room) PushBackMovie

func (r *Room) PushBackMovie(movie *Movie) error

func (*Room) PushFrontMovie

func (r *Room) PushFrontMovie(movie *Movie) error

func (Room) Range

func (m Room) Range(f func(e *dllist.Element[*Movie]) bool) (interrupt bool)

func (*Room) RegClient

func (r *Room) RegClient(user *User, conn *websocket.Conn) (*Client, error)

func (*Room) ResetMaxInactivityTime

func (r *Room) ResetMaxInactivityTime(maxInactivityTime time.Duration)

func (*Room) RootUser

func (r *Room) RootUser() *User

func (*Room) Serve

func (r *Room) Serve()

func (*Room) SetHidden

func (r *Room) SetHidden(hidden bool)

func (*Room) SetPassword

func (r *Room) SetPassword(password string) error

func (*Room) SetRootUser

func (r *Room) SetRootUser(u *User)

func (*Room) SetSeekRate

func (r *Room) SetSeekRate(seek, rate, timeDiff float64) Status

func (*Room) SetStatus

func (r *Room) SetStatus(playing bool, seek, rate, timeDiff float64) Status

func (*Room) SetVersion

func (r *Room) SetVersion(version uint64)

func (*Room) Start

func (r *Room) Start()

func (*Room) SwapMovie

func (r *Room) SwapMovie(id1, id2 uint64) error

func (Room) UnRegClient

func (h Room) UnRegClient(user *User) error

func (*Room) UpdateActiveTime

func (r *Room) UpdateActiveTime()

func (*Room) UserList

func (r *Room) UserList() (users []User)

func (*Room) Version

func (r *Room) Version() uint64

type RoomConf

type RoomConf func(r *Room)

func WithHidden

func WithHidden(hidden bool) RoomConf

func WithMaxInactivityTime

func WithMaxInactivityTime(maxInactivityTime time.Duration) RoomConf

func WithRootUser

func WithRootUser(u *User) RoomConf

func WithVersion

func WithVersion(version uint64) RoomConf

type Status

type Status struct {
	Seek    float64 `json:"seek"`
	Rate    float64 `json:"rate"`
	Playing bool    `json:"playing"`
	// contains filtered or unexported fields
}

type User

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

func NewUser

func NewUser(id string, password string, room *Room, conf ...UserConf) (*User, error)

func (*User) Broadcast

func (u *User) Broadcast(msg Message, conf ...BroadcastConf) error

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

func (*User) CheckVersion

func (u *User) CheckVersion(version uint64) bool

func (*User) CloseHub

func (u *User) CloseHub()

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsRoot

func (u *User) IsRoot() bool

func (*User) LastAct

func (u *User) LastAct() int64

func (*User) LastActTime

func (u *User) LastActTime() time.Time

func (*User) Movie

func (u *User) Movie(id uint64) (*MovieInfo, error)

func (*User) MovieList

func (u *User) MovieList() []*MovieInfo

func (*User) Name

func (u *User) Name() string

func (*User) NewMovie

func (u *User) NewMovie(url string, name string, type_ string, live bool, proxy bool, rtmpSource bool, headers map[string][]string, conf ...MovieConf) (*Movie, error)

func (*User) NewMovieWithBaseMovie

func (u *User) NewMovieWithBaseMovie(baseMovie BaseMovie, conf ...MovieConf) (*Movie, error)

func (*User) RegClient

func (u *User) RegClient(conn *websocket.Conn) (*Client, error)

func (*User) Room

func (u *User) Room() *Room

func (*User) SetAdmin

func (u *User) SetAdmin(admin bool)

func (*User) SetPassword

func (u *User) SetPassword(password string) error

func (*User) SetVersion

func (u *User) SetVersion(version uint64)

func (*User) UpdateLastAct

func (u *User) UpdateLastAct() int64

func (*User) Version

func (u *User) Version() uint64

type UserConf

type UserConf func(*User)

func WithUserAdmin

func WithUserAdmin(admin bool) UserConf

func WithUserVersion

func WithUserVersion(version uint64) UserConf

Jump to

Keyboard shortcuts

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