ws

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorToHttpCode

func ErrorToHttpCode(err error) int

func SendJsonResponse

func SendJsonResponse(writer http.ResponseWriter, resp interface{}, err error)

func WSConnWriteError

func WSConnWriteError(wsConn *websocket.Conn, err error) error

func WSConnWriteMessage

func WSConnWriteMessage(wsConn *websocket.Conn, msg interface{}) error

Types

type WSClient

type WSClient struct {
	PingPeriod time.Duration
	PongPeriod time.Duration
	// contains filtered or unexported fields
}

func (*WSClient) Start

func (w *WSClient) Start() error

func (*WSClient) Stop

func (w *WSClient) Stop()

type WSMsgType

type WSMsgType interface{}

type WSMux

type WSMux struct {
	Upgrader            websocket.Upgrader
	HandleClientMessage func(ws *WSMux, msg WSMsgType) error
	// contains filtered or unexported fields
}

func NewWSMux

func NewWSMux() *WSMux

func (*WSMux) AddToTopic

func (w *WSMux) AddToTopic(topicId string, client *WSClient) error

Adds a client to a particular topic id. This makes it eligible to receive messages sent on a particular topic Normally this is called by

func (*WSMux) Publish

func (w *WSMux) Publish(topicId string, msg WSMsgType) error

Publishes a message to all clients on caring about given topic

func (*WSMux) RemoveClient

func (w *WSMux) RemoveClient(client *WSClient) error

func (*WSMux) RemoveFromTopic

func (w *WSMux) RemoveFromTopic(topicId string, client *WSClient) error

Remove a client from particular topic id. This makes it stop receiving messages sent on the particular topic

func (*WSMux) SetForTopic

func (w *WSMux) SetForTopic(topicId string, client *WSClient) error

Sets the "listening" client on a topic. This ensures that there is only a single client for the given topic.

func (*WSMux) Subscribe

func (w *WSMux) Subscribe(req *http.Request, writer http.ResponseWriter) (*WSClient, error)

*

  • Called when a new connection arrives.

Jump to

Keyboard shortcuts

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