Live: broadcast events when dashboard is saved (#27583)
Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
This commit is contained in:
co-authored by
kay delaney
Torkel Ödegaard
parent
44c9aea28c
commit
8a5fc00330
@@ -0,0 +1,32 @@
|
||||
package live
|
||||
|
||||
import (
|
||||
"github.com/centrifugal/centrifuge"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
)
|
||||
|
||||
// PluginHandler manages all the `grafana/dashboard/*` channels
|
||||
type PluginHandler struct {
|
||||
Plugin *plugins.PluginBase
|
||||
}
|
||||
|
||||
// GetHandlerForPath called on init
|
||||
func (g *PluginHandler) GetHandlerForPath(path string) (models.ChannelHandler, error) {
|
||||
return g, nil // all dashboards share the same handler
|
||||
}
|
||||
|
||||
// GetChannelOptions called fast and often
|
||||
func (g *PluginHandler) GetChannelOptions(id string) centrifuge.ChannelOptions {
|
||||
return centrifuge.ChannelOptions{}
|
||||
}
|
||||
|
||||
// OnSubscribe for now allows anyone to subscribe to any dashboard
|
||||
func (g *PluginHandler) OnSubscribe(c *centrifuge.Client, e centrifuge.SubscribeEvent) error {
|
||||
return nil // anyone can subscribe
|
||||
}
|
||||
|
||||
// OnPublish called when an event is received from the websocket
|
||||
func (g *PluginHandler) OnPublish(c *centrifuge.Client, e centrifuge.PublishEvent) ([]byte, error) {
|
||||
return e.Data, nil // broadcast any event
|
||||
}
|
||||
Reference in New Issue
Block a user