Documentation ¶
Overview ¶
Package websocket starts a WebSocket service forwarding internal events to http clients
Index ¶
- Constants
- func ClearSession(session *melody.Session)
- func Marshal(m Message) []byte
- func NewErrorMessage(e error) []byte
- func NewErrorMessageString(e string) []byte
- func UpdateSessionFromClaims(session *melody.Session, claims claim.Claims, pool *views.ClientsPool)
- type ChatHandler
- func (c *ChatHandler) AppendUserToRoom(room *chat.ChatRoom, userName string)
- func (c *ChatHandler) BroadcastChatMessage(ctx context.Context, msg *chat.ChatEvent) error
- func (c *ChatHandler) FindOrCreateRoom(ctx context.Context, room *chat.ChatRoom, createIfNotExists bool) (*chat.ChatRoom, error)
- func (c *ChatHandler) InitHandlers(serviceCtx context.Context)
- func (c *ChatHandler) RemoveUserFromRoom(room *chat.ChatRoom, userName string)
- type ChatMessage
- type ChatMessageType
- type Message
- type MessageType
- type NodeChangeEventWithInfo
- type NodeEventsBatcher
- type WebsocketHandler
- func (w *WebsocketHandler) BroadcastActivityEvent(ctx context.Context, event *activity.PostActivityEvent) error
- func (w *WebsocketHandler) BroadcastIDMChangeEvent(ctx context.Context, event *idm.ChangeEvent) error
- func (w *WebsocketHandler) BroadcastNodeChangeEvent(ctx context.Context, event *NodeChangeEventWithInfo) error
- func (w *WebsocketHandler) BroadcastTaskChangeEvent(ctx context.Context, event *jobs.TaskChangeEvent) error
- func (w *WebsocketHandler) HandleNodeChangeEvent(ctx context.Context, event *tree.NodeChangeEvent) error
- func (w *WebsocketHandler) InitHandlers(serviceCtx context.Context)
Constants ¶
const SessionClaimsKey = "profile"
const SessionProfileKey = "profile"
const SessionRolesKey = "roles"
const (
SessionRoomKey = "room"
)
const SessionUsernameKey = "user"
const SessionWorkspacesKey = "workspaces"
Variables ¶
This section is empty.
Functions ¶
func ClearSession ¶
func ClearSession(session *melody.Session)
func NewErrorMessage ¶
func NewErrorMessageString ¶
func UpdateSessionFromClaims ¶
func UpdateSessionFromClaims(session *melody.Session, claims claim.Claims, pool *views.ClientsPool)
Types ¶
type ChatHandler ¶
type ChatHandler struct { Websocket *melody.Melody Pool *views.ClientsPool }
func NewChatHandler ¶
func NewChatHandler(serviceCtx context.Context) *ChatHandler
func (*ChatHandler) AppendUserToRoom ¶
func (c *ChatHandler) AppendUserToRoom(room *chat.ChatRoom, userName string)
func (*ChatHandler) BroadcastChatMessage ¶
func (*ChatHandler) FindOrCreateRoom ¶
func (*ChatHandler) InitHandlers ¶
func (c *ChatHandler) InitHandlers(serviceCtx context.Context)
func (*ChatHandler) RemoveUserFromRoom ¶
func (c *ChatHandler) RemoveUserFromRoom(room *chat.ChatRoom, userName string)
type ChatMessage ¶
type ChatMessage struct { Type ChatMessageType `json:"@type"` RoomType chat.RoomType Payload string }
type ChatMessageType ¶
type ChatMessageType string
const ( JoinRoom ChatMessageType = "join" LeaveRoom ChatMessageType = "leave" PostMessage ChatMessageType = "msg" )
type Message ¶
type Message struct { Type MessageType `json:"@type"` JWT string `json:"jwt"` Error string `json:"error"` }
Should pass JWT instead of username
type MessageType ¶
type MessageType string
const ( MsgSubscribe MessageType = "subscribe" MsgUnsubscribe MessageType = "unsubscribe" MsgError MessageType = "error" )
type NodeChangeEventWithInfo ¶ added in v1.2.0
type NodeChangeEventWithInfo struct { tree.NodeChangeEvent // contains filtered or unexported fields }
type NodeEventsBatcher ¶ added in v1.2.0
type NodeEventsBatcher struct {
// contains filtered or unexported fields
}
NodeEventsBatcher buffers events with same node.uuid and flatten them into one where possible
func NewEventsBatcher ¶ added in v1.2.0
func NewEventsBatcher(timeout time.Duration, uuid string, out chan *NodeChangeEventWithInfo, done chan string) *NodeEventsBatcher
NewEventsBatcher creates a new NodeEventsBatcher
func (*NodeEventsBatcher) Flush ¶ added in v1.2.0
func (n *NodeEventsBatcher) Flush()
Flush applies the events buffered as one
type WebsocketHandler ¶
type WebsocketHandler struct { Websocket *melody.Melody EventRouter *views.RouterEventFilter // contains filtered or unexported fields }
func NewWebSocketHandler ¶
func NewWebSocketHandler(serviceCtx context.Context) *WebsocketHandler
func (*WebsocketHandler) BroadcastActivityEvent ¶
func (w *WebsocketHandler) BroadcastActivityEvent(ctx context.Context, event *activity.PostActivityEvent) error
BroadcastActivityEvent listens to activities and broadcast them to sessions with the adequate user.
func (*WebsocketHandler) BroadcastIDMChangeEvent ¶
func (w *WebsocketHandler) BroadcastIDMChangeEvent(ctx context.Context, event *idm.ChangeEvent) error
BroadcastIDMChangeEvent listens to ACL events and broadcast them to sessions if the Role, User, or Workspace is concerned This triggers a registry reload in the UX (and eventually a change of permissions)
func (*WebsocketHandler) BroadcastNodeChangeEvent ¶
func (w *WebsocketHandler) BroadcastNodeChangeEvent(ctx context.Context, event *NodeChangeEventWithInfo) error
BroadcastNodeChangeEvent will browse the currently registered websocket sessions and decide whether to broadcast the event or not.
func (*WebsocketHandler) BroadcastTaskChangeEvent ¶
func (w *WebsocketHandler) BroadcastTaskChangeEvent(ctx context.Context, event *jobs.TaskChangeEvent) error
BroadcastTaskChangeEvent listens to tasks events and broadcast them to sessions with the adequate user.
func (*WebsocketHandler) HandleNodeChangeEvent ¶ added in v1.2.0
func (w *WebsocketHandler) HandleNodeChangeEvent(ctx context.Context, event *tree.NodeChangeEvent) error
HandleNodeChangeEvent listens to NodeChangeEvents and either broadcase them directly, or use NodeEventsBatcher to buffer them and flatten them into one.
func (*WebsocketHandler) InitHandlers ¶
func (w *WebsocketHandler) InitHandlers(serviceCtx context.Context)