room

package
v0.22.5 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultWebScene

func DefaultWebScene() *schema.WebScene

Types

type Client

type Client struct {

	// config
	Config *ClientConfig
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub.

type ClientConfig added in v0.11.0

type ClientConfig struct {
	// Time allowed to write a message to the peer.
	WriteWait time.Duration

	// Time allowed to read the next pong message from the peer.
	PongWait time.Duration

	// Send pings to peer with this period. Must be less than pongWait.
	PingPeriod time.Duration

	// Maximum message size allowed from peer.
	MaxMessageSize int64
}

func DefaultClientConfig added in v0.11.0

func DefaultClientConfig() *ClientConfig

type ClientSetOrientationMessage

type ClientSetOrientationMessage struct {
	Objects []PlayerRepresentation
}

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub(webScene *schema.WebScene, graphInstance *graph.Instance) *Hub

func (*Hub) Run

func (h *Hub) Run()

func (*Hub) ServeWs

func (hub *Hub) ServeWs(w http.ResponseWriter, r *http.Request, clientConfig *ClientConfig)

serveWs handles websocket requests from the peer.

type Message

type Message struct {
	Type MessageType
	Data []byte
}

func MessageFromClient added in v0.11.0

func MessageFromClient(data []byte) Message

func ServerRoomStateUpdate added in v0.11.0

func ServerRoomStateUpdate(room RoomState) Message

func SeverSetClientIDMessage added in v0.11.0

func SeverSetClientIDMessage(id string) Message

func (Message) ClientSetDisplayName added in v0.11.0

func (m Message) ClientSetDisplayName() string

func (Message) ClientSetOrientation added in v0.11.0

func (m Message) ClientSetOrientation() (ClientSetOrientationMessage, error)

func (Message) ClientSetScene added in v0.11.0

func (m Message) ClientSetScene() json.RawMessage

func (Message) ClientSetSceneData

func (m Message) ClientSetSceneData() schema.WebScene

func (Message) ServerRoomStateUpdate added in v0.11.0

func (m Message) ServerRoomStateUpdate() RoomState

func (Message) SeverSetClientID added in v0.11.0

func (m Message) SeverSetClientID() string

func (Message) Write added in v0.11.0

func (m Message) Write(out io.Writer) error

type MessageType

type MessageType byte
const (
	ClientSetOrientationMessageType MessageType = 0
	ClientSetDisplayNameMessageType MessageType = 1
	ClientSetSceneMessageType       MessageType = 2
	ClientSetPointerMessageType     MessageType = 3
	ClientRemovePointerMessageType  MessageType = 4

	ServerSetClientIDMessageType       MessageType = 0 + 128
	ServerRoomStateUpdateMessageType   MessageType = 1 + 128
	ServerRefrershGeneratorMessageType MessageType = 2 + 128
	ServerBroadcastMessageType         MessageType = 3 + 128
)

type Player

type Player struct {
	Name           string                 `json:"name"`
	Representation []PlayerRepresentation `json:"representation"`
}

type PlayerRepresentation added in v0.11.0

type PlayerRepresentation struct {
	Type     byte                          `json:"type"`
	Position vector3.Serializable[float32] `json:"position"`
	Rotation Vec4[float32]                 `json:"rotation"`
}

type RoomState

type RoomState struct {
	ModelVersion uint32
	WebScene     *schema.WebScene
	Players      map[string]*Player
}

type Vec4 added in v0.11.0

type Vec4[T vector.Number] struct {
	X T
	Y T
	Z T
	W T
}

Jump to

Keyboard shortcuts

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