2020-10-02 01:46:14 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-11-04 01:11:23 +08:00
|
|
|
// AllowBroadcast checks if a message from the websocket can be broadcast on this channel
|
|
|
|
func (g *PluginHandler) AllowBroadcast(c *centrifuge.Client, e centrifuge.PublishEvent) error {
|
|
|
|
return nil // broadcast any event
|
2020-10-02 01:46:14 +08:00
|
|
|
}
|