Documentation ¶
Index ¶
- func ReplaceGlobals(notifier *Notifier) func()
- type Client
- type ClientManager
- type GenericClient
- type Notifier
- func (notifier *Notifier) Broadcast(notif notification.Notification)
- func (notifier *Notifier) CleanCache()
- func (notifier *Notifier) Register(client Client) error
- func (notifier *Notifier) Send(message []byte, client Client)
- func (notifier *Notifier) SendToUser(notif notification.Notification, user users.UserWithPermissions) error
- func (notifier *Notifier) SendToUserLogin(notif notification.Notification, login string) error
- func (notifier *Notifier) SendToUserLogins(notif notification.Notification, users []string) error
- func (notifier *Notifier) SendToUsers(notif notification.Notification, users []users.UserWithPermissions) error
- func (notifier *Notifier) Unregister(client Client) error
- type SSEClient
- type WebsocketClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReplaceGlobals ¶
func ReplaceGlobals(notifier *Notifier) func()
ReplaceGlobals affect a new notifier to the global notifier singleton
Types ¶
type Client ¶
type Client interface { GetUser() *users.UserWithPermissions GetSendChannel() chan []byte Read() Write() }
Client is used as an abstract notifier client, which could use SSE or WS implementations
type ClientManager ¶
ClientManager is the websocket client pool manager It is used only to manage the client pool, and read/write on a specific client using raw byte slice message
func NewClientManager ¶
func NewClientManager() *ClientManager
NewClientManager renders a new manager responsible for every connection
func (*ClientManager) GetClients ¶
func (manager *ClientManager) GetClients() []Client
GetClients returns all clients of the manager
func (*ClientManager) Register ¶
func (manager *ClientManager) Register(newClient Client) error
Register registers a new client
func (*ClientManager) Unregister ¶
func (manager *ClientManager) Unregister(existentClient Client) error
Unregister unregisters a client
type GenericClient ¶
type GenericClient struct { ID string Send chan []byte User *users.UserWithPermissions }
GenericClient is a standard notification client
func (*GenericClient) GetSendChannel ¶
func (c *GenericClient) GetSendChannel() chan []byte
GetSendChannel returns Send channel
func (*GenericClient) GetUser ¶
func (c *GenericClient) GetUser() *users.UserWithPermissions
GetUser returns current client user
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier is the main struct used to send notifications
func NewNotifier ¶
func NewNotifier() *Notifier
NewNotifier returns a pointer to a new instance of Notifier
func (*Notifier) Broadcast ¶
func (notifier *Notifier) Broadcast(notif notification.Notification)
Broadcast send a notification to every connected client
func (*Notifier) CleanCache ¶ added in v5.3.6
func (notifier *Notifier) CleanCache()
func (*Notifier) SendToUser ¶ added in v5.3.6
func (notifier *Notifier) SendToUser(notif notification.Notification, user users.UserWithPermissions) error
SendToUser send a notification to a specific user
func (*Notifier) SendToUserLogin ¶ added in v5.3.6
func (notifier *Notifier) SendToUserLogin(notif notification.Notification, login string) error
SendToUserLogin send a notification to a specific user using his login
func (*Notifier) SendToUserLogins ¶ added in v5.3.6
func (notifier *Notifier) SendToUserLogins(notif notification.Notification, users []string) error
SendToUserLogins send a notification to user logins corresponding the input ids
func (*Notifier) SendToUsers ¶
func (notifier *Notifier) SendToUsers(notif notification.Notification, users []users.UserWithPermissions) error
SendToUsers send a notification to users corresponding the input ids
func (*Notifier) Unregister ¶
Unregister disconnect an existing client from the client manager pool
type SSEClient ¶
type SSEClient struct { GenericClient // contains filtered or unexported fields }
SSEClient represents a single specific server-sent event connection
func BuildSSEClient ¶
func BuildSSEClient(w http.ResponseWriter, user *users.UserWithPermissions) (*SSEClient, error)
BuildSSEClient build and returns a new SSEClient
type WebsocketClient ¶
type WebsocketClient struct { GenericClient Socket *websocket.Conn Receive chan []byte }
WebsocketClient structure represents a specific websocket connection, used by the manager
func BuildWebsocketClient ¶
func BuildWebsocketClient(w http.ResponseWriter, r *http.Request, user *users.UserWithPermissions) (*WebsocketClient, error)
BuildWebsocketClient renders a new client after getting a new connection established
func NewWebsocketClient ¶
func NewWebsocketClient(conn *websocket.Conn, user *users.UserWithPermissions) *WebsocketClient
NewWebsocketClient creates a new client object containing the new connection
func (*WebsocketClient) Read ¶
func (c *WebsocketClient) Read()
Read a message from one client and broadcast it to others
func (*WebsocketClient) Write ¶
func (c *WebsocketClient) Write()
Write a message on a client socket