shogo4405 / HaishinKit.swift

Camera and Microphone streaming library via RTMP and SRT for iOS, macOS, tvOS and visionOS.
BSD 3-Clause "New" or "Revised" License
2.72k stars 605 forks source link

connection closed by peer on stopping the RTMP stream #1472

Open talhatsk opened 3 weeks ago

talhatsk commented 3 weeks ago

Describe the bug

Hi, when i try to stop the stream,FCUnpublish() followed by closeStream() is invoked and the RTMP server reports connection closed by peer which is not the desired effect. It should stop/kill the stream. Then i tried it through OBS, when i stopped from there it sent deleteStream()instead of closeStream() after FCUnpublish() which deleted the stream and invoked Webhooks.

image Screenshot 2024-06-11 at 9 31 55 PM

To Reproduce

stop the stream and check on wireshark, you will see FCUnpublish() followed by closeStream()

Expected behavior

stopping the stream should call deleteStream() instead of closeStream()

Version

1.8.1

Smartphone info.

iPhone Xs Max

Additional context

No response

Screenshots

No response

Relevant log output

No response

shogo4405 commented 3 weeks ago

I see. I believe the fix is simple, so I'm looking forward to your PR.

xoraingroup commented 3 weeks ago

@shogo4405 - It seems it might need to rename the command to deleteStream()

image

But I am not sure, if a separate method should be used to not break the API?

xoraingroup commented 1 week ago

@shogo4405 is this ok? I am waiting for a Yes or No :)

shogo4405 commented 1 week ago

No. You need to consider the behavior when viewing, the behavior when using FCPublish, and the behavior when not using FCPublish. I have no knowledge regarding deleteStream, so I don't know. It will need to be investigated.

xoraingroup commented 1 week ago

closeStream closes stream but does not unpublish (delete) stream from rtmp server. This causes the rtmp server to not send webhooks because the stream is still there in rtmp server but in closed state and it waits for timeout of rtmp ingestion. The delete stream makes sure that the stream is unpublished from rtmp server and rtmp server sends the relevant webhooks to notify the relevant services. The webhooks are important part of creating flows and this is where we are stucked using this library.

From viewing perspective, the FCUnpublish with deleteStream unpublishes the stream and the client player just stops loading hls fragments. If fetching stream as rtmp pull, it just stops with error that stream does not exist.

I am not sure if i am making sense.

levs42 commented 1 week ago

It makes sense in the context of your specific RTMP server. There are many of them, and they tend to have different implementations of RTMP spec. Therefore the best options is to create a PR with an optional deleteStream call. Here #1393 is a good example of handing undocumented FCPublish command in an optional manner.