feat: expose audio-state-changed
on webContents
(#37366)
feat: expose audio-state-changed on webContents
This commit is contained in:
parent
c8f715f9a1
commit
512e56baf7
3 changed files with 19 additions and 3 deletions
|
@ -635,6 +635,15 @@ Emitted when media starts playing.
|
||||||
|
|
||||||
Emitted when media is paused or done playing.
|
Emitted when media is paused or done playing.
|
||||||
|
|
||||||
|
#### Event: 'audio-state-changed'
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
* `event` Event<>
|
||||||
|
* `audible` boolean - True if one or more frames or child `webContents` are emitting audio.
|
||||||
|
|
||||||
|
Emitted when media becomes audible or inaudible.
|
||||||
|
|
||||||
#### Event: 'did-change-theme-color'
|
#### Event: 'did-change-theme-color'
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
|
|
|
@ -1507,7 +1507,14 @@ content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::OnAudioStateChanged(bool audible) {
|
void WebContents::OnAudioStateChanged(bool audible) {
|
||||||
Emit("-audio-state-changed", audible);
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
gin::Handle<gin_helper::internal::Event> event =
|
||||||
|
gin_helper::internal::Event::New(isolate);
|
||||||
|
v8::Local<v8::Object> event_object = event.ToV8().As<v8::Object>();
|
||||||
|
gin::Dictionary dict(isolate, event_object);
|
||||||
|
dict.Set("audible", audible);
|
||||||
|
EmitWithoutEvent("audio-state-changed", event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::BeforeUnloadFired(bool proceed,
|
void WebContents::BeforeUnloadFired(bool proceed,
|
||||||
|
|
|
@ -565,11 +565,11 @@ describe('webContents module', () => {
|
||||||
oscillator.connect(context.destination)
|
oscillator.connect(context.destination)
|
||||||
oscillator.start()
|
oscillator.start()
|
||||||
`);
|
`);
|
||||||
let p = once(w.webContents, '-audio-state-changed');
|
let p = once(w.webContents, 'audio-state-changed');
|
||||||
w.webContents.executeJavaScript('context.resume()');
|
w.webContents.executeJavaScript('context.resume()');
|
||||||
await p;
|
await p;
|
||||||
expect(w.webContents.isCurrentlyAudible()).to.be.true();
|
expect(w.webContents.isCurrentlyAudible()).to.be.true();
|
||||||
p = once(w.webContents, '-audio-state-changed');
|
p = once(w.webContents, 'audio-state-changed');
|
||||||
w.webContents.executeJavaScript('oscillator.stop()');
|
w.webContents.executeJavaScript('oscillator.stop()');
|
||||||
await p;
|
await p;
|
||||||
expect(w.webContents.isCurrentlyAudible()).to.be.false();
|
expect(w.webContents.isCurrentlyAudible()).to.be.false();
|
||||||
|
|
Loading…
Reference in a new issue