skymaze / pymediasoup

mediasoup python client
MIT License
25 stars 14 forks source link

Re-establishment of a producer session after teardown #8

Closed neilyoung closed 11 months ago

neilyoung commented 11 months ago

I like this fine library, well written, indeed.

However, I'm having a little problem. I have applied a publish/unpublish pattern on top of basically the example/mediaoup.py core code. I see, that you are creating VideoStreamTrack and AudioStreamTrack very early and apply the handles in an array on Device instantiation. Later, in the produce function a Producer is created and the tracks are provided again:

videoProducer: Producer = await self._sendTransport.produce(
                track=self._videoTrack,
                stopTracks=False,
                appData=appData
            )

That works perfectly on publish, but when I try to unpublish such a stream by calling producer.close(), I cannot again publish like so after the close.

I'm either catching aiortc.exceptions.InvalidAccessError: Track already has a sender or pymediasoup.errors.InvalidStateError: track ended, depending on the state of the stopTracks flag (false/true).

Would you know a clean way to "reanimate" these Video/AudioStreamTracks for the next session?

TIA

neilyoung commented 11 months ago

OK, at the first glance this seems to be possible: