hub

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const RoomBufSize = 128

RoomBufSize is the number of incoming messages to buffer for each topic.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Message  string
	SenderID string

	Annotations map[string]string
}

Message gets converted to/from JSON and sent in the body of pubsub messages.

func NewMessage

func NewMessage(s string) *Message

func (*Message) Apply

func (m *Message) Apply(opts ...MessageOption) error

Apply applies the given options to the config, returning the first error encountered (if any).

func (*Message) Copy

func (m *Message) Copy() *Message

func (*Message) Seal

func (m *Message) Seal(key string) error

func (*Message) Unseal

func (m *Message) Unseal(key string) error

func (*Message) WithMessage

func (m *Message) WithMessage(s string) *Message

type MessageOption

type MessageOption func(cfg *Message) error

type Room

type Room struct {
	// Messages is a channel of messages received from other peers in the chat room
	Messages chan *Message
	// contains filtered or unexported fields
}

Room represents a subscription to a single PubSub topic. Messages can be published to the topic with Room.Publish, and received messages are pushed to the Messages channel.

func JoinRoom

func JoinRoom(ctx context.Context, ps *pubsub.PubSub, selfID peer.ID, roomName string) (*Room, error)

JoinRoom tries to subscribe to the PubSub topic for the room name, returning a Room on success.

func (*Room) Publish

func (cr *Room) Publish(message string, o ...func(*Message)) error

Publish sends a message to the pubsub topic.

func (*Room) PublishMessage

func (cr *Room) PublishMessage(m *Message) error

Publish sends a message to the pubsub topic.

Jump to

Keyboard shortcuts

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