receive

package
v4.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: BSD-2-Clause, BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const AnyType = catalog.NoType

ID to respond to any message type

Variables

This section is empty.

Functions

func AnyUser

func AnyUser() *id.ID

ID to respond to any user

Types

type Listener

type Listener interface {
	// the Hear function is called to exercise the listener, passing in the
	// data as an item
	Hear(item Message)
	// Returns a name, used for debugging
	Name() string
}

Listener interface for a listener adhere to

type ListenerFunc

type ListenerFunc func(item Message)

ListenerFunc This function type defines callbacks that get passed when the listener is listened to. It will always be called in its own goroutine. It may be called multiple times simultaneously

type ListenerID

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

ListenerID id object returned when a listener is created and is used to delete it from the system

func (ListenerID) GetMessageType

func (lid ListenerID) GetMessageType() catalog.MessageType

GetMessageType getter for message type

func (ListenerID) GetName

func (lid ListenerID) GetName() string

GetName getter for name

func (ListenerID) GetUserID

func (lid ListenerID) GetUserID() *id.ID

GetUserID getter for userID

func (ListenerID) String

func (lid ListenerID) String() string

String returns the values in the ListenerID in a human-readable format. This functions adheres to the fmt.Stringer interface.

type Message

type Message struct {
	MessageType catalog.MessageType
	ID          e2e.MessageID
	Payload     []byte

	Sender      *id.ID
	RecipientID *id.ID
	EphemeralID ephemeral.Id
	Timestamp   time.Time // Message timestamp of when the user sent

	Encrypted bool

	Round rounds.Round
}

type Switchboard

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

func New

func New() *Switchboard

New generates and returns a new switchboard object.

func (*Switchboard) RegisterChannel

func (sw *Switchboard) RegisterChannel(name string, user *id.ID,
	messageType catalog.MessageType, newListener chan Message) ListenerID

RegisterChannel Registers a new listener built around the passed channel. Returns the ID of the new listener. Keep this around if you want to be able to delete the listener later.

name is used for debug printing and not checked for uniqueness

user: 0 for all, or any user ID to listen for messages from a particular user. 0 can be id.ZeroUser or id.ZeroID messageType: 0 for all, or any message type to listen for messages of that type. 0 can be Message.AnyType newListener: an item channel. Do not pass nil to this.

If a message matches multiple listeners, all of them will hear the message.

func (*Switchboard) RegisterFunc

func (sw *Switchboard) RegisterFunc(name string, user *id.ID,
	messageType catalog.MessageType, newListener ListenerFunc) ListenerID

RegisterFunc Registers a new listener built around the passed function. Returns the ID of the new listener. Keep this around if you want to be able to delete the listener later.

name is used for debug printing and not checked for uniqueness

user: 0 for all, or any user ID to listen for messages from a particular user. 0 can be id.ZeroUser or id.ZeroID messageType: 0 for all, or any message type to listen for messages of that type. 0 can be Message.AnyType newListener: a function implementing the ListenerFunc function type. Do not pass nil to this.

If a message matches multiple listeners, all of them will hear the message.

func (*Switchboard) RegisterListener

func (sw *Switchboard) RegisterListener(user *id.ID,
	messageType catalog.MessageType, newListener Listener) ListenerID

RegisterListener Registers a new listener. Returns the ID of the new listener. Keep this around if you want to be able to delete the listener later.

name is used for debug printing and not checked for uniqueness

user: 0 for all, or any user ID to listen for messages from a particular user. 0 can be id.ZeroUser or id.ZeroID messageType: 0 for all, or any message type to listen for messages of that type. 0 can be Message.AnyType newListener: something implementing the Listener interface. Do not pass nil to this.

If a message matches multiple listeners, all of them will hear the message.

func (*Switchboard) Speak

func (sw *Switchboard) Speak(item Message)

Speak broadcasts a message to the appropriate listeners. each is spoken to in their own goroutine

func (*Switchboard) Unregister

func (sw *Switchboard) Unregister(listenerID ListenerID)

Unregister removes the listener with the specified ID so it will no longer get called

func (*Switchboard) UnregisterUserListeners

func (sw *Switchboard) UnregisterUserListeners(userID *id.ID)

UnregisterUserListeners removes all the listeners registered with the specified user.

Jump to

Keyboard shortcuts

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