api

package
v0.0.0-...-2ee6939 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: AGPL-3.0 Imports: 51 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BroadcastChannels = sync.Map{} // [string (channel-name)] -> *BroadcastChannel
	UnifiedSSE        = &EventSourceServer{
		EventBus:  EventBus.New(),
		WaitGroup: &sync.WaitGroup{},
		Subscriber: &EventSourceSubscriber{
			lock:  &sync.Mutex{},
			count: 0,
		},
	}
)

Functions

func DestroyBroadcastChannel

func DestroyBroadcastChannel(channel string, force bool) bool

DestroyBroadcastChannel tries to destroy a broadcast channel

Return true if the channel destroy successfully, otherwise false

func PruneBroadcastChannels

func PruneBroadcastChannels() []string

PruneBroadcastChannels prunes all broadcast channels without subscribers

func SQL

func SQL(c *gin.Context)

func ServeAPI

func ServeAPI(ginServer *gin.Engine)

Types

type BroadcastChannel

type BroadcastChannel struct {
	Name       string // channel name
	WebSocket  *melody.Melody
	Subscriber *BroadcastSubscriber // SEE subscriber
}

func ConstructBroadcastChannel

func ConstructBroadcastChannel(channel string) *BroadcastChannel

ConstructBroadcastChannel creates a broadcast channel

func GetBroadcastChannel

func GetBroadcastChannel(channel string) *BroadcastChannel

GetBroadcastChannel gets a broadcast channel

If the channel does not exist but the SSE server is subscribed, it will create a new broadcast channel. If the SSE server is not subscribed, it will return nil.

func (*BroadcastChannel) BroadcastBinary

func (b *BroadcastChannel) BroadcastBinary(data []byte) (sent bool, err error)

BroadcastBinary broadcast binary message to all subscribers

func (*BroadcastChannel) BroadcastString

func (b *BroadcastChannel) BroadcastString(message string) (sent bool, err error)

BroadcastString broadcast string message to all subscribers

func (*BroadcastChannel) Destroy

func (b *BroadcastChannel) Destroy(force bool) bool

func (*BroadcastChannel) HandleRequest

func (b *BroadcastChannel) HandleRequest(c *gin.Context)

func (*BroadcastChannel) Subscribed

func (b *BroadcastChannel) Subscribed() bool

func (*BroadcastChannel) SubscriberCount

func (b *BroadcastChannel) SubscriberCount() int

SubscriberCount gets the total number of subscribers

type BroadcastSubscriber

type BroadcastSubscriber struct {
	Count int // SEE subscriber count
}

type ChannelInfo

type ChannelInfo struct {
	Name  string `json:"name"`
	Count int    `json:"count"`
}

type ColorScheme

type ColorScheme struct {
	Primary   string
	Secondary string
}

type DocFile

type DocFile struct {
	ID       string     `json:"id"`
	Children []*DocFile `json:"children,omitempty"`
}

type EventSourceServer

type EventSourceServer struct {
	EventBus   EventBus.Bus
	WaitGroup  *sync.WaitGroup
	Subscriber *EventSourceSubscriber
}

func (*EventSourceServer) GetRetry

func (s *EventSourceServer) GetRetry(c *gin.Context) uint

GetRetry gets the retry interval

If the retry interval is not specified, it will return 0

func (*EventSourceServer) SSEvent

func (s *EventSourceServer) SSEvent(c *gin.Context, event *sse.Event)

SSEvent writes a Server-Sent Event into the body stream.

func (*EventSourceServer) SendEvent

func (s *EventSourceServer) SendEvent(event *MessageEvent) bool

SendEvent sends a message to all subscribers

func (*EventSourceServer) Stream

func (s *EventSourceServer) Stream(c *gin.Context, step func(event *MessageEvent, ok bool) bool) bool

Stream streams message to client

If the client is gone, it will return true

func (*EventSourceServer) Subscribe

func (s *EventSourceServer) Subscribe(c *gin.Context, retry uint, channels ...string)

Subscribe subscribes to specified broadcast channels

func (*EventSourceServer) SubscribeAll

func (s *EventSourceServer) SubscribeAll(c *gin.Context, retry uint)

SubscribeAll subscribes to all broadcast channels

func (*EventSourceServer) Subscribed

func (s *EventSourceServer) Subscribed() bool

Subscribed checks whether the SSE server is subscribed

type EventSourceSubscriber

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

func (*EventSourceSubscriber) Count

func (s *EventSourceSubscriber) Count() int

type File

type File struct {
	Filename string
	Header   textproto.MIMEHeader
	Size     int64
	Content  string
}

type MessageEvent

type MessageEvent struct {
	ID   string // event ID
	Type MessageType
	Name string // channel name
	Data []byte
}

type MessageEventChannel

type MessageEventChannel chan *MessageEvent

type MessageID

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

func (*MessageID) Next

func (m *MessageID) Next() uint64

type MessageType

type MessageType string
const (
	MessageTypeString MessageType = "string"
	MessageTypeBinary MessageType = "binary"
	MessageTypeClose  MessageType = "close"

	EvtBroadcastMessage = "broadcast.message"
)

type MultipartForm

type MultipartForm struct {
	Value map[string][]string
	File  map[string][]File
}

type PublishMessage

type PublishMessage struct {
	Type     MessageType `json:"type"`     // "string" | "binary"
	Size     int         `json:"size"`     // message size
	Filename string      `json:"filename"` // empty string for string-message
}

type PublishResult

type PublishResult struct {
	Code int    `json:"code"` // 0: success
	Msg  string `json:"msg"`  // error message

	Channel ChannelInfo    `json:"channel"`
	Message PublishMessage `json:"message"`
}

type Workspace

type Workspace struct {
	Path   string `json:"path"`
	Closed bool   `json:"closed"`
}

Jump to

Keyboard shortcuts

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