Unpublish() should be async?

this call:
this.openvidu.sendRequest('unpublishVideo'

is asynchronous but next part of code is executed synchronously.

I think that repeated calls to publish-unpublish will throw undesired behaviours/exceptions.

Do you think the same as me? Thanks!

Asynchronous calls from the browser only matter if you need the response from the server to do something else. Unpublish method doesn’t return anything valuable.
The “protection” against repeated calls to the method makes no sense in the context of a browser. You can call 100 times this method at the same time whether it is tagged as async or not. The protection must rely on developers calling the method only when required (I mean: if the method has already been sent, then don’t allow the UI to call it again), and of course, the server (in this case OpenVidu Server) will properly return an error if an RPC is done with parameters that are not valid (in this case, becasue the Publisher wanted to be unpublished doesn’t exist anymore).

I understand you, I don’t need to do anything else in OV but I need to notify another system that unpublish action for this user has finished, so from my point of view will be better an async method with resolve call when media is unpublished and stream is destroyed or rejected when error.

BR and good product!
Alberto

You can get the unpublish event on the server side if you want using Webhook event webrtcConnectionDestroyed https://docs.openvidu.io/en/2.13.0/reference-docs/openvidu-server-cdr/#webrtcconnectiondestroyed

Notifying a different system from the browser is not a good idea. You should notify other systems from your backend, which is the only secure place where to do so. If not, anyone with some basic knowledge could hack your system very easily.

Regards.

Thx Pablo!

This will be very useful for us.

We check webhook and it is fine.

But we have one use case when we want to change resolution and framerate for users that has already published.

So, for this implementation we call at first publish with initial config and after a few minutes we call unpublish and publish with new config. These two calls are throwing errrors in openvidu-browser like these:

Is it this the correct way to proceed?

Thanks,
Alberto

Hello @dovalin,

Then, you need a way to know when is safe to talk to publish() after calling to unpublish() and avoid such errors, right? That is why you want an “async” unpublish()?

Yeah that’s the approach we are looking for.

Already included in master branch. Available from 2.18.0