chrisguttandin/extendable-media-recorder

Add a `deregister` method

Closed this issue · 5 comments

There is a method to register a worker: await register(await connect()).

Could you add a method to deregister it as well?

Thank you!

Sorry for leaving this unanswered for a long time. I guess it's the same issue as chrisguttandin/media-encoder-host-worker#262. Let's use this one for the conversation.

I'm curious what would be the use case of removing a codec again? Can you please elaborate a bit why this is necessary?

@chrisguttandin thank you for the response! yes, this is the same issue as chrisguttandin/media-encoder-host-worker#262, just was not sure what was the best channel to reach out.
We use Phoenix LivView in our app and there is this case where don't need to keep the worker registered in most of the pages, so we'd like to deregister it when it is no longer needed in the context of the app. Does that shed more light on this issue?

Actually I wanted to ask about the same. Whenever I initiate an audio recording, I invoke the register method and subsequently halt the recording process. Initially, everything operates smoothly. However, upon attempting to commence another recording session, I encounter the error message: There is already an encoder stored which handles exactly the same mime types. This error appears to be linked to the await register(await connect()) function. From my understanding, employing the unregister method should resolve this issue. I've attempted to resolve it by utilizing disconnect(port) and port.close(), however it didnt help.

@MateuszPu You can check if the codec is already registered and avoid calling register again, which triggers the error you mentioned above. I had the same problem but fixed it using something like this:

        const [stream] = await Promise.all([
            navigator.mediaDevices.getUserMedia({ audio: true }),
            connect().then((port) => {
                if (!MediaRecorder.isTypeSupported('audio/wav')) {
// Only register the codec if the recoder does not support it, otherwise ignore to prevent the error
                    register(port)
                }
            } ),
          ]);

It would be helpful if there was a cleaner way to deregister the codec via a functional call.

I've added an experimental (for now) function to deregister a port. The following should now work.

await register(port);

// ....

await deregister(port);

Please let me know if you encounter any errors or rough edges.