websocket

package
v0.0.0-...-9a10968 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BroadcastMessage

func BroadcastMessage(msg string)

BroadcastMessage send broadcast message to channel and record stats

func HandleWebSocketCommand

func HandleWebSocketCommand(cmd, usage string, handler func(c *WebsocketConnection, array []string))

HandleWebSocketCommand used to register command and handler

func InitWebSocket

func InitWebSocket()

InitWebSocket start websocket

func ServeWs

func ServeWs(w http.ResponseWriter, r *http.Request)

ServeWs handles websocket requests from the peer.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub maintains the set of active connections and broadcasts messages to the connections.

type MsgType

type MsgType string

MsgType is the type of different message

const (
	// PrivateMessage means message is 1 to 1
	PrivateMessage MsgType = "PRIVATE"
	// PublicMessage means broadcast message
	PublicMessage MsgType = "PUBLIC"
	// ConfigMessage used to send configuration
	ConfigMessage MsgType = "CONFIG"
)

type WebsocketConnection

type WebsocketConnection struct {
	// contains filtered or unexported fields
}

WebsocketConnection is an middleman between the websocket connection and the hub.

func (*WebsocketConnection) Broadcast

func (c *WebsocketConnection) Broadcast(msg string)

Broadcast public message to all channels

func (*WebsocketConnection) WriteMessage

func (c *WebsocketConnection) WriteMessage(t MsgType, msg string) error

WriteMessage will use the right way to write message, don't call c.write directly

func (*WebsocketConnection) WritePrivateMessage

func (c *WebsocketConnection) WritePrivateMessage(msg string) error

WritePrivateMessage will send msg to channel

type WebsocketHandlerFunc

type WebsocketHandlerFunc func(c *WebsocketConnection, array []string)

WebsocketHandlerFunc define the func to handle websocket

Jump to

Keyboard shortcuts

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