op

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoomPending = errors.New("room pending, please wait for admin to approve")
	ErrRoomBanned  = errors.New("room banned")
)
View Source
var (
	ErrUserBanned  = errors.New("user banned")
	ErrUserPending = errors.New("user pending, please wait for admin to approve")
)
View Source
var (
	ErrAlreadyClosed = fmt.Errorf("already closed")
)

Functions

func ClientNum

func ClientNum(roomID string) int64

func CloseRoomById

func CloseRoomById(roomID string) error

func CloseUserById

func CloseUserById(id string) error

func CompareAndCloseRoom

func CompareAndCloseRoom(room *Room) error

func CompareAndCloseRoomEntry

func CompareAndCloseRoomEntry(id string, room *synccache.Entry[*Room]) error

func CompareAndCloseUser

func CompareAndCloseUser(user *User) error

func CompareAndDeleteRoom

func CompareAndDeleteRoom(room *Room) error

func CompareAndDeleteUser

func CompareAndDeleteUser(user *User) error

func DeleteRoomByID

func DeleteRoomByID(roomID string) error

func DeleteUserByID

func DeleteUserByID(id string) error

func GetUserName

func GetUserName(userID string) string

func HasRoom

func HasRoom(roomID string) bool

func HasRoomByName

func HasRoomByName(name string) bool

func Init

func Init(size int) error

func SetRoleByID

func SetRoleByID(userID string, role model.Role) error

func SetRoomStatus

func SetRoomStatus(roomID string, status model.RoomStatus) error

Types

type BaseCache

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

func (*BaseCache) Clear

func (b *BaseCache) Clear()

func (*BaseCache) InitOrLoadMPDCache

func (b *BaseCache) InitOrLoadMPDCache(id string, refreshFunc func() (*MPDCache, error), maxAge time.Duration) (*refreshcache.RefreshCache[*MPDCache], error)

func (*BaseCache) InitOrLoadURLCache

func (b *BaseCache) InitOrLoadURLCache(id string, refreshFunc func() (string, error), maxAge time.Duration) (*refreshcache.RefreshCache[string], error)

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 (*Client) Broadcast

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

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) User

func (c *Client) User() *User

type Current

type Current struct {
	Movie  Movie  `json:"movie"`
	Status Status `json:"status"`
}

func (*Current) Proto

func (c *Current) Proto() *pb.Current

func (*Current) SetSeek

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) UpdateSeek

func (c *Current) UpdateSeek()

type ElementJsonMessage

type ElementJsonMessage struct {
	BeforeSendFunc func(sendTo *User) error
	*pb.ElementMessage
}

func (*ElementJsonMessage) BeforeSend

func (em *ElementJsonMessage) BeforeSend(sendTo *User) error

func (*ElementJsonMessage) Encode

func (em *ElementJsonMessage) Encode(w io.Writer) error

func (*ElementJsonMessage) MessageType

func (em *ElementJsonMessage) MessageType() int

func (*ElementJsonMessage) String

func (em *ElementJsonMessage) String() string

type ElementMessage

type ElementMessage struct {
	BeforeSendFunc func(sendTo *User) error
	*pb.ElementMessage
}

func (*ElementMessage) BeforeSend

func (em *ElementMessage) BeforeSend(sendTo *User) error

func (*ElementMessage) Encode

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

func (*ElementMessage) MessageType

func (em *ElementMessage) MessageType() int

func (*ElementMessage) String

func (em *ElementMessage) String() string

type Hub

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

func (*Hub) Broadcast

func (h *Hub) Broadcast(data Message, conf ...BroadcastConf) error

func (*Hub) ClientNum

func (h *Hub) ClientNum() int64

func (*Hub) Close

func (h *Hub) Close() error

func (*Hub) Closed

func (h *Hub) Closed() bool

func (*Hub) RegClient

func (h *Hub) RegClient(cli *Client) (*Client, error)

func (*Hub) SendToUser

func (h *Hub) SendToUser(userID string, data Message) error

func (*Hub) Start

func (h *Hub) Start() error

func (*Hub) UnRegClient

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

type MPDCache

type MPDCache struct {
	MPDFile string
	URLs    []string
}

