pubsub

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package pubsub contains LISTEN/NOTIFY structs for v2 poll data and v3 poller control

Index

Constants

View Source
const ChanV2 = "v2ch"

The channel which has V2* payloads

View Source
const ChanV3 = "v3ch"

The channel which has V3* payloads

Variables

This section is empty.

Functions

This section is empty.

Types

type Listener

type Listener interface {
	// Begin listening on this channel with this callback starting from this position. Blocks until Close() is called.
	Listen(chanName string, start int64, fn func(p PartialWrapper)) error
	// Close the listener. No more callbacks should fire.
	Close() error
}

Listener represents the common functions required by all subscription listeners

type Notifier

type Notifier interface {
	// Notify chanName that there is a new payload p. Return an error if we failed to send the notification.
	Notify(chanName string, p Payload) error
}

Notifier represents the common functions required by all notifiers

type PartialWrapper

type PartialWrapper struct {
	PayloadType string          `json:"t"`
	Payload     json.RawMessage `json:"p"`
}

PartialWrapper partially decodes Wrapper, enough to work out the type of payload.

func (PartialWrapper) Type

func (p PartialWrapper) Type() string

type Payload

type Payload interface {
	Type() string
}

Every payload needs a type to distinguish what kind of update it is.

type V2AccountData

type V2AccountData struct {
	UserID string
	RoomID string
	Types  []string
}

func (V2AccountData) Type

func (v V2AccountData) Type() string

type V2Accumulate

type V2Accumulate struct {
	RoomID    string
	PrevBatch string
	EventNIDs []int64
}

func (V2Accumulate) Type

func (v V2Accumulate) Type() string

type V2DeviceData

type V2DeviceData struct {
	Pos int64
}

func (V2DeviceData) Type

func (v V2DeviceData) Type() string

type V2InitialSyncComplete

type V2InitialSyncComplete struct {
	UserID   string
	DeviceID string
}

func (V2InitialSyncComplete) Type

func (v V2InitialSyncComplete) Type() string

type V2Initialise

type V2Initialise struct {
	RoomID      string
	SnapshotNID int64
}

func (V2Initialise) Type

func (v V2Initialise) Type() string

type V2InviteRoom

type V2InviteRoom struct {
	UserID string
	RoomID string
}

func (V2InviteRoom) Type

func (v V2InviteRoom) Type() string

type V2LeaveRoom

type V2LeaveRoom struct {
	UserID string
	RoomID string
}

func (V2LeaveRoom) Type

func (v V2LeaveRoom) Type() string

type V2Pub

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

V2Pub receives v2 data and persists it in the DB, then sends NOTIFY updates.

func NewV2Pub

func NewV2Pub(notifier Notifier, enablePrometheus bool) *V2Pub

func (*V2Pub) Notify

func (p *V2Pub) Notify(payload Payload) error

func (*V2Pub) Teardown added in v0.7.4

func (p *V2Pub) Teardown()

type V2Receipt added in v0.7.3

type V2Receipt struct {
	RoomID   string
	Receipts []internal.Receipt
}

func (V2Receipt) Type added in v0.7.3

func (v V2Receipt) Type() string

type V2Sub

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

func NewV2Sub

func NewV2Sub(l Listener, recv V2SubReceiver) *V2Sub

func (*V2Sub) Listen

func (v *V2Sub) Listen(start int64) error

func (*V2Sub) Teardown

func (v *V2Sub) Teardown()

type V2SubReceiver

type V2SubReceiver interface {
	Initialise(p *V2Initialise)
	Accumulate(p *V2Accumulate)
	OnAccountData(p *V2AccountData)
	OnInvite(p *V2InviteRoom)
	OnLeftRoom(p *V2LeaveRoom)
	OnUnreadCounts(p *V2UnreadCounts)
	OnInitialSyncComplete(p *V2InitialSyncComplete)
	OnDeviceData(p *V2DeviceData)
	OnTyping(p *V2Typing)
	OnReceipt(p *V2Receipt)
}

type V2Typing added in v0.7.2

type V2Typing struct {
	RoomID         string
	EphemeralEvent json.RawMessage
}

func (V2Typing) Type added in v0.7.2

func (v V2Typing) Type() string

type V2UnreadCounts

type V2UnreadCounts struct {
	UserID            string
	RoomID            string
	HighlightCount    *int
	NotificationCount *int
}

func (V2UnreadCounts) Type

func (v V2UnreadCounts) Type() string

type V3EnsurePolling

type V3EnsurePolling struct {
	UserID   string
	DeviceID string
}

func (V3EnsurePolling) Type

func (v V3EnsurePolling) Type() string

type V3Pub

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

V3Pub sends signalling messages to v2 pollers

func NewV3Pub

func NewV3Pub(notifier Notifier, enablePrometheus bool) *V3Pub

func (*V3Pub) EnsurePolling

func (p *V3Pub) EnsurePolling(userID, deviceID string)

EnsurePolling blocks until the V2InitialSyncComplete response is received for this device. It is the caller's responsibility to call OnInitialSyncComplete when new events arrive.

func (*V3Pub) OnInitialSyncComplete

func (p *V3Pub) OnInitialSyncComplete(payload *V2InitialSyncComplete)

func (*V3Pub) Teardown added in v0.7.4

func (p *V3Pub) Teardown()

type V3Sub

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

func NewV3Sub

func NewV3Sub(l Listener, recv V3SubReceiver) *V3Sub

func (*V3Sub) Listen

func (v *V3Sub) Listen(start int64) error

func (*V3Sub) Teardown

func (v *V3Sub) Teardown()

type V3SubReceiver

type V3SubReceiver interface {
	EnsurePolling(p *V3EnsurePolling)
}

type Wrapper

type Wrapper struct {
	Type    string      `json:"t"`
	Payload interface{} `json:"p"`
}

Wrapper is serialised and sent over the wire.

Jump to

Keyboard shortcuts

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