hub

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Subprotocols = []string{"cp0", "cp1"}

Functions

func GetTheater

func GetTheater(theaterId, token []byte) (*proto.Theater, error)

func SendEventToUser

func SendEventToUser(ctx context.Context, event []byte, user *proto.User)

Types

type Auth

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

func (*Auth) Err

func (a *Auth) Err() error

func (*Auth) Event

func (a *Auth) Event() pb.Message

func (*Auth) Token

func (a *Auth) Token() []byte

func (*Auth) User

func (a *Auth) User() *proto.User

type Client

type Client struct {
	Id string

	Event chan *protocol.Packet
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, conn net.Conn, rType RoomType) *Client

Create a new client

func NewTheaterClient

func NewTheaterClient(ctx context.Context, conn net.Conn) (client *Client)

Create a new theater client

func NewUserClient

func NewUserClient(ctx context.Context, conn net.Conn) (client *Client)

Create a new user client

func (*Client) Close

func (c *Client) Close() error

Close client connection

func (*Client) GetUser

func (c *Client) GetUser() *proto.User

Get client authenticated user

func (*Client) IsAuthenticated

func (c *Client) IsAuthenticated() bool

Check if client authorized

func (*Client) IsGuest

func (c *Client) IsGuest() bool

Get client authenticated user

func (*Client) Listen

func (c *Client) Listen()

Listen of client events

func (*Client) OnAuthorized

func (c *Client) OnAuthorized(callback func(auth Auth) Room)

Set a callback when client authorized

func (*Client) OnGuest

func (c *Client) OnGuest(callback func(auth Auth) Room)

Set a callback when client authorized

func (*Client) OnLeave

func (c *Client) OnLeave(cb func(room Room))

Set a callback when client left

func (*Client) OnUnauthorized

func (c *Client) OnUnauthorized(cb func())

Set a callback when client unauthorized

func (*Client) PingPongHandler

func (c *Client) PingPongHandler()

Handle PingPong

func (*Client) Token

func (c *Client) Token() []byte

Get client authenticated user

func (*Client) WriteMessage

func (c *Client) WriteMessage(msg []byte) (err error)

Write message to client

type ClientWithRoom

type ClientWithRoom struct {
	Id   string
	Room string
}

type Hub

type Hub interface {
	FindRoom(name string) (room Room, err error)
	GetOrCreateRoom(name string) (room Room)
	RemoveRoom(name string)
	Close() error
	Handler(w http.ResponseWriter, req *http.Request)
}

type Room

type Room interface {
	GetType() RoomType
	GetName() string
	Join(c *Client)
	HandleEvents(c *Client) error
	Leave(c *Client)
}

type RoomType

type RoomType int
const (
	UserRoomType RoomType = iota
	TheaterRoomType
)

type Session

type Session struct {
	Id uint32

	State               *proto.PERSONAL_STATE
	StaticPersonalState bool
	// contains filtered or unexported fields
}

func NewSession

func NewSession(client *Client) *Session

func (*Session) Destroy

func (s *Session) Destroy()

func (*Session) Token

func (s *Session) Token() []byte

Get client authenticated user

type TheaterHub

type TheaterHub struct {
	VideoPlayers cmap.ConcurrentMap
	// contains filtered or unexported fields
}

TheaterHub holds theater rooms

func NewTheaterHub

func NewTheaterHub() *TheaterHub

Constructor

func (*TheaterHub) Close

func (hub *TheaterHub) Close() error

func (*TheaterHub) ServeHTTP

func (hub *TheaterHub) ServeHTTP(w http.ResponseWriter, req *http.Request)

Get ws conn. and hands it over to correct room

type TheaterRoom

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

func NewTheaterRoom

func NewTheaterRoom(hub *TheaterHub, theater *proto.Theater) *TheaterRoom

create a new theater room

func (*TheaterRoom) GetName

func (room *TheaterRoom) GetName() string

func (*TheaterRoom) GetType

func (room *TheaterRoom) GetType() RoomType

func (*TheaterRoom) HandleEvents

func (room *TheaterRoom) HandleEvents(client *Client) error

Handle client events

func (*TheaterRoom) Join

func (room *TheaterRoom) Join(client *Client)

Join a client to room

func (*TheaterRoom) Leave

func (room *TheaterRoom) Leave(client *Client)

Removes client from room

func (*TheaterRoom) SendEventToTheaterMembers

func (room *TheaterRoom) SendEventToTheaterMembers(ctx context.Context, event []byte)

func (*TheaterRoom) SubscribeEvents

func (room *TheaterRoom) SubscribeEvents(client *Client)

func (*TheaterRoom) Sync

func (room *TheaterRoom) Sync(client *Client)

type Timer

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

func (*Timer) Listen

func (t *Timer) Listen()

type UserHub

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

Controls a bunch of rooms

func NewUserHub

func NewUserHub() *UserHub

Create a new userhub

func (*UserHub) Close

func (hub *UserHub) Close() error

Close user hub

func (*UserHub) ServeHTTP

func (hub *UserHub) ServeHTTP(w http.ResponseWriter, req *http.Request)

Get ws conn. and hands it over to correct room

type UserRoom

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

Has a name, clients, count which holds the actual coutn and index which acts as the unique id

func NewUserRoom

func NewUserRoom(hub *UserHub, name string) (room *UserRoom)

Constructor

func (*UserRoom) FeatchFriends

func (room *UserRoom) FeatchFriends(client *Client) ([]*proto.User, error)

func (*UserRoom) FeatchFriendsState

func (room *UserRoom) FeatchFriendsState(client *Client) error

func (*UserRoom) GetContext

func (room *UserRoom) GetContext() context.Context

func (*UserRoom) GetName

func (room *UserRoom) GetName() string

func (*UserRoom) GetType

func (room *UserRoom) GetType() RoomType

func (*UserRoom) HandleEvents

func (room *UserRoom) HandleEvents(client *Client) error

Handle messages

func (*UserRoom) Join

func (room *UserRoom) Join(client *Client)

func (*UserRoom) Leave

func (room *UserRoom) Leave(client *Client)

func (*UserRoom) SubscribeEvents

func (room *UserRoom) SubscribeEvents(client *Client)

func (*UserRoom) UpdateState

func (room *UserRoom) UpdateState(client *Client, state proto.PERSONAL_STATE)

type VideoPlayer

type VideoPlayer struct {
	Theater *proto.Theater
	// contains filtered or unexported fields
}

func NewVideoPlayer

func NewVideoPlayer() *VideoPlayer

func (*VideoPlayer) CurrentTime

func (vp *VideoPlayer) CurrentTime() float32

func (*VideoPlayer) CurrentTimeChan

func (vp *VideoPlayer) CurrentTimeChan() <-chan float32

func (*VideoPlayer) End

func (vp *VideoPlayer) End()

func (*VideoPlayer) InProgress

func (vp *VideoPlayer) InProgress() bool

func (*VideoPlayer) Pause

func (vp *VideoPlayer) Pause()

func (*VideoPlayer) Play

func (vp *VideoPlayer) Play()

func (*VideoPlayer) SetCurrentTime

func (vp *VideoPlayer) SetCurrentTime(currentTime float32)

func (*VideoPlayer) Timer

func (vp *VideoPlayer) Timer() *Timer

Jump to

Keyboard shortcuts

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