Documentation ¶
Index ¶
- Variables
- func DestroyBroadcastChannel(channel string, force bool) bool
- func PruneBroadcastChannels() []string
- func SQL(c *gin.Context)
- func ServeAPI(ginServer *gin.Engine)
- type BroadcastChannel
- func (b *BroadcastChannel) BroadcastBinary(data []byte) (sent bool, err error)
- func (b *BroadcastChannel) BroadcastString(message string) (sent bool, err error)
- func (b *BroadcastChannel) Destroy(force bool) bool
- func (b *BroadcastChannel) HandleRequest(c *gin.Context)
- func (b *BroadcastChannel) Subscribed() bool
- func (b *BroadcastChannel) SubscriberCount() int
- type BroadcastSubscriber
- type ChannelInfo
- type ColorScheme
- type DocFile
- type EventSourceServer
- func (s *EventSourceServer) GetRetry(c *gin.Context) uint
- func (s *EventSourceServer) SSEvent(c *gin.Context, event *sse.Event)
- func (s *EventSourceServer) SendEvent(event *MessageEvent) bool
- func (s *EventSourceServer) Stream(c *gin.Context, step func(event *MessageEvent, ok bool) bool) bool
- func (s *EventSourceServer) Subscribe(c *gin.Context, retry uint, channels ...string)
- func (s *EventSourceServer) SubscribeAll(c *gin.Context, retry uint)
- func (s *EventSourceServer) Subscribed() bool
- type EventSourceSubscriber
- type File
- type MessageEvent
- type MessageEventChannel
- type MessageID
- type MessageType
- type MultipartForm
- type PublishMessage
- type PublishResult
- type Workspace
Constants ¶
This section is empty.
Variables ¶
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 ¶
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
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 ColorScheme ¶
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 MessageType ¶
type MessageType string
const ( MessageTypeString MessageType = "string" MessageTypeBinary MessageType = "binary" MessageTypeClose MessageType = "close" EvtBroadcastMessage = "broadcast.message" )
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"` }
Source Files ¶
- account.go
- ai.go
- archive.go
- asset.go
- attr.go
- av.go
- bazaar.go
- block.go
- block_op.go
- bookmark.go
- broadcast.go
- clipboard.go
- export.go
- extension.go
- file.go
- filetree.go
- format.go
- graph.go
- history.go
- icon.go
- import.go
- inbox.go
- lute.go
- network.go
- notebook.go
- notification.go
- outline.go
- pandoc.go
- petal.go
- ref.go
- repo.go
- riff.go
- router.go
- search.go
- setting.go
- snippet.go
- sql.go
- storage.go
- sync.go
- system.go
- tag.go
- template.go
- transaction.go
- workspace.go