3.8 KiB
3.8 KiB
Internal Streamer Replacement Design
Summary
Replace the external @dank074/discord-video-stream dependency with an internal streaming module that uses discord.js-selfbot-v13 private APIs to deliver the same screen share behavior (video + audio) with identical UI/API surface.
Goals
- Maintain feature parity for screen share (video + audio, 720p @ 30fps, bitrate 2500/4000, H264, audio on).
- Keep existing UI and API contracts unchanged (
/api/media/queuewithmode: "screen"). - Remove
@dank074/discord-video-streamfrom dependencies and deletevendor/Discord-video-stream. - Ensure clean lifecycle handling (start/stop, cleanup, error reporting).
Non-Goals
- Rewriting WebRTC/RTP stack from scratch.
- Changing media queue behavior or UI layout.
- Adding new screen share modes or settings.
Architecture Overview
Introduce a new internal module under src/streaming/ that encapsulates:
- Voice/session management using private
discord.js-selfbot-v13APIs. - FFmpeg preparation for H264 + Opus (AnnexB video + Opus audio).
- Stream playback into the internal dispatcher.
screenShareController will depend on this module instead of @dank074/discord-video-stream.
Components
1) Streaming Session Module (src/streaming/)
Proposed exports:
createStreamSession(client)- Joins or reuses voice connection for video streaming.
- Exposes a
sessionobject withstartVideo(),stopVideo(), andsendStream(stream)hooks.
prepareFfmpegStream(source, opts)- Spawns ffmpeg with the same parameters used today.
- Returns
{ command, output }(output is a Readable stream).
playPreparedStream(output, session)- Pipes the prepared stream into the internal dispatcher.
- Returns a promise that resolves when playback completes.
2) Screen Share Controller (src/media/screenShareController.ts)
- Replace Streamer/prepareStream/playStream with internal module usage.
- Keep the public API identical (
start(source)returningScreenSharePlayback).
3) Web Server Wiring (src/webserver.ts)
- Remove
Streamerinstantiation and dependencies. - Pass only
getVoiceStatusand new streaming module dependencies intocreateScreenShareController.
Data Flow
- User queues screen share via
/api/media/queuewithmode: "screen". MediaControllercallsscreenShareController.start(source).screenShareControllerresolves URL, callsprepareFfmpegStream.createStreamSessionensures voice connection and dispatcher ready.playPreparedStreamsends output to Discord.- On completion or stop, cleanup runs and state updates propagate.
Error Handling
- Voice not connected: throw
VOICE_NOT_CONNECTED. - FFmpeg spawn/exit failure: throw
SCREEN_STREAM_FAILED. - Dispatcher error: stop stream, cleanup, log error, set state idle.
Lifecycle Rules
start()always stops any active stream first.stop()kills ffmpeg, stops dispatcher, and resets internal state.- Completion resolves
donepromise and triggers cleanup.
Testing Strategy
- Unit tests for
screenShareController:- Calls to
prepareFfmpegStreamandplayPreparedStreamonstart(). - Ensures
stop()kills ffmpeg and ends session.
- Calls to
- Unit tests for
streamingmodule:- Session initialization and cleanup logic with mocked private APIs.
Migration Steps
- Implement
src/streaming/module. - Update
screenShareControllerto use internal module. - Remove
@dank074/discord-video-streamimports and wiring. - Delete
vendor/Discord-video-streamdirectory. - Update
package.jsondependencies. - Update tests.
Risks
- Private
discord.js-selfbot-v13APIs may change. - Harder debugging if internal dispatcher behavior differs.
Rollback Plan
- Revert to previous commit that restores
@dank074/discord-video-streamand the vendor directory.