Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API #125

Merged
merged 14 commits into from
Nov 28, 2024
Merged

New API #125

merged 14 commits into from
Nov 28, 2024

Conversation

longnguyen2004
Copy link
Collaborator

@longnguyen2004 longnguyen2004 commented Nov 27, 2024

The new API that I promised

Functions added (names are changeable, feel free to suggest):

  • prepareStream: Take the input (a file path or a Readable stream) and use ffmpeg to create a Matroska media stream compatible with this library
    • Returns the ffmpeg instance and the output stream
    • All media related option (width, height, frame rate, bit rate, etc.) goes here
    • Compared to streamLivestreamVideo, the ffmpeg instance is returned back to user code, and the user is free to do whatever they want with it
  • playStream: Take the input stream and set up the muxer, packetizer and stream settings
    • All streaming related option (stream type: "Go Live" or camera, RTCP sender report, encryption type) goes here
    • Auto-detection and setup of the stream parameters (width, height, frame rate, video codec)
    • Voice states are completely managed by this function, the user doesn't need to juggle a bunch of internal functions.

Typical use case:

import { NewApi } from "@dank074/discord-video-stream";

// ...
let playback;
try {
  await streamer.joinVoice(guildId, channelId);

  if (streamer.client.user!.voice!.channel instanceof StageChannel)
    await streamer.client.user!.voice!.setSuppressed(false);

  const { command, output } = NewApi.prepareStream(url, {
    height: 1080,
    bitrateVideo: 5000,
    bitrateVideoMax: 10000,
    // other media settings
  });
  playback = command;

  await NewApi.playStream(output, streamer, {
    forceChacha20Encryption: true
  });

  // To end the stream prematurely, do playback.kill("SIGTERM")
}

Due to the need to keep backwards compatibility with streamLivestreamVideo, there are a few places that I'm not completely happy with (updatePacketizer being one of them). Once the old API is removed then we can do more cleanup. Please report if there are any breakage of the old API, since I might have missed something.

If streaming as a camera stream, we have to create the voice connection before creating the media stream. At that point, the streaming codec is unknown, so let's just announce all the supported codecs
It does not make sense to specify different IDs than the one we currently connect to anyway, so remove those
This will allow us to recall `setProtocols` to change encryption parameters if need be
I mean this can just be inlined as well, but whatever...
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.

2 participants