8000 iOS screen broadcast freezes after the app is moved to the background for a few minutes. · Issue #1641 · flutter-webrtc/flutter-webrtc · GitHub
[go: up one dir, main page]

Skip to content

iOS screen broadcast freezes after the app is moved to the background for a few minutes. #1641

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

Open
harshmdr opened this issue Jul 30, 2024 · 12 comments

Comments

@harshmdr
Copy link

After moving background, open any app like gmail etc and then leave it for some seconds and now screen streaming is frozen in IOS. Once you back into foreground, it is working again.

Any suggestion/solution here?

@harshmdr harshmdr changed the title The iOS screen broadcast freezes after the app is moved to the background for a few minutes. iOS screen broadcast freezes after the app is moved to the background for a few minutes. Jul 30, 2024
@harshmdr
Copy link
Author

It is working on debug mode while developing but not for release app.

@vendroid12
Copy link

I will look into that.

It is working on debug mode while developing but not for release app.

@harshmdr
Copy link
Author

Thank you @vendroid12

@lambiengcode
Copy link
Contributor

A year ago, I faced this issue and after investigations, I realized that starting iOS CallKit is necessary because it keeps your app as a high priority.

callkit-waterbus

@harshmdr
Copy link
Author
harshmdr commented Jul 31, 2024

Can you please explain a little bit more like what steps do I need to do? @lambiengcode
I just need to broadcast IOS screen on all other apps.
Thank you

@lambiengcode
Copy link
Contributor

When broadcasting my phone screen, if I switch to other apps for a few minutes without starting CallKit, the system assumes my app is using unnecessary energy. I noticed that apps like Jitsi and Google Meet start CallKit to avoid this issue. After implementing CallKit in my app, it worked correctly as well.

You can use: https://pub.dev/packages/flutter_callkit_incoming and implement some code in native iOS:

import Flutter
import UIKit
import waterbus_callkit_incoming

public class WaterbusSdkPlugin: NSObject, FlutterPlugin {
  var uuidCall: String = ""

  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "waterbus-sdk/native-plugin", binaryMessenger: registrar.messenger())
    let instance = WaterbusSdkPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

  public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
    switch call.method {
    case "getPlatformVersion":
      result("" + UIDevice.current.systemVersion)
      break
    case "startCallKit":
      let arguments = call.arguments as? [String: Any] ?? [String: Any]()
      let uuidCallPartner = NSUUID().uuidString
      self.uuidCall = uuidCallPartner

      let nameCall = arguments["nameCaller"] as? String ?? "Waterbus"
      var info = [String:Any?]()
      info["id"] = uuidCallPartner
      info["nameCaller"] = nameCall
      info["handle"] = "0123456789"
      info["type"] = 1
      
      SwiftFlutterCallkitIncomingPlugin.sharedInstance?.startCall(waterbus_callkit_incoming.Data(args: info), fromPushKit: true)
      result(true)
      break
    case "getCurrentUuid":
      result(self.uuidCall)
      break
    default:
      result(FlutterMethodNotImplemented)
    }
  }
}

After call connected, call startCallKit. Take a look at: https://github.com/waterbustech/waterbus-flutter-sdk/blob/migration/v2/ios/Classes/WaterbusSdkPlugin.swift

@harshmdr
Copy link
Author

Thanks @lambiengcode

@harshmdr
Copy link
Author

I am not using incoming and outgoing calls in our app, so you mean we just need to show that we are using call, Is that right?
@lambiengcode

@lambiengcode
Copy link
Contributor

My app does not use incoming calls. I implemented CallKit solely for screen sharing. Is is clear?

@harshmdr
Copy link
Author
harshmdr commented Jul 31, 2024

@lambiengcode Thanks, now your solution is working for me.
I have used https://pub.dev/packages/flutter_callkit_incoming , no need to add native code.

Future<bool> startOutGoingCall() async {
    if (Platform.isIOS) {
      try {
        // Generate a UUID
        String uuid = const Uuid().v4().toString();
        // Ready Params
        CallKitParams params = CallKitParams(
            id: uuid,
            nameCaller: "harsh tyagi",
            handle: '0123456789',
            type: 1,
            extra: <String, dynamic>{'userId': 'harshtyagimdr'},
            ios: const IOSParams(
                iconName: "Logo", // ios/Runner/Assets.xcassets/Logo.imageset
                handleType: 'generic',
                audioSessionActive: false,
                configureAudioSession: false));

        await FlutterCallkitIncoming.startCall(params);

        callListener = FlutterCallkitIncoming.onEvent.listen((event) {
          switch (event!.event) {
            case Event.actionCallStart:
              print("call started");
              break;
            case Event.actionCallEnded:
              print("call Stopped");
              break;
            default:
              break;
          }
        });
        setState(() {
          currentUuid = uuid;
        });
        return true;
      } catch (e) {
        showToast("Something went wrong! Please start again", isError: true);
      }
    }
    return false;
  }

  Future<void> stopOutGoingCall() async {
    if (currentUuid != null && Platform.isIOS) {
      try {
        await FlutterCallkitIncoming.endCall(currentUuid!);
        setState(() {
          currentUuid = null;
        });
        callListener?.cancel();
      } catch (e) {
        print("Error while stop outgoing call: $e");
      }
    }
  }

@harshmdr
Copy link
Author
harshmdr commented Aug 2, 2024

@lambiengcode Do you have any idea about that issue #1631?

@seawaya0012
Copy link

@lambiengcode Thx bro!!

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

4 participants
0