Only send events to clients who need it

- User events (star, rating, plays) only sent to same user
- Don't send to the client (browser window) that originated the event
This commit is contained in:
Deluan
2021-06-15 18:35:08 -04:00
parent 5f6f74ff2d
commit b65e76293a
13 changed files with 197 additions and 63 deletions
+3 -3
View File
@@ -74,7 +74,7 @@ func (c *MediaAnnotationController) setRating(ctx context.Context, id string, ra
return err
}
event := &events.RefreshResource{}
c.broker.SendMessage(event.With(resource, id))
c.broker.SendMessage(ctx, event.With(resource, id))
return nil
}
@@ -177,7 +177,7 @@ func (c *MediaAnnotationController) scrobblerRegister(ctx context.Context, playe
if err != nil {
log.Error("Error while scrobbling", "trackId", trackId, "user", username, err)
} else {
c.broker.SendMessage(&events.RefreshResource{})
c.broker.SendMessage(ctx, &events.RefreshResource{})
log.Info("Scrobbled", "title", mf.Title, "artist", mf.Artist, "user", username)
}
@@ -242,7 +242,7 @@ func (c *MediaAnnotationController) setStar(ctx context.Context, star bool, ids
}
event = event.With("song", ids...)
}
c.broker.SendMessage(event)
c.broker.SendMessage(ctx, event)
return nil
})
+2 -5
View File
@@ -10,6 +10,7 @@ import (
"net/url"
"strings"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/core"
"github.com/navidrome/navidrome/core/auth"
"github.com/navidrome/navidrome/log"
@@ -19,10 +20,6 @@ import (
"github.com/navidrome/navidrome/utils"
)
const (
cookieExpiry = 365 * 24 * 3600 // One year
)
func postFormToQueryParams(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
@@ -160,7 +157,7 @@ func getPlayer(players core.Players) func(next http.Handler) http.Handler {
cookie := &http.Cookie{
Name: playerIDCookieName(userName),
Value: player.ID,
MaxAge: cookieExpiry,
MaxAge: consts.CookieExpiry,
HttpOnly: true,
Path: "/",
}
+3 -2
View File
@@ -9,6 +9,7 @@ import (
"time"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/core"
"github.com/navidrome/navidrome/core/auth"
"github.com/navidrome/navidrome/log"
@@ -181,7 +182,7 @@ var _ = Describe("Middlewares", func() {
cookie := &http.Cookie{
Name: playerIDCookieName("someone"),
Value: "123",
MaxAge: cookieExpiry,
MaxAge: consts.CookieExpiry,
}
r.AddCookie(cookie)
@@ -208,7 +209,7 @@ var _ = Describe("Middlewares", func() {
cookie := &http.Cookie{
Name: playerIDCookieName("someone"),
Value: "123",
MaxAge: cookieExpiry,
MaxAge: consts.CookieExpiry,
}
r.AddCookie(cookie)
mockedPlayers.transcoding = &model.Transcoding{ID: "12"}