type Message

type Message interface {
	MessageType() int
	String() string
	Encode(w io.Writer) error
	BeforeSend(sendTo *User) error
}

type Movie

type Movie struct {
	Movie model.Movie
	// contains filtered or unexported fields
}

func (*Movie) Cache

func (m *Movie) Cache() *BaseCache

func (*Movie) Channel

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

func (*Movie) Terminate

func (m *Movie) Terminate()

func (*Movie) Update

func (m *Movie) Update(movie *model.BaseMovie) error

func (*Movie) Validate

func (movie *Movie) Validate() error

type PingMessage

type PingMessage struct{}

func (*PingMessage) BeforeSend

func (pm *PingMessage) BeforeSend(sendTo *User) error

func (*PingMessage) Encode

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

func (*PingMessage) MessageType

func (pm *PingMessage) MessageType() int

func (*PingMessage) String

func (pm *PingMessage) String() string

type Room

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

func CreateRoom

func CreateRoom(name, password string, maxCount int64, conf ...db.CreateRoomConfig) (*Room, error)

func GetAllRoomsInCacheWithNoNeedPassword

func GetAllRoomsInCacheWithNoNeedPassword() []*Room

func GetAllRoomsInCacheWithoutHidden

func GetAllRoomsInCacheWithoutHidden() []*Room

func LoadOrInitRoom

func LoadOrInitRoom(room *model.Room) (*Room, error)

func LoadOrInitRoomByID

func LoadOrInitRoomByID(id string) (*Room, error)

func LoadRoomByID

func LoadRoomByID(id string) (*Room, error)

func (*Room) AddMovie

func (r *Room) AddMovie(m *model.Movie) error

func (*Room) AddMovies

func (r *Room) AddMovies(movies []*model.Movie) error

func (*Room) AddUserPermission

func (r *Room) AddUserPermission(userID string, permission model.RoomUserPermission) error

func (*Room) Broadcast

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

func (*Room) CheckVersion

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

func (*Room) ClearMovies

func (r *Room) ClearMovies() error

func (*Room) ClientNum

func (r *Room) ClientNum() int64

func (*Room) Current

func (r *Room) Current() *Current

func (*Room) DeleteMovieByID

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

func (*Room) GetChannel

func (r *Room) GetChannel(channelName string) (*rtmps.Channel, error)

func (*Room) GetMovieByID

func (r *Room) GetMovieByID(id string) (*Movie, error)

func (*Room) GetMoviesCount

func (r *Room) GetMoviesCount() int

func (*Room) GetMoviesWithPage

func (r *Room) GetMoviesWithPage(page, pageSize int) []*Movie

func (*Room) GetRoomUserRelation

func (r *Room) GetRoomUserRelation(userID string) (model.RoomUserPermission, error)

func (*Room) HasPermission

func (r *Room) HasPermission(userID string, permission model.RoomUserPermission) bool

func (*Room) LoadOrCreateRoomUserRelation

func (r *Room) LoadOrCreateRoomUserRelation(userID string) (*model.RoomUserRelation, error)

func (*Room) NeedPassword

func (r *Room) NeedPassword() bool

func (*Room) RegClient

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

func (*Room) RemoveUserPermission

func (r *Room) RemoveUserPermission(userID string, permission model.RoomUserPermission) error

func (*Room) SendToUser

func (r *Room) SendToUser(user *User, data Message) error

func (*Room) SetCurrentMovie

func (r *Room) SetCurrentMovie(movie *Movie, play bool)

func (*Room) SetCurrentMovieByID

func (r *Room) SetCurrentMovieByID(id string, play bool) error

func (*Room) SetPassword

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

func (*Room) SetRoomStatus

func (r *Room) SetRoomStatus(status model.RoomStatus) error

func (*Room) SetSeekRate

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

func (*Room) SetSettings

func (r *Room) SetSettings(settings model.RoomSettings) error

func (*Room) SetStatus

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

func (*Room) SetUserPermission

func (r *Room) SetUserPermission(userID string, permission model.RoomUserPermission) error

func (*Room) SetUserStatus

func (r *Room) SetUserStatus(userID string, status model.RoomUserStatus) error

