Is there a way to finish broadcast gracefully from within RPBroadcastSampleHandler?

2k views Asked by At

I am implementing a broadcast upload extension in iOS using my own custom SampleHandler extending RPBroadcastSampleHandler. The problem is pretty easy - I need a way to gracefully end the broadcast from within the extension.

The requirement is to stop broadcasting and turn off screen recording when all the other users stop watching the broadcast. I can easily detect that case. However, it seems that RPBroadcastSampleHandler does not provide a way to finish it, at least not a graceful way.

Based on official documentation, there is a broadcastFinished() callback on broadcast finishing (when the user ends it), and there is a way to finish it when there is an error - finishBroadcastWithError(_:). I could provide some nice error message and end it with an error, but I would prefer to just end it without showing any error at all - I don't want to indicate that there was any error, since this is intended behavior.

Anyone have a way on how to achieve this?

1

There are 1 answers

0
Mehmet Baykar On

You should do it using Obj-C code. As you can see on the Telegram Official repository they use BroadcastUploadHelpers in order to stop the sampleHandler gracefully.

void finishBroadcastGracefully(RPBroadcastSampleHandler * _Nonnull broadcastSampleHandler) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
[broadcastSampleHandler finishBroadcastWithError:nil];
#pragma clang diagnostic pop
}