Created
March 27, 2017 12:17
-
-
Save ivancuric/5ac6fd635c6d82a5f8d5884fe21a7911 to your computer and use it in GitHub Desktop.
Method for finding out the refresh rate of the device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _getRefreshRate() { | |
const rafPromise = _ => new Promise(requestAnimationFrame); | |
const idlePromise = _ => new Promise(requestIdleCallback); | |
let f1, f2; | |
return new Promise(resolve => { | |
idlePromise() | |
.then(_ => rafPromise()) | |
.then(frame => {f1 = frame; return rafPromise();}) | |
.then(frame => {f2 = frame; return rafPromise();}) | |
.then(_ => { | |
const ft = f2 - f1; | |
const fps = Math.ceil(1000 / ft); | |
console.log(`Refresh rate should be ${fps}Hz`); | |
resolve(); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment