ant-media / Ant-Media-Server

Ant Media Server is a live streaming engine software that provides adaptive, ultra low latency streaming by using WebRTC technology with ~0.5 seconds latency. Ant Media Server is auto-scalable and it can run on-premise or on-cloud.
https://antmedia.io
Other
4.31k stars 636 forks source link

iOS screen share pausing when app enters in background mode. #3603

Open vinodvulupala opened 3 years ago

vinodvulupala commented 3 years ago

Hi Team,

I integrated Ant media in my project for screen sharing, it is working fine in Foreground mode, but when app enters in "background mode" screen sharing is pausing but still audio is working.Please let me know the way to work even in background mode.

Enabled background modes

  1. Voice over IP and Audio
  2. airplay, and Picture in Picture
riotbroadcast commented 3 years ago

Hi there, I'm not very good with github, so perhaps email me to stephenanning@gmail.com , but I am trying to achieve this with audio only. So you're saying that your webRTC audio stream continued in the background when you had those background modes enabled?!

kputyra commented 3 years ago

Hi @vinodvulupala and @riotbroadcast

I've encountered the same problem previously. This is not related to Ant Media, but to browsers. Modern browsers try to save battery by stopping rendering graphics & video when in background. If I remember correctly, this should not happen to outgoing WebRTC streams, like screen sharing, but I don't know the entire WebRTC specification.

My hacky workaround is to draw periodically the stream on canvas and only then send it to Ant Media. You could achieve that with setTimeout(), but this is again not reliable (when in a background, the browsers runs those tasks with lower frequency, it can even do not run it at all). That's why I decided to use a web worker (a script running on a separate thread, check MDN for info & examples):

  1. The web worker sends a message to the main thread 30x per second.
  2. The main thread reacts to the message by drawing the screen on canvas.
  3. A stream captured from the canvas is sent to Ant Media Still not a perfect solution, but it's better than a paused stream. I'm not sure if this works on every browser (not tested with Safari).

@riotbroadcast I've never had issues with audio not being published, but I had issues with audio not being played on Safari. One option is to play it on an

mekya commented 3 years ago

Thank you for your great explanation @kputyra

Is there anything you want Ant Media team to take a look? @vinodvulupala @riotbroadcast

Btw, sorry for the late reply.

riotbroadcast commented 3 years ago

Our issue is on iOS and Android. The streams work perfectly when the devices are connected to Wi-Fi. Streams will not start on LTE/4g on iOS and on Android LTE/4g the streams will start but they constantly pause/drop out.

Warm regards, Stephen Anning 0403 881 700

Sent from Stephen's iPhone

On 26 Oct 2021, at 21:57, Ahmet Oğuz Mermerkaya @.***> wrote:

 Thank you for your great explanation @kputyra

Is there anything you want Ant Media team to take a look? @vinodvulupala @riotbroadcast

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

riotbroadcast commented 3 years ago

We are also only streaming audio, we have video disabled.

Warm regards, Stephen Anning 0403 881 700

Sent from Stephen's iPhone

On 26 Oct 2021, at 22:48, Stephen Anning @.***> wrote:

Our issue is on iOS and Android. The streams work perfectly when the devices are connected to Wi-Fi. Streams will not start on LTE/4g on iOS and on Android LTE/4g the streams will start but they constantly pause/drop out.

Warm regards, Stephen Anning 0403 881 700

Sent from Stephen's iPhone

On 26 Oct 2021, at 21:57, Ahmet Oğuz Mermerkaya @.***> wrote:

 Thank you for your great explanation @kputyra

Is there anything you want Ant Media team to take a look? @vinodvulupala @riotbroadcast

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

mekya commented 3 years ago

Hi Stephen, I think the problem you're mentioning is not directly related to this issue.

Our issue is on iOS and Android. The streams work perfectly when the devices are connected to Wi-Fi. Streams will not start on LTE/4g on iOS and on Android LTE/4g the streams will start but they constantly pause/drop out.

Your problem seems like a connection issue. Workaround solution can be something using TURN server. Alternatively, we can schedule a meeting to understand the problem.