{"modulePath":"github.com/infinitbyte/framework","version":"v1.1.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package websocket\n\n## Functions\n\n```go\nfunc BroadcastMessage(msg string)\n```\nBroadcastMessage send broadcast message to channel and record stats\n\n```go\nfunc HandleWebSocketCommand(cmd, usage string, handler func(c *WebsocketConnection, array []string))\n```\nHandleWebSocketCommand used to register command and handler\n\n```go\nfunc InitWebSocket(cfg config.WebsocketConfig)\n```\nInitWebSocket start websocket\n\n```go\nfunc RegisterConnectCallback(f ConnectCallbackFunc)\n```\n\n```go\nfunc RegisterDisconnectCallback(f DisconnectCallbackFunc)\n```\n\n```go\nfunc SendPrivateMessage(session string, msg string) error\n```\n\n```go\nfunc ServeWs(w http.ResponseWriter, r *http.Request)\n```\nServeWs handles websocket requests from the peer.\n\n## Types\n\n```go\ntype ConnectCallbackFunc func(sessionID string, w http.ResponseWriter, r *http.Request) error\n```\n\n```go\ntype DisconnectCallbackFunc func(sessionID string)\n```\n\n```go\ntype Hub struct {\n\t// contains filtered or unexported fields\n}\n```\nHub maintains the set of active connections and broadcasts messages to the connections.\n\n```go\ntype MsgType string\n```\nMsgType is the type of different message\n\n```go\nconst (\n\t// PrivateMessage means message is 1 to 1\n\tPrivateMessage MsgType = \"PRIVATE\"\n\t// PublicMessage means broadcast message\n\tPublicMessage MsgType = \"PUBLIC\"\n\t// ConfigMessage used to send configuration\n\tConfigMessage MsgType = \"CONFIG\"\n\n\t// SystemMessage used to send system related info\n\tSystemMessage MsgType = \"SYSTEM\"\n)\n```\n\n```go\ntype WebsocketConnection struct {\n\t// contains filtered or unexported fields\n}\n```\nWebsocketConnection is an middleman between the websocket connection and the hub.\n\n```go\nfunc (c *WebsocketConnection) Broadcast(msg string)\n```\nBroadcast public message to all channels\n\n```go\nfunc (c *WebsocketConnection) WriteMessage(t MsgType, msg string) error\n```\nWriteMessage will use the right way to write message, don't call c.write directly\n\n```go\nfunc (c *WebsocketConnection) WritePrivateMessage(msg string) error\n```\nWritePrivateMessage will send msg to channel\n\n```go\ntype WebsocketHandlerFunc func(c *WebsocketConnection, array []string)\n```\nWebsocketHandlerFunc define the func to handle websocket\n\n","path":"github.com/infinitbyte/framework/core/api/websocket","name":"websocket","synopsis":"","isRedistributable":true}
