apivideo / api.video-flutter-live-stream

Flutter RTMP live stream client. Made with ♥ by api.video
MIT License
62 stars 37 forks source link

[Bug]: The 'video.api.livestream/events' channel sent a message from native to Flutter on a non-platform thread #47

Closed imsujan276 closed 4 months ago

imsujan276 commented 6 months ago

Version

v1.1.1

Which operating systems have you used?

Environment that reproduces the issue

Is it reproducible in the example application?

Yes

RTMP Server

api.video

Reproduction steps

  1. start the streaming in ios
  2. stop it
  3. you can see the error message in the console

Expected result

There should not be any error message in the console and the package should have sent the Platform channel messages on the platform thread

Actual result

The app give the following error message in console

[ERROR:flutter/shell/common/shell.cc(1015)] The 'video.api.livestream/events' 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.

Additional context

Example:

ApiVideoLiveStreamController createLiveStreamController() {
    return ApiVideoLiveStreamController(
      initialAudioConfig: rtmsConfigaudioConfig,
      initialVideoConfig: rtmsConfig.videoConfig,
      onConnectionSuccess: () {
        log('VideoStream: Connection succeeded');
      },
      onConnectionFailed: (error) {
        log('VideoStream: Connection failed: $error');
      },
      onDisconnection: () {
        log('VideoStream: Connection Disconnected');
      },
      onError: (err) {
        log('VideoStream: Connection Error: $err');
      },
    );
  }

Relevant logs output

[log] VideoStream: Stream Started
[ERROR:flutter/shell/common/shell.cc(1015)] The 'video.api.livestream/events' 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.
[log] VideoStream: Connection succeeded
ThibaultBee commented 5 months ago

Could you test branch with fix https://github.com/apivideo/api.video-flutter-live-stream/tree/fix/ios_event_thread?

imsujan276 commented 5 months ago

Thank you @ThibaultBee

This solved the issue

imsujan276 commented 5 months ago

But now it takes several seconds to startStreaming() and get the onConnectionSuccess callback.

Previously, it happened instantly

ThibaultBee commented 5 months ago

Hi, I made a fix in the iOS native RTMP lib: https://github.com/apivideo/api.video-swift-live-stream I will update this dependency before releasing a new version of apivideo_live_stream.

imsujan276 commented 5 months ago

Thank you

I will keep an eye on the update

ThibaultBee commented 5 months ago

Could you test on the main branch?

imsujan276 commented 4 months ago

yeah but does it include the changes made for Issue 48 for Android too?

ThibaultBee commented 4 months ago

yes

imsujan276 commented 4 months ago

i tried it using the main branch, it is still taking several seconds for the stream connection to succeed.

imsujan276 commented 4 months ago

https://github.com/apivideo/api.video-flutter-live-stream/assets/11173809/c980fab2-719b-4a50-a473-f35992de4177

You can see in the video, it takes around 10 seconds for the connection to succeed.

ThibaultBee commented 4 months ago

🤔

imsujan276 commented 4 months ago
  1. Yes i have the same issue while running the example in iOS too
  2. NO, I don't have an example from that URL
ThibaultBee commented 4 months ago

Sorry, could you test with the example from https://github.com/apivideo/api.video-swift-live-stream?

imsujan276 commented 4 months ago

I think that repo is for native iOS app. I am using flutter so not sure how

ThibaultBee commented 4 months ago

Do you have xcode? I guess yet because you need it for Flutter. Run open Examples/ExampleUIKit/ExampleUIKit.xcodeproj/

If I ask so, it just to know if the issue comes from the Flutter iOS part or the native iOS part.

imsujan276 commented 4 months ago

It worked really fast. No issues

ThibaultBee commented 4 months ago

I did have a look at Flutter iOS code but could not find anything. Are you sure to be up to date? (last version of the internal library with pod update,...)

imsujan276 commented 4 months ago

Yes.

I did pull the latest branch from git and run pod update, pod install --repo-update.

Installed and run correctly. just giving me that 10 seconds delay to succeed the connection

ThibaultBee commented 4 months ago

The original issue is solved in v1.2.0. Please reopen it if you feel something is missing.

About your connection issue, as it is not related to the opened issue. Please open a new issue.