New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add isCurrentlyAudible() to WebContents #13614
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 looks great to me
I've added a simple test. Major downside: When you're running the test, you'll hear a beep for about 10 milliseconds. Happy to take it out again if people would rather test in silence 😉 |
fe01734
to
f3da2de
Compare
f3da2de
to
13a2a1a
Compare
I wonder if it will register if you play recorded silence. |
It looks like the 32bit AppVeyor build had no test failures, but failed in an unrelated script. I can’t restart it, could someone with rights maybe kick it? |
@YurySolovyov It does actually check whether or not sound is really playing, silent or muted audio doesn't count. As an example, in the test, we need to wait a few ms because the oscillator takes a few ms to actually reach an audible level. Cool, right? |
oscillator.start() | ||
|
||
// It'll take a few ms before the beep shows up | ||
setTimeout(() => event.sender.send('playing'), 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it will take more than 100ms for the oscillator to become audible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It never should. In theory, it should start immediately, but the Web Audio API is still a working draft, so I've added the 100ms to ensure that we'll never have a flaky test, even if you're running the test on the slowest of all machines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, if you say so =)
spec/api-web-contents-spec.js
Outdated
w.webContents.send('play') | ||
}) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use our event helpers and Chai's expect
here:
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const {expect} = chai
chai.use(dirtyChai)
<...>
it('returns whether audio is playing', async () => {
w.loadURL(`file://${path.join(__dirname, 'fixtures', 'api', 'is-currently-audible.html')}`)
w.show()
await emittedOnce(w.webContents, 'did-finish-load')
expect(w.webContents.isCurrentlyAudible()).to.be.false()
w.webContents.send('play')
await emittedOnce(ipcMain, 'playing')
expect(w.webContents.isCurrentlyAudible()).to.be.true()
})
@alexeykuzmin feedback implemented! |
Is there precedent for the name Also wow I used to love Weezer. Are they still a band? |
Please import all dependencies =) const chai = require('chai')
const dirtyChai = require('dirty-chai')
const {expect} = chai
chai.use(dirtyChai) |
@zeke
|
@zeke That's what Chrome calls it, so I thought it'd be best if we just stick with existing names. I agree that the name ain't great, but going with the same Google has makes it easier for people to browse Google / StackOverflow for edge cases. |
All the failing tests seem to fail on unrelated issues. |
Checklist
This PR adds
IsCurrentlyAudible
to WebContents, allowing developers to determine whether or not audio is currently playing.npm test
passes