-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: AudioContext baseLatency entropy source (#1004)
- Loading branch information
1 parent
703ea10
commit c975bbf
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { getBrowserVersion, isGecko, isWebKit } from '../../tests/utils' | ||
import getAudioBaseLatency from './audio_base_latency' | ||
|
||
describe('Sources', () => { | ||
describe('audioBaseLatency', () => { | ||
it("doesn't fail", () => { | ||
const result = getAudioBaseLatency() | ||
if (!hasBaseLatencySupport()) { | ||
expect(result).toBe(undefined) | ||
return | ||
} | ||
|
||
if (isGecko()) { | ||
expect(result).toBe(0) | ||
} else { | ||
expect(result).toBeGreaterThan(0) | ||
} | ||
}) | ||
|
||
it('returns a stable value', () => { | ||
const first = getAudioBaseLatency() | ||
const second = getAudioBaseLatency() | ||
expect(second).toBe(first) | ||
}) | ||
}) | ||
}) | ||
|
||
function hasBaseLatencySupport() { | ||
if (isWebKit()) { | ||
const { major, minor } = getBrowserVersion() || { major: 0, minor: 0 } | ||
if (major < 14) { | ||
return false | ||
} else if (major == 14) { | ||
return minor >= 1 | ||
} | ||
} | ||
return true | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function getAudioContextBaseLatency(): number | undefined { | ||
if (!window.AudioContext) { | ||
return undefined | ||
} | ||
|
||
return new AudioContext().baseLatency | ||
} |
This file contains 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