livekit / client-sdk-flutter

Flutter Client SDK for LiveKit
https://docs.livekit.io
Apache License 2.0
266 stars 132 forks source link

[bug] Crash when join room on Windows #586

Open thaidmfinnick opened 2 months ago

thaidmfinnick commented 2 months ago

Describe the bug When I start call from Windows, it throws: [ERROR:flutter/shell/common/shell.cc(1055)] The 'FlutterWebRTC/Texture1515781191712' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel If I call in app productions, my app crashes immediately.

It seems relevant to many issues from WebRTC: https://github.com/flutter-webrtc/flutter-webrtc/issues/1580 https://github.com/flutter-webrtc/flutter-webrtc/issues/1465 https://github.com/flutter-webrtc/flutter-webrtc/issues/1525

To Reproduce Just call from Windows platform with Livekit Client (v2.2.5)

Expected behavior Can call from Windows. I cannot call from Windows after migrating Livekit from v1.x to v2.x Platform information

Thank you and hope you reply!

The-Funk commented 1 month ago

I'm running into this exact same issue. Someone over here, apparently figured out that this specific throw can be removed from flutter_wbrtc and their application will run again.

From what I gather about platform channels, flutter_webrtc appears to be doing the right thing.

But I could be wrong. I'm still diving into this issue and trying to understand what's going wrong and why Flutter doesn't like the MethodChannel created by flutter_webrtc, and what might be causing the video to fail for me in Windows builds.

One thing I noticed with the Livekit docs was that they say to use VS 2019 build tools. I'm using VS 2022. I don't know if that's problematic or not. I think most people are using 2022 by now.

thaidmfinnick commented 1 month ago

I'm running into this exact same issue. Someone https://github.com/simonbengtsson/simple_peer_flutter/issues/3, apparently figured out that this specific throw can be removed from flutter_wbrtc and their application will run again.

Thank you for your contribution about this issue! Before figuring out what happened to flutter_webrtc on Windows, I need to call functionality working again. I will try your solution you mention. Really look forward to hearing issue's updates from you.

But I could be wrong. I'm still diving into this issue and trying to understand what's going wrong and why Flutter doesn't like the MethodChannel created by flutter_webrtc, and what might be causing the video to fail for me in Windows builds.

I'm not sure but I use audioplayers lib and catch the same error.

The-Funk commented 1 month ago

@thaidmfinnick I've seen the same error with audioplayers as well, which is yet another well maintained library that claims Windows support. This leads me to believe the issue is deeper and possibly something Flutter related and not library related. Disclaimer: I am not a flutter_webrtc contributor, just someone else investigating these issues with Windows builds.

thaidmfinnick commented 1 month ago

Disclaimer: I am not a flutter_webrtc contributor, just someone else investigating these issues with Windows builds.

Yes, respect.

The-Funk commented 1 month ago

@thaidmfinnick I set up an MVP and I can confirm that without the changes/patch and with VS tools 2022 you can in fact get the video to display even with the platform channel warnings.

thaidmfinnick commented 1 month ago

I'm running into this exact same issue. Someone https://github.com/simonbengtsson/simple_peer_flutter/issues/3, apparently figured out that this specific throw can be removed from flutter_wbrtc and their application will run again.

This solution you mention above helps my app doesn't crash. Room can be started but no participants join, no media published. Windows' user feels like...

DanielBerrioB commented 1 month ago

I'm facing the same issue, hope this can get solved quickly, participants join but no media is published

cloudwebrtc commented 1 month ago

Since there is no method to get the current thread in the flutter windows plugin, we need to wait for this https://github.com/flutter/flutter/issues/134346 to be resolved

The-Funk commented 1 month ago

Since there is no method to get the current thread in the flutter windows plugin, we need to wait for this flutter/flutter#134346 to be resolved

I figured this was the case, your code looked good. So the platform thread warning is a Flutter issue after all. I learned a lot about platform channels from reading your code by the way. Looks a lot like Java reflection lol!

thaidmfinnick commented 1 month ago

Since there is no method to get the current thread in the flutter windows plugin, we need to wait for this https://github.com/flutter/flutter/issues/134346 to be resolved

So it means until this https://github.com/flutter/flutter/issues/134346 to be resolved, Windows users cannot call with Livekit and Flutter WebRTC?? Do we have another way to workaround?

Thank you for all supports!