Skip to content
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

Merged
merged 3 commits into from Jul 12, 2018

Conversation

felixrieseberg
Copy link
Member

@felixrieseberg felixrieseberg commented Jul 10, 2018

Checklist

This PR adds IsCurrentlyAudible to WebContents, allowing developers to determine whether or not audio is currently playing.

  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • relevant documentation is changed or added
  • commit messages or PR title follow semantic commit guidelines

audible

@felixrieseberg felixrieseberg requested review from a team July 10, 2018 16:16
Copy link
Member

@codebytere codebytere left a 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

@felixrieseberg
Copy link
Member Author

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 😉

@YurySolovyov
Copy link
Contributor

I wonder if it will register if you play recorded silence.

@felixrieseberg
Copy link
Member Author

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?

@MarshallOfSound MarshallOfSound added the semver/minor backwards-compatible functionality label Jul 11, 2018
@felixrieseberg
Copy link
Member Author

@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)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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 =)

w.webContents.send('play')
})
})
})
Copy link
Contributor

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()
})

@felixrieseberg
Copy link
Member Author

@alexeykuzmin feedback implemented!

@zeke
Copy link
Contributor

zeke commented Jul 11, 2018

Is there precedent for the name IsCurrentlyAudible? Wondering if something like IsPlayingAudio might make more sense.

Also wow I used to love Weezer. Are they still a band?

@alexeykuzmin
Copy link
Contributor

@felixrieseberg

ReferenceError: expect is not defined

Please import all dependencies =)

const chai = require('chai')
const dirtyChai = require('dirty-chai')

const {expect} = chai

chai.use(dirtyChai)

@alexeykuzmin
Copy link
Contributor

@zeke
I guess such a name is because of this

It does actually check whether or not sound is really playing, silent or muted audio doesn't count.

@felixrieseberg
Copy link
Member Author

@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.

@felixrieseberg
Copy link
Member Author

All the failing tests seem to fail on unrelated issues.

@MarshallOfSound MarshallOfSound merged commit deedf6c into master Jul 12, 2018
@MarshallOfSound MarshallOfSound deleted the is-currently-audible branch July 12, 2018 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor backwards-compatible functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants