ws

package
v0.0.0-...-22f0dc9 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxMessageSize determines the chunking size of messages used by gorilla
	MaxMessageSize = 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectFunc

type ConnectFunc func(out chan<- []byte)

type Service

type Service struct {
	// Type must be unique in an UIChannel
	Type string
	// In is the channel to receive messages with the specific type from the
	// clients.
	In <-chan interface{}
	// Out is the channel to send messages to the clients.
	Out chan<- interface{}
	// contains filtered or unexported fields
}

Service encapsulates a way to exchange JSON messages with a specific type with WebSocket clients. The messages are in the form of `{"type": <Type>, "message": <actual message>}`.

type UIChannel

type UIChannel interface {
	// Handler exposes the UIChannel as an http.Handler
	Handler() http.Handler
	// Register registers a service with an optional helloFn to send initial
	// message to connected clients.
	Register(t string, helloFn helloFnType) (*Service, error)
	// SendMessage sends data over the given websocket channel
	SendMessage(ch string, data any) error
	// RegisterWithMsgInitializer is similar to Register, but with an additional
	// newMsgFn to initialize the message data type to-be received from WebSocket
	// client, instead of letting JSON unmarshaler to guess the data type.
	RegisterWithMsgInitializer(t string, helloFn helloFnType, newMsgFn newMsgFnType) (*Service, error)
	// Unregister stops the UIChannel from processing messages with the specific type.
	Unregister(t string)
}

UIChannel is a WebSocket server which can be attached to an HTTP server. Services can be registered with specific types so once the WebSocket clients are connected, they can exchange any JSON messages with the services.

func NewUIChannel

func NewUIChannel() UIChannel

Jump to

Keyboard shortcuts

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