pubsub

package
v4.0.0-...-ac11496 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StandardCommandCallbacks = map[string]CommandCallback{
	"PONG":     IgnoreCommand,
	"RESPONSE": IgnoreCommand,

	"RECONNECT": func(client *Client, message *Message) error {
		_ = client.Connection.Close(websocket.StatusNormalClosure, "")
		client.Connection = nil
		return nil
	},
}

Functions

func IgnoreCommand

func IgnoreCommand(_ *Client, _ *Message) error

func RandomNone

func RandomNone() string

Types

type Client

type Client struct {
	Connection        *websocket.Conn
	Topics            map[string]int
	TopicsMutex       sync.Mutex
	CommandCallbacks  map[string]CommandCallback
	ReconnectAttempts int
}

func NewClient

func NewClient() *Client

func (*Client) AddShoutoutChannel

func (client *Client) AddShoutoutChannel(broadcasterID string) error

func (*Client) Backoff

func (client *Client) Backoff()

func (*Client) Close

func (client *Client) Close()

func (*Client) Connect

func (client *Client) Connect() error

func (*Client) Forever

func (client *Client) Forever()

func (*Client) Listen

func (client *Client) Listen(topics ...string) error

func (*Client) Loop

func (client *Client) Loop() error

func (*Client) Ping

func (client *Client) Ping() error

func (*Client) Receive

func (client *Client) Receive() (*Message, error)

func (*Client) ReceiveWithContext

func (client *Client) ReceiveWithContext(ctx context.Context) (*Message, error)

func (*Client) RemoveShoutoutChannel

func (client *Client) RemoveShoutoutChannel(broadcasterID string) error

func (*Client) Send

func (client *Client) Send(message *Message) error

func (*Client) SendRegistration

func (client *Client) SendRegistration() error

func (*Client) Unlisten

func (client *Client) Unlisten(topics ...string) error

type CommandCallback

type CommandCallback func(client *Client, message *Message) error

type Message

type Message struct {
	Type  string      `json:"type"`
	Error string      `json:"error,omitempty"`
	Nonce string      `json:"nonce,omitempty"`
	Data  MessageData `json:"data,omitempty"`
}

func (*Message) AddNonce

func (message *Message) AddNonce() *Message

type MessageData

type MessageData struct {
	Topics  []string `json:"topics,omitempty"`
	Topic   string   `json:"topic,omitempty"`
	Message string   `json:"message,omitempty" json:"message,omitempty"`
}

type ShoutoutPayload

type ShoutoutPayload struct {
	Type string `json:"type,omitempty"`
	Data struct {
		BroadcasterUserID         string `json:"broadcasterUserID,omitempty"`
		TargetUserID              string `json:"targetUserID,omitempty"`
		TargetLogin               string `json:"targetLogin,omitempty"`
		TargetUserProfileImageURL string `json:"targetUserProfileImageURL,omitempty"`
		SourceUserID              string `json:"sourceUserID,omitempty"`
		SourceLogin               string `json:"sourceLogin,omitempty"`
		ShoutoutID                string `json:"shoutoutID,omitempty"`
		TargetUserDisplayName     string `json:"targetUserDisplayName,omitempty"`
		TargetUserCTAInfo         string `json:"targetUserCTAInfo,omitempty"`
		TargetUserPrimaryColorHex string `json:"targetUserPrimaryColorHex,omitempty"`
	} `json:"data"`
}

type TopicsData

type TopicsData struct {
	Topics []string `json:"topics,omitempty"`
}

Jump to

Keyboard shortcuts

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