nc

package
v0.0.0-...-851e5e8 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package nc provides a MQTT client to connect to the Notification Centre server. MQTT could be viewed as an application layer version of TCP since it uses similar mechanisms to ensure message delivery.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCredentials = fmt.Errorf("stored credentials are not valid")

Functions

This section is empty.

Types

type AcknowledgementPayload

type AcknowledgementPayload struct {
	MessageID  string `json:"message_id"`
	TrackType  string `json:"track_type"`
	ActionSlug string `json:"action_slug"`
}

type ActionPayload

type ActionPayload struct {
	Name string `json:"name"`
	URL  string `json:"url"`
	Slug string `json:"slug"`
}

type AttributePayload

type AttributePayload struct {
	InviteeID        string   `json:"invitee_id"`
	ServerID         int      `json:"server_id"`
	ServerIP         string   `json:"server_ip"`
	AffectedMachines []string `json:"affected_machines"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a client for Notification center

func NewClient

func NewClient(
	clientBuilder ClientBuilder,
	subjectInfo events.Publisher[string],
	subjectErr events.Publisher[error],
	subjectPeerUpdate events.Publisher[[]string],
	credsFetcher CredentialsGetter,
) *Client

NewClient is a constructor for a NC client

func (*Client) Start

func (c *Client) Start() error

Start initiates the connection with the NC server and subscribes to mandatory topics

func (*Client) Stop

func (c *Client) Stop() error

Stop unsubscribes the topics and drops a connection with the NC server

type ClientBuilder

type ClientBuilder interface {
	Build(opts *mqtt.ClientOptions) mqtt.Client
}

type ConfirmationPayload

type ConfirmationPayload struct {
	MessageID string `json:"message_id"`
}

type CredentialsGetter

type CredentialsGetter struct {
	// contains filtered or unexported fields
}

func (*CredentialsGetter) GetCredentialsFromAPI

func (cf *CredentialsGetter) GetCredentialsFromAPI() (config.NCData, error)

GetCredentials fetches credentials from core API and saves them in local config

func (*CredentialsGetter) GetCredentialsFromConfig

func (cf *CredentialsGetter) GetCredentialsFromConfig() (config.NCData, error)

GetCredentialsFromConfig loads credentials from local config

type DataPayload

type DataPayload struct {
	Event    EventPayload    `json:"event"`
	Metadata MetadataPayload `json:"metadata"`
}

type EventPayload

type EventPayload struct {
	Type       string           `json:"type"`
	Attributes AttributePayload `json:"attributes"`
}

type MessagePayload

type MessagePayload struct {
	Data         DataPayload         `json:"data"`
	Notification NotificationPayload `json:"notification"`
}

type MetadataPayload

type MetadataPayload struct {
	Acked     bool   `json:"acked"`
	CreatedAt int    `json:"created_at"`
	MessageID string `json:"message_id"`
	TargetUID string `json:"target_uid"`
}

type MqttClientBuilder

type MqttClientBuilder struct{}

func (MqttClientBuilder) Build

type NotificationClient

type NotificationClient interface {
	Start() error
	Stop() error
}

type NotificationPayload

type NotificationPayload struct {
	Title   string          `json:"title"`
	Body    string          `json:"body"`
	Actions []ActionPayload `json:"actions"`
}

type RecPayload

type RecPayload struct {
	Message MessagePayload `json:"message"`
}

RecPayload defines a payload sent by a NC

Jump to

Keyboard shortcuts

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