events

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ID           string
	Remote       string
	Listener     string
	Username     []byte
	CleanSession bool
	First        bool
}

Client contains limited information about a connected client.

type Clientlike

type Clientlike interface {
	Info() Client
}

Clientlike is an interface for Clients and client-like objects that are able to describe their client/listener IDs and remote address.

type Events

type Events struct {
	OnProcessMessage // published message receieved before evaluation.
	OnMessage        // published message receieved.
	OnError          // server error.
	OnConnect        // client connected.
	OnDisconnect     // client disconnected.
	OnSubscribe      // topic subscription created.
	OnUnsubscribe    // topic subscription removed.
}

Events provides callback handlers for different event hooks.

type OnConnect

type OnConnect func(Client, Packet)

OnConnect is called when a client successfully connects to the broker.

type OnDisconnect

type OnDisconnect func(Client, error)

OnDisconnect is called when a client disconnects to the broker. An error value is passed to the function if the client disconnected abnormally, otherwise it will be nil on a normal disconnect.

type OnError

type OnError func(Client, error)

OnError is called when errors that will not be passed to OnDisconnect are handled by the server.

type OnMessage

type OnMessage func(Client, Packet) (Packet, error)

OnMessage function is called when a publish message is received. Note, this hook is ONLY called by connected client publishers, it is not triggered when using the direct s.Publish method. The function receives the sent message and the data of the client who published it, and allows the packet to be modified before it is dispatched to subscribers. If no modification is required, return the original packet data. If an error occurs, the original packet will be dispatched as if the event hook had not been triggered. This function will block message dispatching until it returns. To minimise this, have the function open a new goroutine on the embedding side.

type OnProcessMessage

type OnProcessMessage func(Client, Packet) (Packet, error)

OnProcessMessage is called when a publish message is received, allowing modification of the packet data after ACL checking has occurred but before any data is evaluated for processing - e.g. for changing the Retain flag. Note, this hook is ONLY called by connected client publishers, it is not triggered when using the direct s.Publish method. The function receives the sent message and the data of the client who published it, and allows the packet to be modified before it is dispatched to subscribers. If no modification is required, return the original packet data. If an error occurs, the original packet will be dispatched as if the event hook had not been triggered. This function will block message dispatching until it returns. To minimise this, have the function open a new goroutine on the embedding side. The `mqtt.ErrRejectPacket` error can be returned to reject and abandon any further processing of the packet.

type OnSubscribe

type OnSubscribe func(filter string, cl Client, qos byte, isFirst bool)

OnSubscribe is called when a new subscription filter for a client is created.

type OnUnsubscribe

type OnUnsubscribe func(filter string, cl Client, isLast bool)

OnUnsubscribe is called when an existing subscription filter for a client is removed.

type Packet

type Packet = packets.Packet

Packets is an alias for packets.Packet.

Jump to

Keyboard shortcuts

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