Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
chore: consolidate CI, E2E, backend and frontend updates
- CI: workflows updates (cd, ci), remove playwright.yml
- E2E: global-setup, auth/playlists/profile specs
- Remove playwright-report and test-results artifacts from tracking
- Backend: auth, handlers, services, workers, migrations
- Frontend: components, features, vite config
- Add e2e-results.json to gitignore
- Docs: REMEDIATION_PROGRESS, audit archive
- Rust: chat-server, stream-server updates
2026-02-17 15:43:21 +00:00
|
|
|
"time"
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
|
|
|
|
|
"veza-backend-api/internal/models"
|
|
|
|
|
"veza-backend-api/internal/repositories"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// LiveStreamService handles live stream business logic
|
|
|
|
|
type LiveStreamService struct {
|
feat(v0.703): Go Live & Streaming Complet
- Backend: room creation for live streams, permissions CanJoin/CanSend/CanRead for stream rooms
- LiveViewChat: useLiveStreamChat hook, WebSocket connection, stream_id as room
- LiveViewPlayer: real-time viewer count via polling (5s)
- Media Session: seekbackward/seekforward handlers (10s step)
- GoLiveView.stories.tsx: Default, Loading, Error, StreamKeyVisible
- Docs: API_REFERENCE, CHANGELOG, PROJECT_STATE, FEATURE_STATUS, RETROSPECTIVE_V0703
- SCOPE_CONTROL, .cursorrules: update to v0.801
- Archive V0_703_RELEASE_SCOPE.md
2026-02-25 08:35:22 +00:00
|
|
|
repo repositories.LiveStreamRepository
|
|
|
|
|
roomRepo *repositories.RoomRepository
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewLiveStreamService creates a new LiveStreamService
|
feat(v0.703): Go Live & Streaming Complet
- Backend: room creation for live streams, permissions CanJoin/CanSend/CanRead for stream rooms
- LiveViewChat: useLiveStreamChat hook, WebSocket connection, stream_id as room
- LiveViewPlayer: real-time viewer count via polling (5s)
- Media Session: seekbackward/seekforward handlers (10s step)
- GoLiveView.stories.tsx: Default, Loading, Error, StreamKeyVisible
- Docs: API_REFERENCE, CHANGELOG, PROJECT_STATE, FEATURE_STATUS, RETROSPECTIVE_V0703
- SCOPE_CONTROL, .cursorrules: update to v0.801
- Archive V0_703_RELEASE_SCOPE.md
2026-02-25 08:35:22 +00:00
|
|
|
func NewLiveStreamService(repo repositories.LiveStreamRepository, roomRepo *repositories.RoomRepository) *LiveStreamService {
|
|
|
|
|
return &LiveStreamService{repo: repo, roomRepo: roomRepo}
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List returns all live streams, optionally filtered by is_live
|
|
|
|
|
func (s *LiveStreamService) List(ctx context.Context, isLive *bool) ([]*models.LiveStream, error) {
|
|
|
|
|
return s.repo.List(ctx, isLive)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get returns a single live stream by ID
|
|
|
|
|
func (s *LiveStreamService) Get(ctx context.Context, id uuid.UUID) (*models.LiveStream, error) {
|
|
|
|
|
return s.repo.GetByID(ctx, id)
|
|
|
|
|
}
|
|
|
|
|
|
feat(v0.703): Go Live & Streaming Complet
- Backend: room creation for live streams, permissions CanJoin/CanSend/CanRead for stream rooms
- LiveViewChat: useLiveStreamChat hook, WebSocket connection, stream_id as room
- LiveViewPlayer: real-time viewer count via polling (5s)
- Media Session: seekbackward/seekforward handlers (10s step)
- GoLiveView.stories.tsx: Default, Loading, Error, StreamKeyVisible
- Docs: API_REFERENCE, CHANGELOG, PROJECT_STATE, FEATURE_STATUS, RETROSPECTIVE_V0703
- SCOPE_CONTROL, .cursorrules: update to v0.801
- Archive V0_703_RELEASE_SCOPE.md
2026-02-25 08:35:22 +00:00
|
|
|
// Create creates a new live stream for a user and a chat room for the stream (GL3-01)
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
func (s *LiveStreamService) Create(ctx context.Context, userID uuid.UUID, stream *models.LiveStream) (*models.LiveStream, error) {
|
|
|
|
|
if stream.Title == "" {
|
|
|
|
|
return nil, errors.New("title is required")
|
|
|
|
|
}
|
|
|
|
|
stream.UserID = userID
|
2026-02-24 08:52:04 +00:00
|
|
|
stream.StreamKey = uuid.New().String()
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
if stream.StreamerName == "" {
|
|
|
|
|
stream.StreamerName = "Streamer"
|
|
|
|
|
}
|
|
|
|
|
if err := s.repo.Create(ctx, stream); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
feat(v0.703): Go Live & Streaming Complet
- Backend: room creation for live streams, permissions CanJoin/CanSend/CanRead for stream rooms
- LiveViewChat: useLiveStreamChat hook, WebSocket connection, stream_id as room
- LiveViewPlayer: real-time viewer count via polling (5s)
- Media Session: seekbackward/seekforward handlers (10s step)
- GoLiveView.stories.tsx: Default, Loading, Error, StreamKeyVisible
- Docs: API_REFERENCE, CHANGELOG, PROJECT_STATE, FEATURE_STATUS, RETROSPECTIVE_V0703
- SCOPE_CONTROL, .cursorrules: update to v0.801
- Archive V0_703_RELEASE_SCOPE.md
2026-02-25 08:35:22 +00:00
|
|
|
// Create chat room for live stream (stream_id = room_id for JoinConversation)
|
|
|
|
|
if s.roomRepo != nil {
|
|
|
|
|
room := &models.Room{
|
|
|
|
|
ID: stream.ID,
|
|
|
|
|
Name: stream.Title,
|
|
|
|
|
Type: "live_stream",
|
|
|
|
|
IsPrivate: false,
|
2026-03-05 22:03:43 +00:00
|
|
|
CreatedBy: userID,
|
feat(v0.703): Go Live & Streaming Complet
- Backend: room creation for live streams, permissions CanJoin/CanSend/CanRead for stream rooms
- LiveViewChat: useLiveStreamChat hook, WebSocket connection, stream_id as room
- LiveViewPlayer: real-time viewer count via polling (5s)
- Media Session: seekbackward/seekforward handlers (10s step)
- GoLiveView.stories.tsx: Default, Loading, Error, StreamKeyVisible
- Docs: API_REFERENCE, CHANGELOG, PROJECT_STATE, FEATURE_STATUS, RETROSPECTIVE_V0703
- SCOPE_CONTROL, .cursorrules: update to v0.801
- Archive V0_703_RELEASE_SCOPE.md
2026-02-25 08:35:22 +00:00
|
|
|
}
|
|
|
|
|
if err := s.roomRepo.Create(ctx, room); err != nil {
|
|
|
|
|
// Non-fatal: stream created, chat room creation failed (e.g. room already exists)
|
|
|
|
|
_ = err
|
|
|
|
|
}
|
|
|
|
|
}
|
Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
Bloc A - Code mort:
- Suppression Studio (components, views, features)
- Suppression gamification + services mock (projectService, storageService, gamificationService)
- Mise à jour Sidebar, Navbar, locales
Bloc B - Frontend:
- Suppression modal.tsx deprecated, Modal.stories (doublon Dialog)
- Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true
- Suppression 19 tests orphelins, retrait exclusions vitest.config
Bloc C - Backend:
- Extraction routes_auth.go depuis router.go
Bloc D - Rust:
- Suppression security_legacy.rs (code mort, patterns déjà dans security/)
2026-02-14 16:23:32 +00:00
|
|
|
return stream, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update updates an existing live stream (with ownership check)
|
|
|
|
|
func (s *LiveStreamService) Update(ctx context.Context, id, userID uuid.UUID, stream *models.LiveStream) (*models.LiveStream, error) {
|
|
|
|
|
existing, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
if existing.UserID != userID {
|
|
|
|
|
return nil, errors.New("live stream not found")
|
|
|
|
|
}
|
|
|
|
|
stream.ID = id
|
|
|
|
|
stream.UserID = userID
|
|
|
|
|
if err := s.repo.Update(ctx, stream); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return stream, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Delete deletes a live stream (with ownership check)
|
|
|
|
|
func (s *LiveStreamService) Delete(ctx context.Context, id, userID uuid.UUID) error {
|
|
|
|
|
existing, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if existing.UserID != userID {
|
|
|
|
|
return errors.New("live stream not found")
|
|
|
|
|
}
|
|
|
|
|
return s.repo.Delete(ctx, id)
|
|
|
|
|
}
|
chore: consolidate CI, E2E, backend and frontend updates
- CI: workflows updates (cd, ci), remove playwright.yml
- E2E: global-setup, auth/playlists/profile specs
- Remove playwright-report and test-results artifacts from tracking
- Backend: auth, handlers, services, workers, migrations
- Frontend: components, features, vite config
- Add e2e-results.json to gitignore
- Docs: REMEDIATION_PROGRESS, audit archive
- Rust: chat-server, stream-server updates
2026-02-17 15:43:21 +00:00
|
|
|
|
2026-02-24 08:52:04 +00:00
|
|
|
// ListByUser returns all streams for a user (including stream_key)
|
|
|
|
|
func (s *LiveStreamService) ListByUser(ctx context.Context, userID uuid.UUID) ([]*models.LiveStream, error) {
|
|
|
|
|
return s.repo.ListByUserID(ctx, userID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RegenerateStreamKey generates a new stream key for a stream (ownership check)
|
|
|
|
|
func (s *LiveStreamService) RegenerateStreamKey(ctx context.Context, id, userID uuid.UUID) (string, error) {
|
|
|
|
|
existing, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
if existing.UserID != userID {
|
|
|
|
|
return "", errors.New("stream not found")
|
|
|
|
|
}
|
|
|
|
|
existing.StreamKey = uuid.New().String()
|
|
|
|
|
if err := s.repo.Update(ctx, existing); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
|
}
|
|
|
|
|
return existing.StreamKey, nil
|
|
|
|
|
}
|
|
|
|
|
|
chore: consolidate CI, E2E, backend and frontend updates
- CI: workflows updates (cd, ci), remove playwright.yml
- E2E: global-setup, auth/playlists/profile specs
- Remove playwright-report and test-results artifacts from tracking
- Backend: auth, handlers, services, workers, migrations
- Frontend: components, features, vite config
- Add e2e-results.json to gitignore
- Docs: REMEDIATION_PROGRESS, audit archive
- Rust: chat-server, stream-server updates
2026-02-17 15:43:21 +00:00
|
|
|
// SetIsLive updates is_live, started_at and ended_at for a stream (called by stream server callbacks)
|
|
|
|
|
func (s *LiveStreamService) SetIsLive(ctx context.Context, id uuid.UUID, isLive bool) error {
|
|
|
|
|
stream, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
stream.IsLive = isLive
|
|
|
|
|
if isLive {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
stream.StartedAt = &now
|
|
|
|
|
stream.EndedAt = nil
|
|
|
|
|
} else {
|
|
|
|
|
now := time.Now()
|
|
|
|
|
stream.EndedAt = &now
|
|
|
|
|
}
|
|
|
|
|
return s.repo.Update(ctx, stream)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateViewerCount adjusts viewer_count by delta (called by stream server for ListenerJoined/ListenerLeft)
|
|
|
|
|
func (s *LiveStreamService) UpdateViewerCount(ctx context.Context, id uuid.UUID, delta int) error {
|
|
|
|
|
stream, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
newCount := stream.ViewerCount + delta
|
|
|
|
|
if newCount < 0 {
|
|
|
|
|
newCount = 0
|
|
|
|
|
}
|
|
|
|
|
stream.ViewerCount = newCount
|
|
|
|
|
return s.repo.Update(ctx, stream)
|
|
|
|
|
}
|
2026-03-10 09:21:57 +00:00
|
|
|
|
|
|
|
|
// GetByStreamKey returns a stream by its stream_key (for RTMP callback validation)
|
|
|
|
|
func (s *LiveStreamService) GetByStreamKey(ctx context.Context, streamKey string) (*models.LiveStream, error) {
|
|
|
|
|
return s.repo.GetByStreamKey(ctx, streamKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateStreamURL sets the HLS stream URL (called by Nginx-RTMP on_publish callback)
|
|
|
|
|
func (s *LiveStreamService) UpdateStreamURL(ctx context.Context, id uuid.UUID, streamURL string) error {
|
|
|
|
|
stream, err := s.repo.GetByID(ctx, id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
stream.StreamURL = streamURL
|
|
|
|
|
return s.repo.Update(ctx, stream)
|
|
|
|
|
}
|