Skip to content

feat(live-streaming): implement live streaming and spectator mode - #459

Merged
Mkalbani merged 1 commit into
MindFlowInteractive:mainfrom
mubashqoz-eng:feat/live-streaming-spectator-mode
Sep 28, 2026
Merged

Mkalbani merged 1 commit into
MindFlowInteractive:mainfrom
mubashqoz-eng:feat/live-streaming-spectator-mode

Conversation

@mubashqoz-eng

Copy link
Copy Markdown
Contributor

Closes #441

Overview

Adds a self-contained backend module for live streaming and spectator mode:
stream lifecycle, spectator joining, real-time chat, viewer tracking, adaptive
quality, recording, moderator tools and viewership analytics. It follows the
src/community-events module shape (entities + DTOs + service + controller +
module) and adds a Socket.IO gateway on the /streams namespace.

The issue asks for ten tasks; this implements all of the acceptance criteria
through a single new src/live-streaming module and wires it into AppModule.

Related Issue

Closes #441

Changes

  • [ADD] src/live-streaming/entities/ — LiveStream (status machine, cached
    and peak viewer counts, recording state), StreamViewer (soft membership so
    viewership is analysable), StreamChatMessage (soft deletes keep the audit
    trail), StreamModerationAction (immutable decisions; enforcement reads them).
  • [ADD] src/live-streaming/dto/ — validated create/join/chat/moderation
    DTOs with Swagger metadata.
  • [ADD] src/live-streaming/live-streaming.service.ts — the behaviour:
    create/start/end/cancel, join/leave/count, deterministic
    qualityForBandwidth, chat post/history, moderator tools, recording, and a
    getAnalytics aggregate. Host and moderator permissions are enforced in the
    service; a finished stream cannot be started or joined, a banned viewer cannot
    join or chat, and an unexpired timeout blocks both.
  • [ADD] src/live-streaming/live-streaming.controller.ts — REST surface for
    every operation. The caller's id travels in x-user-id; binding that header to
    the JWT guard is a gateway-shell decision, and the service is where the real
    host/moderator check lives.
  • [ADD] src/live-streaming/gateways/live-streaming.gateway.ts — stream:join,
    stream:leave, stream:chat, stream:quality. Chat broadcasts to the
    stream:<id> room; counts are re-read from the roster so two sockets cannot
    drift the number; a disconnect leaves on behalf of the socket's stored user.
  • [ADD] src/live-streaming/live-streaming.module.ts and
    src/migrations/1760000000000-CreateLiveStreamingTables.ts — module wiring and
    the four-table schema with indexes.
  • [MODIFY] src/app.module.ts — import LiveStreamingModule.
  • [ADD] src/live-streaming/README.md — model, routes, gateway events,
    quality ladder and migration.

Verification Results

npx jest src/live-streaming
npx tsc --noEmit
npx eslint "src/live-streaming/**/*.ts"

Acceptance check:

Acceptance criterion Status
Streams created and managed ✅ scheduled/live/ended/cancelled; start/end/cancel host-only, idempotent where safe
Spectators join successfully ✅ join is idempotent; viewer count is read from the active roster and peak is monotonic
Chat real-time ✅ stream:chat broadcasts to the stream room; REST history excludes deleted messages
Quality adapts to bandwidth ✅ pure qualityForBandwidth ladder, unit-tested at every boundary
Recording functional ✅ start/stop by the host; ending a recorded stream finalises a URL
Analytics track viewership ✅ current/peak/total viewers, chat count, moderation count, quality distribution, duration
Moderator tools ✅ ban/unban/timeout/delete/pin/clear with an immutable action log; host or assigned moderator only
Comprehensive tests ✅ 42 tests (service + gateway)
  • npx jest src/live-streaming: 2 suites, 42 tests, all passing.
  • npx jest test/spectator/spectator.service.spec.ts: passing (unchanged).
  • npx tsc --noEmit: 207 pre-existing errors across the repo; none in any file
    this PR touches.
  • npx eslint "src/live-streaming/**/*.ts": 3 errors, all the
    no-unsafe-return / no-unsafe-assignment pattern in the generic test-repo
    mock that existing specs (community-events.service.spec.ts) also carry.

Blockers and pre-existing failures (not from this diff)

  • main is red before this change. npm run typecheck fails with 207
    errors in files unrelated to this diff (for example
    src/skill-rating/elo.service.spec.ts importing ../elo.service from the
    wrong directory, src/users/users.service.ts importing a missing
    common/pagination, src/replay/tests/replay.integration.spec.ts referencing
    an undefined analyticRepo). Because CI's typecheck step is not
    tolerated (lint:check and format:check are), CI cannot go green for any PR
    until those are fixed separately.
  • test/spectator/multiplayer.spectator.spec.ts fails on main with
    Nest can't resolve dependencies of the MultiplayerGateway ... EventEmitter,
    independent of this change.
  • npx jest on the whole suite is large and mixed; I verified the suites this
    module can affect and left the unrelated pre-existing failures alone.

Notes for the reviewer

  • The module is not auth-guarded; it trusts x-user-id and enforces host and
    moderator authority inside the service. If the repo standard is to attach
    JwtAuthGuard at the controller, that is a one-line change I can fold in.
  • getAnalytics derives currentViewers and the quality distribution from the
    active roster (source of truth) while LiveStream.viewerCount is a cached
    read; a reconciliation job is not needed but the two are deliberately both
    asserted in tests.

…ndFlowInteractive#441)

Add a self-contained LiveStreamingModule covering the issue's acceptance
criteria:

- stream creation and lifecycle (scheduled/live/ended/cancelled, host-only
  start/end/cancel, recording finalised on end)
- spectator join/leave, idempotent joins, and roster-derived viewer counts
  with a monotonic peak
- real-time chat over a Socket.IO gateway (/streams) plus REST history,
  with soft deletes that preserve the audit trail
- deterministic bandwidth -> quality adaptation
- moderator tools (ban/unban/timeout/delete/pin/clear) with an immutable
  action log; host and assigned moderators only
- viewership analytics (current/peak/total, chat, moderation, quality
  distribution, duration, recording state)
- a migration creating the four tables and indexes, and a module README

42 unit tests cover lifecycle, permissions, chat, moderation, recording,
quality and analytics.
@drips-wave

drips-wave Bot commented Sep 28, 2026

Copy link
Copy Markdown

@mubashqoz-eng Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Mkalbani
Mkalbani merged commit 23d9294 into MindFlowInteractive:main Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Live Streaming and Spectator Mode

2 participants