feat(live): wip work

This commit is contained in:
Torkel Ödegaard
2016-03-14 16:18:07 +01:00
parent 2adc4d12be
commit 195be2742c
5 changed files with 53 additions and 23 deletions

View File

@@ -115,25 +115,3 @@ func (c *connection) writePump() {
}
}
}
type LiveConn struct {
}
func New() *LiveConn {
go h.run()
return &LiveConn{}
}
func (lc *LiveConn) Serve(w http.ResponseWriter, r *http.Request) {
log.Info("Live: Upgrading to WebSocket")
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Error(3, "Live: Failed to upgrade connection to WebSocket", err)
return
}
c := newConnection(ws)
h.register <- c
go c.writePump()
c.readPump()
}

View File

@@ -1,6 +1,9 @@
package live
import "github.com/grafana/grafana/pkg/log"
import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/log"
)
type hub struct {
// Registered connections.
@@ -14,6 +17,8 @@ type hub struct {
// Unregister requests from connections.
unregister chan *connection
streamPipe chan *dtos.StreamMessage
}
var h = hub{

35
pkg/api/live/live.go Normal file
View File

@@ -0,0 +1,35 @@
package live
import (
"net/http"
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/middleware"
)
type LiveConn struct {
}
func New() *LiveConn {
go h.run()
return &LiveConn{}
}
func (lc *LiveConn) Serve(w http.ResponseWriter, r *http.Request) {
log.Info("Live: Upgrading to WebSocket")
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Error(3, "Live: Failed to upgrade connection to WebSocket", err)
return
}
c := newConnection(ws)
h.register <- c
go c.writePump()
c.readPump()
}
func (lc *LiveConn) PushToStream(c *middleware.Context, message dtos.StreamMessage) {
}