func (*Room) SwapMoviePositions

func (r *Room) SwapMoviePositions(id1, id2 string) error

func (*Room) UnregisterClient

func (r *Room) UnregisterClient(user *User) error

func (*Room) UpdateMovie

func (r *Room) UpdateMovie(movieId string, movie *model.BaseMovie) error

func (*Room) Version

func (r *Room) Version() uint32

type RoomInfo

type RoomInfo struct {
	RoomId       string           `json:"roomId"`
	RoomName     string           `json:"roomName"`
	PeopleNum    int64            `json:"peopleNum"`
	NeedPassword bool             `json:"needPassword"`
	CreatorID    string           `json:"creatorId"`
	Creator      string           `json:"creator"`
	CreatedAt    int64            `json:"createdAt"`
	Status       model.RoomStatus `json:"status"`
}

func GetRoomHeapInCacheWithoutHidden

func GetRoomHeapInCacheWithoutHidden() []*RoomInfo

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 {
	model.User
	// contains filtered or unexported fields
}

func CreateOrLoadUser

func CreateOrLoadUser(username string, password string, conf ...db.CreateUserConfig) (*User, error)

func CreateOrLoadUserWithProvider

func CreateOrLoadUserWithProvider(username, password string, p provider.OAuth2Provider, pid string, conf ...db.CreateUserConfig) (*User, error)

func CreateUser

func CreateUser(username string, password string, conf ...db.CreateUserConfig) (*User, error)

func GetUserByProvider

func GetUserByProvider(p provider.OAuth2Provider, pid string) (*User, error)

func LoadOrInitUser

func LoadOrInitUser(u *model.User) (*User, error)

func LoadOrInitUserByID

func LoadOrInitUserByID(id string) (*User, error)

func LoadUserByUsername

func LoadUserByUsername(username string) (*User, error)

func (*User) AddMovieToRoom

func (u *User) AddMovieToRoom(room *Room, movie *model.BaseMovie) error

func (*User) AddMoviesToRoom

func (u *User) AddMoviesToRoom(room *Room, movies []*model.BaseMovie) error

func (*User) BindProvider

func (u *User) BindProvider(p provider.OAuth2Provider, pid string) error

func (*User) CheckVersion

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

func (*User) ClearMovies

func (u *User) ClearMovies(room *Room) error

func (*User) CreateRoom

func (u *User) CreateRoom(name, password string, conf ...db.CreateRoomConfig) (*Room, error)

func (*User) DeleteMovieByID

func (u *User) DeleteMovieByID(room *Room, movieID string) error

func (*User) DeleteMoviesByID

func (u *User) DeleteMoviesByID(room *Room, movieIDs []string) error

func (*User) DeleteRoom

func (u *User) DeleteRoom(room *Room) error

func (*User) HasRoomPermission

func (u *User) HasRoomPermission(room *Room, permission model.RoomUserPermission) bool

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsBanned

func (u *User) IsBanned() bool

func (*User) IsPending

func (u *User) IsPending() bool

func (*User) IsRoot

func (u *User) IsRoot() bool

func (*User) NewMovie

func (u *User) NewMovie(movie *model.BaseMovie) *model.Movie

func (*User) NewMovies

func (u *User) NewMovies(movies []*model.BaseMovie) []*model.Movie

func (*User) SetCurrentMovie

func (u *User) SetCurrentMovie(room *Room, movie *Movie, play bool) error

func (*User) SetCurrentMovieByID

func (u *User) SetCurrentMovieByID(room *Room, movieID string, play bool) error

func (*User) SetPassword

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

func (*User) SetRole

func (u *User) SetRole(role model.Role) error

func (*User) SetRoomPassword

func (u *User) SetRoomPassword(room *Room, password string) error

func (*User) SetRoomSetting

func (u *User) SetRoomSetting(room *Room, setting model.RoomSettings) error

func (*User) SetUsername

func (u *User) SetUsername(username string) error

func (*User) UpdateMovie

func (u *User) UpdateMovie(room *Room, movieID string, movie *model.BaseMovie) error

func (*User) Version

func (u *User) Version() uint32

Jump to

Keyboard shortcuts

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