Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop Streaming flow & onDisconnect #7

Closed
BlueBazze opened this issue Aug 5, 2022 · 2 comments
Closed

Stop Streaming flow & onDisconnect #7

BlueBazze opened this issue Aug 5, 2022 · 2 comments

Comments

@BlueBazze
Copy link
Contributor

Summary

Noticed that the callback onDisconnect is not being called when executing stopStreaming.
Is this intentional? Or an error?

Motivation

My users can only stream inside of a time based window. Meaning they will get disconnected when the time reaches the end time of that predefined time window. In order to accommodate this on mobile. When the end time is reached, the live stream will shut down and close the live stream page. Meaning i gotta know when the connection have been closed before i close the stream view.

Problem

In the stopStreaming method
The rtmpConnection.close() might go async at some point.
Meaning the event listeners will get removed before the connection is actually closed.
Or
rtmpConnection.close() might not trigger the rtmpStatusHandler at all for some reason.

Solution

Have a private enum that contains the status that we want the live stream to be in.
Meaning in startStreaming, we set this variable to "streaming".
So if the connection fails, we know if the user wants the stream and we can retry the connection.
In stopStreamingwe set the enum to "stopped". When the rtmpStatusHandler reaches RTMPConnection.Code.connectClosed.rawValue we can first onDisconnect and afterwards check the enum, and then remove the event listeners.

Can make a pr. But want a go ahead first.

@ThibaultBee
Copy link
Member

ThibaultBee commented Aug 5, 2022

You are right there should be a onDisconnect event when user calls stopStreaming. I have tried to comment the part that removes the event listeners but rtmpStatusHandler is not called. See shogo4405/HaishinKit.swift#671 (comment)

Unfortunately, the easiest solution I see is to trigger onDisconnect in the stopStreaming if the application is connected.

@BlueBazze
Copy link
Contributor Author

Took a deeper look at it.
Unfortunately you are right.

Issue fixed with 9708f21bbd0147d2cd292cbfd1880e231b6c4bf7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants