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
+16 -6
View File
@@ -9,12 +9,13 @@ import (
type contextKey string
const (
User = contextKey("user")
Username = contextKey("username")
Client = contextKey("client")
Version = contextKey("version")
Player = contextKey("player")
Transcoding = contextKey("transcoding")
User = contextKey("user")
Username = contextKey("username")
Client = contextKey("client")
Version = contextKey("version")
Player = contextKey("player")
Transcoding = contextKey("transcoding")
ClientUniqueId = contextKey("clientUniqueId")
)
func WithUser(ctx context.Context, u model.User) context.Context {
@@ -41,6 +42,10 @@ func WithTranscoding(ctx context.Context, t model.Transcoding) context.Context {
return context.WithValue(ctx, Transcoding, t)
}
func WithClientUniqueId(ctx context.Context, clientUniqueId string) context.Context {
return context.WithValue(ctx, ClientUniqueId, clientUniqueId)
}
func UserFrom(ctx context.Context) (model.User, bool) {
v, ok := ctx.Value(User).(model.User)
return v, ok
@@ -70,3 +75,8 @@ func TranscodingFrom(ctx context.Context) (model.Transcoding, bool) {
v, ok := ctx.Value(Transcoding).(model.Transcoding)
return v, ok
}
func ClientUniqueIdFrom(ctx context.Context) (string, bool) {
v, ok := ctx.Value(ClientUniqueId).(string)
return v, ok
}