✨ Disconnect websocket auto cleaning up subscribed channels
This commit is contained in:
@ -6,12 +6,25 @@ import (
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/nex"
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/database"
|
||||
"git.solsynth.dev/hypernet/messaging/pkg/internal/services"
|
||||
)
|
||||
|
||||
func (v *Server) BroadcastEvent(ctx context.Context, in *proto.EventInfo) (*proto.EventResponse, error) {
|
||||
log.Debug().Str("event", in.GetEvent()).
|
||||
Msg("Got a broadcasting event...")
|
||||
|
||||
switch in.GetEvent() {
|
||||
// Clear the subscribed channel
|
||||
case "ws.client.unregister":
|
||||
// Update user last seen at
|
||||
data := nex.DecodeMap(in.GetData())
|
||||
id := data["id"].(string)
|
||||
services.UnsubscribeAllWithClient(id)
|
||||
log.Info().Str("client", id).Msg("Client unregistered, cleaning up subscribed channels...")
|
||||
// Account recycle
|
||||
case "deletion":
|
||||
data := nex.DecodeMap(in.GetData())
|
||||
resType, ok := data["type"].(string)
|
||||
|
@ -76,7 +76,7 @@ func (v *Server) PushStream(_ context.Context, request *proto.PushStreamRequest)
|
||||
action := strings.Split(in.Action, ".")[1]
|
||||
switch action {
|
||||
case "subscribe":
|
||||
services.SubscribeChannel(uint(request.GetUserId()), data.ChannelID)
|
||||
services.SubscribeChannel(uint(request.GetUserId()), data.ChannelID, request.GetClientId())
|
||||
case "unsubscribe":
|
||||
services.UnsubscribeChannel(uint(request.GetUserId()), data.ChannelID)
|
||||
case "unsubscribeAll":
|
||||
|
Reference in New Issue
Block a user