Search code examples
uwpvoiplifecyclebackground-task

UWP Background VoIP Call


We are developing a RTP VoIP app for UWP Desktop. We are using a third-party library for the audio/video communication. The audio connection works fine as long as the app is in foreground or not minimized but as soon as the app is sent to the background by minimizing the audio connection is paused. When again in foreground the connection is resumed.

There are two distinct cases which occur:

  1. Fail: The uwp desktop app user initiates a call and then minimizes the app. The audio is cut off.
  2. Success: The uwp desktop app receives a call (which is first triggered by a PushNotificationChannel notification event). In this case, during the call, when the app is minimized, the audio connection stays active... which is a bit unexplained...

The purpose here is to get the background call audio (for case 1.) to also work while the app window is minimized.

Remarks: Based on the difference between the two call cases (no push notification for case 1) we assume that the push notification might be acquiring some type of deferral which we are not aware of. The interesting part is that this partially works. Case 1. will also work if it is tried after case 2. during the same app session.

PS: we already acquired the deferal for the following app lifecycle events:

        this.Suspending += this.OnSuspending;
        this.EnteredBackground += this.AppEnteredBackground;
        this.LeavingBackground += this.AppLeavingBackground;

        private void AppEnteredBackground(object sender, EnteredBackgroundEventArgs e)
        {
            var deferral = e.GetDeferral();
        }  

And also have the background media capability in the manifest:

<uap3:Capability Name="backgroundMediaPlayback" />

All and any ideas are most welcome :)


Solution

  • We have found a solution by using the VoipPohneCall UWP feature.

    When a call is established we request a new outgoing call:

    _voipCall = VoipCallCoordinator.GetDefault().RequestNewOutgoingCall(...);
    _voipCall.NotifyCallActive();
    

    And when the call ends:

    _voipCall.NotifyCallEnded();
    

    Covers both our required use-cases.