live

package
v0.44.25 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

The package to provide a server-side instance for the SSE message streaming.

Index

Constants

This section is empty.

Variables

View Source
var Streamer = &sse.Server{

	Provider: &sse.Joe{

		ReplayProvider: &sse.ValidReplayProvider{
			TTL:        time.Minute * 5,
			GCInterval: time.Minute,
			AutoIDs:    true,
		},
	},

	OnSession: func(s *sse.Session) (sse.Subscription, bool) {

		topics := s.Req.URL.Query()["topic"]

		for _, topic := range topics {

			if topic != topicRandomNumbers && topic != topicMetrics {

			}
		}

		if len(topics) == 0 {

			topics = []string{topicRandomNumbers, topicMetrics}
		}

		return sse.Subscription{
			Client:      s,
			LastEventID: s.LastEventID,
			Topics:      append(topics, sse.DefaultTopic),
		}, true
	},
}

Core SSE server as the HTTP handler wrapper.

Functions

func BroadcastMessage

func BroadcastMessage(payload EventPayload)

BroadcastMessage is a wrapper function for a SSE message sending.

func NewLiveRouter added in v0.44.24

func NewLiveRouter() chi.Router

Types

type EventPayload added in v0.44.11

type EventPayload struct {
	ID   string
	Type string
	Data string
}

EventPayload is the metastructure to organize the SSE event's data association better. It is an input for the BroadcastMessage function.

Jump to

Keyboard shortcuts

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