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
|
2020-11-06 02:37:04 +08:00
|
|
|
func (h *PluginHandler) GetHandlerForPath(path string) (models.ChannelHandler, error) {
|
|
|
|
return h, nil // all dashboards share the same handler
|
2020-10-02 01:46:14 +08:00
|
|
|
}
|
|
|
|
|
2020-11-06 02:37:04 +08:00
|
|
|
// OnSubscribe for now allows anyone to subscribe
|
|
|
|
func (h *PluginHandler) OnSubscribe(c *centrifuge.Client, e centrifuge.SubscribeEvent) (centrifuge.SubscribeReply, error) {
|
|
|
|
return centrifuge.SubscribeReply{}, nil
|
2020-10-02 01:46:14 +08:00
|
|
|
}
|
|
|
|
|
2020-11-06 02:37:04 +08:00
|
|
|
// OnPublish checks if a message from the websocket can be broadcast on this channel
|
|
|
|
func (h *PluginHandler) OnPublish(c *centrifuge.Client, e centrifuge.PublishEvent) (centrifuge.PublishReply, error) {
|
|
|
|
return centrifuge.PublishReply{}, nil // broadcast any event
|
2020-10-02 01:46:14 +08:00
|
|
|
}
|