Documentation ¶
Overview ¶
Package websocket contains implementation of websocket.
Index ¶
Constants ¶
View Source
const ( RoomLoggedUserCount = "logged-user-count" RoomBroadcastMessages = "broadcast-messages" RoomAlarmsGroup = "alarms/" RoomAlarmDetailsGroup = "alarm-details/" RoomHealthcheck = "healthcheck" RoomHealthcheckStatus = "healthcheck-status" RoomMessageRates = "message-rates" RoomIcons = "icons" )
View Source
const ( RMessageClientPing = iota RMessageJoin RMessageLeave RMessageAuth )
View Source
const ( WMessageClientPong = iota WMessageSuccess WMessageFail WMessageCloseRoom WMessageAuthSuccess )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
type Authorizer interface { // Authenticate authenticates user by token. Authenticate(ctx context.Context, token string) (string, error) // Authorize checks if user has access to room. Authorize(ctx context.Context, userID, room string) (bool, error) // AddRoom adds room with permissions. AddRoom(room string, perms []string) error AddGroup(group string, perms []string, check GroupCheckExists) error GetGroupIds(group string) []string RemoveGroupRoom(group, id string) error }
Authorizer is used to implement websocket room authentication and authorization.
func NewAuthorizer ¶
func NewAuthorizer( enforcer security.Enforcer, tokenProviders []security.TokenProvider, ) Authorizer
type Connection ¶
type GroupOnJoin ¶
type GroupParameters ¶
type GroupParameters struct { CheckExists GroupCheckExists OnNotExist GroupOnNotExist OnJoin GroupOnJoin OnLeave GroupOnLeave }
func (GroupParameters) IsZero ¶
func (p GroupParameters) IsZero() bool
type Hub ¶
type Hub interface { // Start pings connections. Start(ctx context.Context) // Connect creates listener connection. Connect(w http.ResponseWriter, r *http.Request) error // Send sends message to all listeners in room. Send(room string, msg any) SendGroupRoom(group, id string, msg any) SendGroupRoomByConnections(connIds []string, group, id string, b any) // RegisterRoom adds room with permissions. RegisterRoom(room string, perms ...string) error RegisterGroup(group string, params GroupParameters, perms ...string) error GetGroupIds(group string) []string GetConnectedGroupIds(group string) []string CloseGroupRoom(group, id string) error CloseGroupRoomAndNotify(group, id string) error GetUserTokens() []string GetConnections() []UserConnection }
Hub interface is used to implement websocket room.
type RMessage ¶
type Store ¶
type Upgrader ¶
type Upgrader interface {
Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (Connection, error)
}
Click to show internal directories.
Click to hide internal directories.