websocket

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 12 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// Error for when sending a message fails.
	ErrTypeMsgSendfail = "msg_send_fail"

	// Error for when receiving a message fails.
	ErrTypeMsgReceiveFail = "msg_receive_fail"

	// Error for when a participant sends a request that requires that it
	// already joined a session.
	ErrTypeSessionNotJoined = "session_not_joined"

	// Error for when a message is received without a timestamp set.
	ErrTypeMsgMissingTimestamp = "msg_missing_timestamp"

	// Error for when a message is skipped by a module.
	ErrTypeMsgSkip = "module_msg_skip"

	// Error for when an entity does not exist.
	ErrEntityComponentTypeNotAdded = "entity-component-type-not-added"

	// Error for when an entity component type already exists.
	ErrEntityComponentTypeAlreadyAdded = "entity-component-type-already-added"
)

Variables

View Source
var (
	// Error returned when a module skipped handling a message.
	ErrModuleMsgSkip = errors.New("handling message is skipped").WithType(ErrTypeMsgSkip)
)

Functions

func NewScheduler

func NewScheduler() *scheduler

func ProtoMsgType

func ProtoMsgType(msg ProtoMsg) string

ProtoMsgType returns the type of the protobuf message as a string.

It panics when msg does not have a GetType method that returns a protobuf error.

func Send

func Send(ws *websocket.Conn, msg Msg) (int, error)

Send sends the given msg through the web socket.

Types

type Consumer

type Consumer interface {
	// Returns the next message to be consumed.
	Consume(context.Context) (Msg, error)

	// Returns the channel that contains the consumable messages.
	Messages() <-chan Msg
}

Consumer represents a message consumer.

type Dispatcher

type Dispatcher interface {
	// Dispatches the given message.
	Dispatch(context.Context, Msg) error

	// The function called when a session frame ends.
	HandleFrame()
}

Dispatcher represents a message dispatcher that decides if and when a message can be consumed.

type Msg

type Msg struct {
	Type protoreflect.Enum
	Time time.Time
	// contains filtered or unexported fields
}

Msg represents a Hagall WebSocket message to be handled.

func MsgFromProto

func MsgFromProto(v ProtoMsg) (Msg, error)

MsgFromProto builds Msg from ProtoMsg.

func Receive

func Receive(ws *websocket.Conn) (Msg, int, error)

Receive receives the incoming message from the web socket.

func (Msg) DataTo

func (m Msg) DataTo(v ProtoMsg) error

DataTo stores the message in the given value. v should be a pointer.

func (Msg) TypeString

func (m Msg) TypeString() string

type ProtoMsg

type ProtoMsg interface {
	protoreflect.ProtoMessage

	GetTimestamp() *timestamppb.Timestamp
}

ProtoMsg is the interface that describes a protobuf message.

type Receiver

type Receiver func() (Msg, int, error)

Receiver represents a function that receives a message.

type ResponseSender

type ResponseSender interface {
	Send(ProtoMsg)
	SendMsg(Msg)
}

type Sender

type Sender func(msg Msg) (int, error)

Sender represents a function that sends a message.

Jump to

Keyboard shortcuts

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