notifier

package
v5.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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

type ClientManager struct {
	Clients map[Client]bool
	// contains filtered or unexported fields
}

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 of 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 C

func C() *Notifier

C is used to access the global notifier singleton

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) Register

func (notifier *Notifier) Register(client Client) error

Register add a new client to the client manager pool

func (*Notifier) Send

func (notifier *Notifier) Send(message []byte, client Client)

Send send a byte slices to a specific websocket client

func (*Notifier) SendToRoles

func (notifier *Notifier) SendToRoles(cacheKey string, timeout time.Duration, notif notification.Notification, roles []uuid.UUID)

SendToRoles send a notification to every user related to the input list of roles

func (*Notifier) SendToUsers

func (notifier *Notifier) SendToUsers(notif notification.Notification, users []uuid.UUID)

SendToUsers send a notification to users corresponding the input ids

func (*Notifier) Unregister

func (notifier *Notifier) Unregister(client Client) error

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

func (*SSEClient) Read

func (c *SSEClient) Read()

func (*SSEClient) Write

func (c *SSEClient) Write()

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL