fix: DataChannel not emitting new data on iOS #123
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
In our project, we use data channels to notify other peers that some state has changed (mic, camera, and other stuff)
On iOS, data channels work for 4-5s after the connection is established then they stop emitting data in
onMessage
flow, while sending data still works properly (Only receiving data was broken)After digging a little deeper in the app, I found out that my collectors (subscription to data flow) are always active, they just don't receive anything. This applies to all flows (
onMessage
,onClose
...)It seemed like an internal problem in
webrtc
, so I cloned the library and started logging and making some changes. I found out that thedelegate
stops receiving callbacks after a short time, which looks like something is reassigning it, or it's getting cleared somewhere.Solution
This solution might be weird, but it works. Before making these changes, I could repeat the problem 10 times out of 10, but after the changes, I couldn't repeat it anymore.
I think having a strong reference of the delegate prevents it from being cleared, therefore it's always active.
I would love to hear your thoughts on this :)