Messaging/pkg/internal/services/websocket.go

35 lines
887 B
Go
Raw Permalink Normal View History

package services
import (
"context"
2024-11-02 05:23:27 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"time"
2024-09-11 15:58:02 +00:00
"github.com/samber/lo"
2024-11-02 05:24:37 +00:00
"git.solsynth.dev/hypernet/messaging/pkg/internal/gap"
"git.solsynth.dev/hypernet/nexus/pkg/proto"
)
2024-11-02 05:23:27 +00:00
func PushCommand(userId uint, task nex.WebSocketPackage) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
2024-11-02 05:23:27 +00:00
pc := gap.Nx.GetNexusGrpcConn()
_, _ = proto.NewStreamServiceClient(pc).PushStream(ctx, &proto.PushStreamRequest{
UserId: lo.ToPtr(uint64(userId)),
Body: task.Marshal(),
})
}
2024-11-02 05:23:27 +00:00
func PushCommandBatch(userId []uint64, task nex.WebSocketPackage) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
2024-11-02 05:23:27 +00:00
pc := gap.Nx.GetNexusGrpcConn()
_, _ = proto.NewStreamServiceClient(pc).PushStreamBatch(ctx, &proto.PushStreamBatchRequest{
UserId: userId,
Body: task.Marshal(),
})
}