-
Notifications
You must be signed in to change notification settings - Fork 41
/
realtime.go
30 lines (24 loc) · 893 Bytes
/
realtime.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package api
import (
"github.com/gin-gonic/gin"
"github.com/joschahenningsen/TUM-Live/dao"
"github.com/joschahenningsen/TUM-Live/tools/realtime"
"github.com/joschahenningsen/TUM-Live/tools/realtime/connector"
log "github.com/sirupsen/logrus"
)
type realtimeRoutes struct {
dao.DaoWrapper
}
var RealtimeInstance = realtime.New(connector.NewMelodyConnector())
func configGinRealtimeRouter(router *gin.RouterGroup, daoWrapper dao.DaoWrapper) {
routes := realtimeRoutes{daoWrapper}
router.GET("/ws", routes.handleRealtimeConnect)
}
func (r realtimeRoutes) handleRealtimeConnect(c *gin.Context) {
properties := make(map[string]interface{}, 1)
properties["ctx"] = c
properties["dao"] = r.DaoWrapper
if err := RealtimeInstance.HandleRequest(c.Writer, c.Request, properties); err != nil {
log.WithError(err).Warn("Something went wrong while handling Realtime-Socket request")
}
}