apivideo / api.video-reactnative-live-stream

React Native RTMP live stream client. Made with ♥ by api.video
https://api.video
MIT License
171 stars 33 forks source link

[Feat]: Unpublish stream #79

Open talhatsk opened 1 month ago

talhatsk commented 1 month ago

Version

2.0.0

Environment that reproduces the issue

Device iPhone xs max iOS 16.1

Use case description

Currently, the stop() method disconnects the stream but doesn't unpublish it from the server. How can we unpublish the stream?

Proposed solution

There should be a method to unpublish the stream from server as well.

Alternative solutions

No response

ThibaultBee commented 1 month ago

Hi,

I guess you are talking about RTMP Command message. I don't think there is an official unpublish message. Which command message do you have in mind? (FCUnpublish, closeStream?)

I am just curious, what server do you use? Because if the connection is closed. There is no need to explicit unpublish.

Do you have the same issue with Android?

talhatsk commented 1 month ago

Hi,

I guess you are talking about RTMP Command message. I don't think there is an official unpublish message. Which command message do you have in mind? (FCUnpublish, closeStream?)

I am just curious, what server do you use? Because if the connection is closed. There is no need to explicit unpublish.

Do you have the same issue with Android?

its FCUnpublish command. so what happen is if the stream gets unpublished then we get webhooks from rtmp server and if we close the stream (which is happening right now), webhooks won't be triggered and we have to wait for the timeout. Can we get any method which can send FCUnpublish command

talhatsk commented 1 month ago

Hi,

I guess you are talking about RTMP Command message. I don't think there is an official unpublish message. Which command message do you have in mind? (FCUnpublish, closeStream?)

I am just curious, what server do you use? Because if the connection is closed. There is no need to explicit unpublish.

Do you have the same issue with Android?

and yes it is same for android

ThibaultBee commented 1 month ago

Hi, I guess you are talking about RTMP Command message. I don't think there is an official unpublish message. Which command message do you have in mind? (FCUnpublish, closeStream?) I am just curious, what server do you use? Because if the connection is closed. There is no need to explicit unpublish. Do you have the same issue with Android?

its FCUnpublish command. so what happen is if the stream gets unpublished then we get webhooks from rtmp server and if we close the stream (which is happening right now), webhooks won't be triggered and we have to wait for the timeout. Can we get any method which can send FCUnpublish command

If the connection between the device and your server is lost, you won't get a FCUnpublish and your webhooks won't be triggered. In that case, you will face the same issue and there is nothing we can do about it.

talhatsk commented 1 month ago

Hi, I guess you are talking about RTMP Command message. I don't think there is an official unpublish message. Which command message do you have in mind? (FCUnpublish, closeStream?) I am just curious, what server do you use? Because if the connection is closed. There is no need to explicit unpublish. Do you have the same issue with Android?

its FCUnpublish command. so what happen is if the stream gets unpublished then we get webhooks from rtmp server and if we close the stream (which is happening right now), webhooks won't be triggered and we have to wait for the timeout. Can we get any method which can send FCUnpublish command

If the connection between the device and your server is lost, you won't get a FCUnpublish and your webhooks won't be triggered. In that case, you will face the same issue and there is nothing we can do about it.

Yes that is ok, network outage may occur or peer disconnections. But that is usually rare.
But we need intentional control to unpublish our stream to complete the flow. So a method would be good enough to unpublish stream along with existing closing stream

ThibaultBee commented 1 month ago

Hi,

For the implementation, I would rather like that stopStream calls FCUnpublish automatically instead of adding a specific method.

talhatsk commented 1 month ago

Hi,

For the implementation, I would rather like that stopStream calls FCUnpublish automatically instead of adding a specific method.

Yes, that would also work

ThibaultBee commented 1 month ago

I made a fix in the Android library. Could you have a look at HaishinKit.swift (the iOS library)?

talhatsk commented 1 month ago

HaishinKit.swift

it checks FCUnpublish to send a call to server to unpublish if let fcPublishName { connection.call("FCUnpublish", responder: nil, arguments: fcPublishName) }

ThibaultBee commented 3 weeks ago

Just to confirm. The argument in the FCUnpublish is going to be the provided StreamKey. Is it what you expect?

talhatsk commented 3 weeks ago

Just to confirm. The argument in the FCUnpublish is going to be the provided StreamKey. Is it what you expect?

yes thats correct

ThibaultBee commented 3 weeks ago

Could you test the iOS version of the main branch?

talhatsk commented 3 weeks ago

Could you test the iOS version of the main branch?

sure, i have to test the example folder on the main branch?

ThibaultBee commented 3 weeks ago

Yes Please :) You can run:

yarn && yarn example ios
talhatsk commented 3 weeks ago

Could you test the iOS version of the main branch?

so i've tested the main branch code, unfortunately its behaving the same way as before. I'm not getting any webhooks fired as it should be on the call of unpublish. The patchset is not working i guess.

ThibaultBee commented 3 weeks ago

hmm. I can see FCUnpublish in Wireshark in the iOS example. See:

Screenshot 2024-06-11 at 16 50 16
xoraingroup commented 3 weeks ago

Hi there,

I was testing the main branch as well. The FCUnpublish() followed by closeStream() does not delete the stream properly from rtmp server. RTMP server reports connection closed by peerdue to closeStream() which is not the intended effect. In term of unpublishing the stream FCUnpublish command must be followed by deleteStream() command.

Here is the packet captured from OBS while starting and stopping.

image

Can you provide an updated build with above modification.

talhatsk commented 3 weeks ago

@ThibaultBee I guess that must be the issue, closeStream() is not killing the stream properly. can we replace or add deleteStream()?

ThibaultBee commented 3 weeks ago

Could you add an issue for this in HaishinKit?

talhatsk commented 3 weeks ago

FCUnpublish() followed by closeStream()

reported. Link