presence

package
v0.0.0-...-996fa4a Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeStatus      = EventType("status")
	EventTypeSubscribe   = EventType("subscribe")
	EventTypeUnsubscribe = EventType("unsubscribe")
)

Various event types

Variables

This section is empty.

Functions

This section is empty.

Types

type EventType

type EventType string

EventType represents a presence event type

type Info

type Info struct {
	ID       string `json:"id"`                 // The subscriber ID.
	Username string `json:"username,omitempty"` // The subscriber username set by client ID.
}

Info represents a presence info for a single connection.

type Notification

type Notification struct {
	Time    int64        `json:"time"`    // The UNIX timestamp.
	Event   EventType    `json:"event"`   // The event, must be "status", "subscribe" or "unsubscribe".
	Channel string       `json:"channel"` // The target channel for the notification.
	Who     Info         `json:"who"`     // The subscriber id.
	Ssid    message.Ssid `json:"-"`       // The ssid to dispatch the notification on.
	// contains filtered or unexported fields
}

Notification represents a state notification.

func (*Notification) Encode

func (e *Notification) Encode() ([]byte, bool)

Encode encodes the presence notifications and returns a payload to send.

type Request

type Request struct {
	Key     string `json:"key"`     // The channel key for this request.
	Channel string `json:"channel"` // The target channel for this request.
	Status  bool   `json:"status"`  // Specifies that a status response should be sent.
	Changes *bool  `json:"changes"` // Specifies that the changes should be notified.
}

Request represents a presence request

type Response

type Response struct {
	Request uint16    `json:"req,omitempty"` // The corresponding request ID.
	Time    int64     `json:"time"`          // The UNIX timestamp.
	Event   EventType `json:"event"`         // The event, must be "status", "subscribe" or "unsubscribe".
	Channel string    `json:"channel"`       // The target channel for the notification.
	Who     []Info    `json:"who"`           // The subscriber ids.
}

Response represents a state notification.

func (*Response) ForRequest

func (r *Response) ForRequest(id uint16)

ForRequest sets the request ID in the response for matching

type Service

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

Service represents a publish service.

func New

func New(auth service.Authorizer, pubsub service.PubSub, survey service.Surveyor, trie *message.Trie) *Service

New creates a new publisher service.

func (*Service) Close

func (s *Service) Close()

Close closes gracefully the service.,

func (*Service) Notify

func (s *Service) Notify(eventType EventType, ev *event.Subscription, filter func(message.Subscriber) bool)

Notify queues up a notification to be sent later.

func (*Service) OnHTTP

func (s *Service) OnHTTP(w http.ResponseWriter, r *http.Request)

OnHTTP occurs when a new HTTP presence request is received.

func (*Service) OnRequest

func (s *Service) OnRequest(c service.Conn, payload []byte) (service.Response, bool)

OnRequest processes a presence request.

func (*Service) OnSurvey

func (s *Service) OnSurvey(queryType string, payload []byte) ([]byte, bool)

OnSurvey handles an incoming presence query.

Jump to

Keyboard shortcuts

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