room

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	UnknownError        = "UnknownError"
	RoomNotFoundError   = "RoomNotFoundError"
	RoomCloseError      = "RoomCloseError"
	NetWorkTimeoutError = "NetWorkTimeoutError"
	MessageContentError = "MessageContentError"
	ServeError          = "ServeError"
	ClientError         = "ClientError"
)
View Source
const (
	BroadcastType      = "broadcast"
	ConnectType        = "connect"
	StartType          = "start"
	CloseType          = "close"
	PingType           = "ping"
	PongType           = "pong"
	UpdateRoomInfoType = "updateRoomInfo"
	MessageType        = "message"
	JoinType           = "join"
	ErrorType          = "error"
	LeaveType          = "leave"
	UnknownType        = "unknown"
)

Variables

This section is empty.

Functions

func IsPublicMessageType

func IsPublicMessageType(messageType string) bool

func NewMessageContent

func NewMessageContent(messageType string) interface{}

func NotMessageType

func NotMessageType(messageType string) bool

Types

type BasicInfo

type BasicInfo struct {
	Name  string            `json:"name"`
	Group string            `json:"group"`
	Tags  map[string]string `json:"tags"`
}

type BasicRpcResponse

type BasicRpcResponse struct {
	Error *Error `json:"error"`
}

func (*BasicRpcResponse) GetError

func (b *BasicRpcResponse) GetError() error

func (*BasicRpcResponse) SetError

func (b *BasicRpcResponse) SetError(err error) error

type BasicRpcResponseInterface

type BasicRpcResponseInterface interface {
	GetError() error
}

type BroadcastMessageContent

type BroadcastMessageContent struct {
	Data        json.RawMessage `json:"data"`
	From        *Connection     `json:"from"`
	IncludeSelf bool            `json:"includeSelf"`
}

type ConnectMessageContent

type ConnectMessageContent struct {
	SelfConnection  *Connection   `json:"selfConnection"`
	RoomConnections []*Connection `json:"roomConnections"`
}

type Connection

type Connection struct {
	Address   *event.Address `json:"address"`
	CreatedAt time.Time      `json:"createdAt"`
	UserID    string         `json:"userId"`
	Name      string         `json:"name"`
}

type Error

type Error struct {
	Code    ErrorCode
	Message string
}

func NewClientError

func NewClientError(msg string, a ...any) *Error

func NewError

func NewError(msg string) *Error

func NewErrorWithCode

func NewErrorWithCode(msg string, code ErrorCode) *Error

func NewMessageContentError

func NewMessageContentError(msg string, a ...any) *Error

func NewNetWorkTimeoutError

func NewNetWorkTimeoutError(msg string, a ...any) *Error

func NewRoomCloseError

func NewRoomCloseError(msg string, a ...any) *Error

func NewRoomNotFoundError

func NewRoomNotFoundError(msg string, a ...any) *Error

func NewServeError

func NewServeError(msg string, a ...any) *Error

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode string

type ErrorMessageContent

type ErrorMessageContent struct {
	Message string `json:"message"`
	Code    string `json:"code"`
}

type Info

type Info struct {
	BasicInfo
	Address     *event.Address `json:"address"`
	Secret      string         `json:"secret"`
	UseSecret   bool           `json:"useSecret"`
	CreatedAt   time.Time      `json:"createdAt"`
	ActiveAt    time.Time      `json:"activeAt"`
	Connections []*Connection  `json:"connections"`
}

func NewRoomInfo

func NewRoomInfo(name string, secret string, useSecret bool, tags map[string]string, group string, address *event.Address) *Info

func (*Info) Update

func (i *Info) Update(info *Info)

type JoinOrLeaveMessageContent

type JoinOrLeaveMessageContent struct {
	Connection *Connection `json:"connection"`
}

type ManagerRoom

type ManagerRoom interface {
	RpcRoom
	ShouldRemove() (string, bool)
	Close(ctx context.Context, closeCode string) error
	IsClose() bool
}

type Message

type Message struct {
	Type      string      `json:"type"`
	CreatedAt int64       `json:"createdAt"`
	RequestId string      `json:"requestId"`
	Content   interface{} `json:"content"`
}

func NewBroadcastMessage

func NewBroadcastMessage(data json.RawMessage, from *Connection) *Message

func NewCloseMessage

func NewCloseMessage(roomAddress event.Address, reason string) *Message

func NewConnectMessage

func NewConnectMessage(selfConnection *Connection, roomConnections []*Connection) *Message

func NewJoinMessage

func NewJoinMessage(connection *Connection) *Message

func NewLeaveMessage

func NewLeaveMessage(connection *Connection) *Message

func NewPingMessage

func NewPingMessage(from event.Address) *Message

func NewSendMessage

func NewSendMessage(data json.RawMessage, from *Connection, to *Connection) *Message

func NewStartMessage

func NewStartMessage(roomAddress event.Address) *Message

func (*Message) GetPong

func (m *Message) GetPong() *Message

func (*Message) ToString

func (m *Message) ToString() string

type MessageMessageContent

type MessageMessageContent struct {
	Data json.RawMessage `json:"data"`
	From *Connection     `json:"from"`
	To   *Connection     `json:"to"`
}

type PingContent

type PingContent struct {
	From event.Address `json:"from"`
}

type RawMessage

type RawMessage struct {
	Type      string          `json:"type"`
	CreatedAt int64           `json:"createdAt"`
	RequestId string          `json:"requestId"`
	Content   json.RawMessage `json:"content"`
}

func (*RawMessage) ToMessage

func (rm *RawMessage) ToMessage() (*Message, error)

type RemoteRoom

type RemoteRoom interface {
	ManagerRoom
	Start(ctx context.Context) error
	SendMessage(ctx context.Context, msg *Message) error
	OnMessage() chan *Message
	Done() chan struct{}
}

type Room

type Room interface {
	RemoteRoom
	Ping()
	GetRoomUsers() []*Connection
	Join(ctx context.Context, connection *Connection, opt *Info) error
	Leave(ctx context.Context, connection *Connection, opt *Info) error
}

type RpcRoom

type RpcRoom interface {
	GetRoomAddress() *event.Address
	GetInfo() *Info
	UpdateInfo(info *Info)
}

type StartOrCloseMessageContent

type StartOrCloseMessageContent struct {
	RoomAddress event.Address `json:"roomAddress"`
	Reason      string        `json:"reason"`
}

type UpdateRoomInfoContent

type UpdateRoomInfoContent struct {
	Info *Info `json:"info"`
}

Jump to

Keyboard shortcuts

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