Documentation
¶
Overview ¶
Package notify provides websocket notification services for broadcasting events to connected clients.
Index ¶
- Variables
- func NewFileNotification(ctx context.Context, fileInfo wlstructs.FileInfo, event websocket_mod.WsEvent, ...) []websocket_mod.WsResponseInfo
- func NewPoolNotification(pool *task.Pool, event websocket_mod.WsEvent, result task.Result) websocket_mod.WsResponseInfo
- func NewSystemNotification(event websocket_mod.WsEvent, data websocket_mod.WsData) websocket_mod.WsResponseInfo
- func NewTaskNotification(task Jobber, event websocket_mod.WsEvent, result task.Result) websocket_mod.WsResponseInfo
- type ClientManager
- func (cm *ClientManager) ClientConnect(ctx context.Context, conn *websocket.Conn, user *user_model.User) (*websocket_model.WsClient, error)
- func (cm *ClientManager) ClientDisconnect(ctx context.Context, c *websocket_model.WsClient) error
- func (cm *ClientManager) DisconnectAll(ctx context.Context) error
- func (cm *ClientManager) Flush(ctx context.Context)
- func (cm *ClientManager) FolderSubToTask(ctx context.Context, folderID string, task IDer)
- func (cm *ClientManager) GetAllClients() []*websocket_model.WsClient
- func (cm *ClientManager) GetClientByTowerID(towerID string) *websocket_model.WsClient
- func (cm *ClientManager) GetClientByUsername(username string) *websocket_model.WsClient
- func (cm *ClientManager) GetConnectedAdmins() []*websocket_model.WsClient
- func (cm *ClientManager) GetCoreByTowerID(towerID string) *websocket_model.WsClient
- func (cm *ClientManager) GetSubscribers(ctx context.Context, st websocket_mod.SubscriptionType, key string) (clients []*websocket_model.WsClient)
- func (cm *ClientManager) ListenForTowerUpdate(tower tower_model.Instance) (notifyChan chan struct{})
- func (cm *ClientManager) Notify(ctx context.Context, msg ...websocket_mod.WsResponseInfo)
- func (cm *ClientManager) PushTowerUpdate(tower tower_model.Instance) bool
- func (cm *ClientManager) Relay(_ websocket_mod.WsResponseInfo)
- func (cm *ClientManager) RemoteConnect(ctx context.Context, conn *websocket.Conn, remote *tower_model.Instance) *websocket_model.WsClient
- func (cm *ClientManager) Send(ctx context.Context, msg websocket_mod.WsResponseInfo)
- func (cm *ClientManager) SubscribeToFile(ctx context.Context, c *client_model.WsClient, file IDer, subTime time.Time) error
- func (cm *ClientManager) SubscribeToTask(ctx context.Context, c *client_model.WsClient, task IDer, subTime time.Time) error
- func (cm *ClientManager) Unsubscribe(ctx context.Context, client *websocket_model.WsClient, key string, ...) error
- func (cm *ClientManager) UnsubscribeAllByID(ctx context.Context, subID string, ...) error
- type FileNotificationOptions
- type IDer
- type Jobber
Constants ¶
This section is empty.
Variables ¶
var ErrSubscriptionNotFound = wlerrors.New("subscription not found")
ErrSubscriptionNotFound is returned when attempting to unsubscribe from a subscription that does not exist.
Functions ¶
func NewFileNotification ¶
func NewFileNotification( ctx context.Context, fileInfo wlstructs.FileInfo, event websocket_mod.WsEvent, options ...FileNotificationOptions, ) []websocket_mod.WsResponseInfo
NewFileNotification creates websocket notifications for a file event, including notifications for the file, its parent folder, and optionally a pre-move parent if the file was moved.
func NewPoolNotification ¶
func NewPoolNotification(pool *task.Pool, event websocket_mod.WsEvent, result task.Result) websocket_mod.WsResponseInfo
NewPoolNotification creates a websocket notification for a task pool event with the given result.
func NewSystemNotification ¶
func NewSystemNotification(event websocket_mod.WsEvent, data websocket_mod.WsData) websocket_mod.WsResponseInfo
NewSystemNotification creates a websocket notification for a system-wide event with the given data.
func NewTaskNotification ¶
func NewTaskNotification(task Jobber, event websocket_mod.WsEvent, result task.Result) websocket_mod.WsResponseInfo
NewTaskNotification creates a websocket notification for a task event with the given result.
Types ¶
type ClientManager ¶
type ClientManager struct {
// contains filtered or unexported fields
}
ClientManager manages websocket client connections and their subscriptions to various resources.
func NewClientManager ¶
func NewClientManager(ctx context.Context) *ClientManager
NewClientManager creates and initializes a new ClientManager with a background notification worker.
func (*ClientManager) ClientConnect ¶
func (cm *ClientManager) ClientConnect(ctx context.Context, conn *websocket.Conn, user *user_model.User) (*websocket_model.WsClient, error)
ClientConnect establishes a new websocket connection for a user and registers the client with the manager.
func (*ClientManager) ClientDisconnect ¶
func (cm *ClientManager) ClientDisconnect(ctx context.Context, c *websocket_model.WsClient) error
ClientDisconnect removes a client from all subscriptions and disconnects them from the manager.
func (*ClientManager) DisconnectAll ¶
func (cm *ClientManager) DisconnectAll(ctx context.Context) error
DisconnectAll disconnects all connected clients from the manager.
func (*ClientManager) Flush ¶
func (cm *ClientManager) Flush(ctx context.Context)
Flush loads a no-op message into the notification channel as a sort of "tracer round", and then waits for the notification worker to process it. This is useful to ensure that all pending notifications are sent before a task forces all clients to unsubscribe, etc.
func (*ClientManager) FolderSubToTask ¶
func (cm *ClientManager) FolderSubToTask(ctx context.Context, folderID string, task IDer)
FolderSubToTask subscribes all clients watching a folder to a task associated with that folder.
func (*ClientManager) GetAllClients ¶
func (cm *ClientManager) GetAllClients() []*websocket_model.WsClient
GetAllClients returns a slice of all connected web and remote clients.
func (*ClientManager) GetClientByTowerID ¶
func (cm *ClientManager) GetClientByTowerID(towerID string) *websocket_model.WsClient
GetClientByTowerID returns the websocket client for the specified tower ID, or nil if not found.
func (*ClientManager) GetClientByUsername ¶
func (cm *ClientManager) GetClientByUsername(username string) *websocket_model.WsClient
GetClientByUsername returns the websocket client for the specified username, or nil if not found.
func (*ClientManager) GetConnectedAdmins ¶
func (cm *ClientManager) GetConnectedAdmins() []*websocket_model.WsClient
GetConnectedAdmins returns a slice of all connected clients that have admin privileges.
func (*ClientManager) GetCoreByTowerID ¶
func (cm *ClientManager) GetCoreByTowerID(towerID string) *websocket_model.WsClient
GetCoreByTowerID returns the core websocket client for the specified tower ID, or nil if not found.
func (*ClientManager) GetSubscribers ¶
func (cm *ClientManager) GetSubscribers(ctx context.Context, st websocket_mod.SubscriptionType, key string) (clients []*websocket_model.WsClient)
GetSubscribers returns a slice of all clients subscribed to the specified subscription type and key.
func (*ClientManager) ListenForTowerUpdate ¶
func (cm *ClientManager) ListenForTowerUpdate(tower tower_model.Instance) (notifyChan chan struct{})
ListenForTowerUpdate returns a notification channel for the specified tower to signal when an immediate update is needed.
func (*ClientManager) Notify ¶
func (cm *ClientManager) Notify(ctx context.Context, msg ...websocket_mod.WsResponseInfo)
Notify queues one or more websocket messages to be sent to clients by the notification worker.
func (*ClientManager) PushTowerUpdate ¶
func (cm *ClientManager) PushTowerUpdate(tower tower_model.Instance) bool
PushTowerUpdate signals to the specified tower's update listener that an immediate update is needed.
func (*ClientManager) Relay ¶
func (cm *ClientManager) Relay(_ websocket_mod.WsResponseInfo)
Relay forwards a websocket message to connected remote instances.
func (*ClientManager) RemoteConnect ¶
func (cm *ClientManager) RemoteConnect(ctx context.Context, conn *websocket.Conn, remote *tower_model.Instance) *websocket_model.WsClient
RemoteConnect establishes a websocket connection for a remote instance and notifies all clients of the connection.
func (*ClientManager) Send ¶
func (cm *ClientManager) Send(ctx context.Context, msg websocket_mod.WsResponseInfo)
Send broadcasts a websocket message to all clients subscribed to the message's subscription key.
func (*ClientManager) SubscribeToFile ¶
func (cm *ClientManager) SubscribeToFile(ctx context.Context, c *client_model.WsClient, file IDer, subTime time.Time) error
SubscribeToFile subscribes a client to receive notifications for changes to a specific file.
func (*ClientManager) SubscribeToTask ¶
func (cm *ClientManager) SubscribeToTask(ctx context.Context, c *client_model.WsClient, task IDer, subTime time.Time) error
SubscribeToTask subscribes a client to receive notifications for a specific task.
func (*ClientManager) Unsubscribe ¶
func (cm *ClientManager) Unsubscribe(ctx context.Context, client *websocket_model.WsClient, key string, unSubTime time.Time) error
Unsubscribe removes a client's subscription to the specified key if the subscription exists and was created before the unsubscribe time.
func (*ClientManager) UnsubscribeAllByID ¶
func (cm *ClientManager) UnsubscribeAllByID(ctx context.Context, subID string, subscriptionType websocket_mod.SubscriptionType) error
UnsubscribeAllByID unsubscribes all clients from a subscription, by its ID. Useful to unsub all from a task when it completes or is canceled, for example.
type FileNotificationOptions ¶
FileNotificationOptions contains optional parameters for file notifications.