Documentation ¶
Index ¶
Constants ¶
View Source
const ( ConfigAckTimeout = "ackTimeout" ConfigReadBufferSize = "readBufferSize" ConfigWriteBufferSize = "writeBufferSize" )
Variables ¶
This section is empty.
Functions ¶
func InitConfig ¶ added in v1.4.6
Types ¶
type BatchHeader ¶ added in v1.4.6
type Protocol ¶ added in v1.4.6
type Protocol interface { // Broadcast performs best-effort delivery to all connections currently active on the specified stream Broadcast(ctx context.Context, stream string, payload interface{}) // NextRoundTrip blocks until at least one connection is started on the stream, and then // returns an interface that can be used to send a payload to exactly one of the attached // connections, and receive an ack/error from just the one connection that was picked. // - Returns an error if the context is closed. RoundTrip(ctx context.Context, stream string, payload WSBatch) (*WebSocketCommandMessage, error) }
The Protocol interface layers a protocol on top of raw websockets, that allows the server side to:
- Model the concept of multiple "streams" on a single WebSocket
- Block until 1 or more connections are available that have "started" a particular stream
- Send a broadcast to all connections on a stream
- Send a single payload to a single selected connection on a stream, and wait for an "ack" back from that specific websocket connection (or that websocket connection to disconnect)
NOTE: This replaces a previous WebSocketChannels interface, which started its life in 2018
and attempted to solve the above problem set in a different way that had a challenging timing issue.
type WSBatch ¶ added in v1.4.6
type WSBatch interface {
GetBatchHeader() *BatchHeader
}
WSBatch is any serializable structure that contains the batch header
type WebSocketCommandMessage ¶
type WebSocketServer ¶
type WebSocketServer interface { Protocol Handler(w http.ResponseWriter, r *http.Request) Close() }
WebSocketServer is the full server interface with the init call
func NewWebSocketServer ¶
func NewWebSocketServer(bgCtx context.Context, config *WebSocketServerConfig) WebSocketServer
NewWebSocketServer create a new server with a simplified interface
type WebSocketServerConfig ¶ added in v1.4.6
type WebSocketServerConfig struct { AckTimeout time.Duration ReadBufferSize int64 WriteBufferSize int64 }
func GenerateConfig ¶ added in v1.4.6
func GenerateConfig(conf config.Section) *WebSocketServerConfig
Click to show internal directories.
Click to hide internal directories.