flutter-webrtc / flutter-webrtc

WebRTC plugin for Flutter Mobile/Desktop/Web
MIT License
4.02k stars 1.09k forks source link

channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread #1474

Open shelutai opened 9 months ago

shelutai commented 9 months ago

Describe the bug when I run the sample on Ubuntu 20.04,

get_user_media_sample, every time I click the record button, the sample crashed.at this line:

await _mediaRecorder!.start(

hope you can help me. Thank you very much.

....


 void _startRecording() async {
    if (_localStream == null) throw Exception('Stream is not initialized');
    if (Platform.isIOS) {
      print('Recording is not available on iOS');
      return;
    }
    // TODO(rostopira): request write storage permission
    // final storagePath = await getExternalStorageDirectory();
    // if (storagePath == null) throw Exception('Can\'t find storagePath');

    // final filePath = storagePath.path + '/webrtc_sample/test.mp4';
    final filePath = '/tmp/webrtc_sample.mp4';
    _mediaRecorder = MediaRecorder();
    setState(() {});

    final videoTrack = _localStream!
        .getVideoTracks()
        .firstWhere((track) => track.kind == 'video');
    await _mediaRecorder!.start(
      filePath,
      videoTrack: videoTrack,
    );
  }

To Reproduce Debug service listening on ws://127.0.0.1:37115/mNsW2mP8T_s=/ws Syncing files to device Linux... [ERROR:flutter/shell/common/shell.cc(1004)] The 'FlutterWebRTC/Texture140372818797984' 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. See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information. Warning: Failed to respond to a message. This is a memory leak. Lost connection to device.

Expected behavior start record Platform information ubuntu 20.04

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.13.1, on Ubuntu 20.04.3 LTS 5.15.0-79-generic, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Chrome - develop for the web [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2022.3) [✓] VS Code (version 1.82.2) [✓] Connected device (2 available)

flutter --version Flutter 3.13.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision e1e47221e8 (8 weeks ago) • 2023-08-22 21:43:18 -0700 Engine • revision b20183e040 Tools • Dart 3.1.0 • DevTools 2.25.0

wjmetcalfiiii commented 9 months ago

I am having the -exact- same problem with sensors_plus 3.1.0

https://github.com/fluttercommunity/plus_plugins/discussions/2280

jzhgithub18 commented 8 months ago

I am having the same problem

Nightwelf commented 2 weeks ago

same on my linux, please help!!!

[ERROR:flutter/shell/common/shell.cc(1055)] The 'FlutterWebRTC/Texture93934846288064' 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. See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.