campfire

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package campfire provides the campfire service to webmesh clients.

Index

Constants

View Source
const (
	// CampFirePrefix is the prefix for campfire service paths.
	CampFirePrefix = "/campfire"
	// RoomsPrefix is the prefix for campfire rooms.
	RoomsPrefix = CampFirePrefix + "/rooms"
)
View Source
const (
	CampfireEnabledEnvVar   = "SERVICES_CAMPFIRE_ENABLED"
	CampfireListenUDPEnvVar = "SERVICES_CAMPFIRE_LISTEN_UDP"
)
View Source
const DefaultListenUDP = ":4095"

DefaultListenUDP is the default UDP address to listen on.

Variables

View Source
var EOF = io.EOF

EOF is an EOF error.

Functions

This section is empty.

Types

type Client

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

Client is the campfire client.

func NewClient

func NewClient(addr string) (*Client, error)

NewClient returns a new campfire client.

func NewClientWithID

func NewClientWithID(addr, id string) (*Client, error)

NewClientWithID returns a new campfire client with the given id.

func (*Client) Close

func (c *Client) Close(ctx context.Context) error

Close closes the client and leaves all rooms.

func (*Client) ID

func (c *Client) ID() string

ID returns the client id.

func (*Client) Join

func (c *Client) Join(ctx context.Context, name string) error

Join joins the room with the given name.

func (*Client) Leave

func (c *Client) Leave(ctx context.Context, name string) error

Leave leaves the room with the given name.

func (*Client) List

func (c *Client) List(ctx context.Context, name string) ([]string, error)

List lists the members of the room with the given name.

func (*Client) Messages

func (c *Client) Messages() <-chan Message

Messages returns the message channel.

func (*Client) Send

func (c *Client) Send(ctx context.Context, name, to, msg string) error

Send sends a message to the room with the given name. If to is not empty, the message is sent to the given recipient.

type Message

type Message struct {
	// Type is the message type.
	Type MessageType
	// Room is the room.
	Room string
	// From is the sender.
	From string
	// To is the recipient.
	To string
	// Body is the message body.
	Body string
}

Message is a campfire message.

func ParseMessage

func ParseMessage(b []byte) (Message, error)

ParseMessage parses a message from the wire form.

func (Message) Encode

func (m Message) Encode() ([]byte, error)

Encode encodes a message to wire form.

type MessageStream

type MessageStream struct {
	net.Conn
}

func NewMessageStream

func NewMessageStream(c net.Conn) *MessageStream

func (*MessageStream) RecvMessage

func (m *MessageStream) RecvMessage() (Message, error)

func (*MessageStream) SendMessage

func (m *MessageStream) SendMessage(msg Message) error

type MessageType

type MessageType int

MessageType is a message type.

const (
	// MessageTypeUnknown is an unknown message type.
	MessageTypeUnknown MessageType = iota
	// MessageTypeJoin is a join message type.
	MessageTypeJoin
	// MessageTypeLeave is a leave message type.
	MessageTypeLeave
	// MessageTypeList is a list message type.
	MessageTypeList
	// MessageTypeMessage is a message message type.
	MessageTypeMessage
	// MessageTypeMember is a member message type.
	// This is a server-only message type.
	MessageTypeMember
	// MessageTypeACK is an ACK message type.
	// This is a server-only message type.
	MessageTypeACK
	// MessageTypeError is an error message type.
	// This is a server-only message type.
	MessageTypeError
)

type Options

type Options struct {
	// Enabled is whether the campfire service is enabled.
	Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty" toml:"enabled,omitempty" mapstructure:"enabled,omitempty"`
	// ListenUDP is the UDP address to listen on.
	ListenUDP string `json:"listen-udp,omitempty" yaml:"listen-udp,omitempty" toml:"listen-udp,omitempty" mapstructure:"listen-udp,omitempty"`
}

Options are options for the campfire service.

func NewOptions

func NewOptions() *Options

NewOptions returns new campfire service options.

func (*Options) BindFlags

func (o *Options) BindFlags(fs *flag.FlagSet, prefix ...string)

BindFlags binds the campfire service options to flags.

func (*Options) DeepCopy added in v0.1.13

func (o *Options) DeepCopy() *Options

DeepCopy returns a deep copy of the campfire service options.

func (*Options) Validate

func (o *Options) Validate() error

Validate validates the campfire service options.

type RoomManager

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

RoomManager is the room manager.

func NewRoomManager

func NewRoomManager(mesh meshdb.Store, c net.PacketConn) (*RoomManager, error)

NewRoomManager returns a new room manager.

func (*RoomManager) Close

func (r *RoomManager) Close()

Close closes the room manager.

func (*RoomManager) HandleMessage

func (r *RoomManager) HandleMessage(srcaddr net.Addr, msg *Message)

HandleMessage handles a campfire message.

type Server

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

Server is the campfire service.

func NewServer

func NewServer(mesh meshdb.Store, opts *Options) *Server

NewServer returns a new campfire service.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context) error

ListenAndServe listens and serves the campfire service.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context)

Shutdown shuts down the campfire service.

Jump to

Keyboard shortcuts

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