dank074 / Discord-video-stream

Experiment for making video streaming work for discord selfbots.
180 stars 32 forks source link

Use `p-cancelable` #91

Closed longnguyen2004 closed 5 months ago

longnguyen2004 commented 5 months ago

This is an implementation of my suggestion in https://github.com/dank074/Discord-video-stream/issues/88#issuecomment-2074024524

Usage:

let playback;
try {
    playback = streamLivestreamVideo(...);
    await playback;
}
catch (e)
{
    if (playback.isCanceled)
        // do stuff when cancel
    // do stuff when error
}

// somewhere else
playback?.cancel();
longnguyen2004 commented 5 months ago

I just realized p-cancelable is ESM...If we were to go this route then this library needs to be changed to ESM also

KuntilBogel commented 5 months ago

@longnguyen2004 iirc you can use dynamic import at commonjs

longnguyen2004 commented 5 months ago

I don't really want to use dynamic imports because it needlessly complicates logic for simple use cases, I'd rather have everything be ESM or CommonJS. I'm in the process of converting this library to ESM. Hope it won't be too much of a breaking change to users.

KuntilBogel commented 5 months ago

@longnguyen2004 but iirc changing the package from cjs to ejs would affect cjs users, am I right?

longnguyen2004 commented 5 months ago

It'll be a breaking change yes, but the situation now is a lot better than when ESM was first added to Node a few years ago, and there shouldn't be many cases where you have to use CJS anymore. Also, people who are using TypeScript are already using ESM syntaxes, but aren't aware that TS transpiles it to CJS by default. Switching to ESM for such people will be even easier.

KuntilBogel commented 5 months ago

alr