C0PT3R Posted January 6, 2016 Share Posted January 6, 2016 Hi, first of all, please excuse my english as it may not be perfect. I'm currently working on an online multiplayer game (webGL -> PIXI, webRTC -> PeerJS) and I just realized that when a player focuses out of the browser tab that displays the game, it stops updating. Searching the web, I found many forum posts talking about visibility API, but none would explain how to achieve my goal. Also heard about Phaser's disableVisibilityChange (or something like that). If Phaser can do it, it means there's a way. Digging through its code doesn't help, as I can't figure out how it is working... Does anybody have a clue? For information, I use requestAnimationFrame. Quote Link to comment Share on other sites More sharing options...
rich Posted January 7, 2016 Share Posted January 7, 2016 Browsers can (and often will) stop running RAF callbacks if the tab isn't visible. There isn't a way to stop this and it's up to the browser to determine what 'visible' means, and how long it should wait because pausing RAF. To get around it you can use the Page Visibility API to tell when the page is 'hidden' and then act accordingly (either stopping network updates, or starting a setTimeout loop, which doesn't stop based on visibility) Quote Link to comment Share on other sites More sharing options...
chg Posted January 7, 2016 Share Posted January 7, 2016 or starting a setTimeout loop, which doesn't stop based on visibilityAs per https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout#Inactive_tabs I was under the impression timeouts could be throttled on inactive tabs somewhat significantly too. Quote Link to comment Share on other sites More sharing options...
C0PT3R Posted January 10, 2016 Author Share Posted January 10, 2016 So, if I understand, I have to choose between pausing the game or sending only one update per second... This is too bad. By the way, thanks for your answers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.