WebAudio: Add stub for AudioDestinationNode.destination

This is called by https://athenacrisis.com/ and passed through to
AudioNode.connect, which expects an AudioNode.

Implement this function enough so that we return an AudioNode so that
AudioNode.connect does not throw a TypeError.
This commit is contained in:
Shannon Booth 2024-07-24 17:50:06 +12:00 committed by Andreas Kling
parent 5eb80b8697
commit a51095f705
Notes: github-actions[bot] 2024-07-24 09:15:48 +00:00
3 changed files with 26 additions and 1 deletions

View file

@ -10,6 +10,7 @@
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/WebAudio/AudioBuffer.h>
#include <LibWeb/WebAudio/AudioBufferSourceNode.h>
#include <LibWeb/WebAudio/AudioDestinationNode.h>
#include <LibWeb/WebAudio/BaseAudioContext.h>
#include <LibWeb/WebAudio/BiquadFilterNode.h>
#include <LibWeb/WebAudio/DynamicsCompressorNode.h>
@ -32,6 +33,24 @@ void BaseAudioContext::initialize(JS::Realm& realm)
WEB_SET_PROTOTYPE_FOR_INTERFACE(BaseAudioContext);
}
void BaseAudioContext::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_destination);
}
// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-destination
JS::NonnullGCPtr<AudioDestinationNode> BaseAudioContext::destination()
{
auto& realm = this->realm();
dbgln("FIXME: Properly implement BaseAudioContext::destination");
if (!m_destination)
m_destination = realm.heap().allocate<AudioDestinationNode>(realm, realm, *this);
return *m_destination;
}
void BaseAudioContext::set_onstatechange(WebIDL::CallbackType* event_handler)
{
set_event_handler_attribute(HTML::EventNames::statechange, event_handler);

View file

@ -55,17 +55,22 @@ public:
WebIDL::ExceptionOr<JS::NonnullGCPtr<DynamicsCompressorNode>> create_dynamics_compressor();
JS::NonnullGCPtr<GainNode> create_gain();
JS::NonnullGCPtr<AudioDestinationNode> destination();
protected:
explicit BaseAudioContext(JS::Realm&, float m_sample_rate = 0);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor& visitor) override;
private:
float m_sample_rate { 0 };
double m_current_time { 0 };
Bindings::AudioContextState m_control_thread_state = Bindings::AudioContextState::Suspended;
Bindings::AudioContextState m_rendering_thread_state = Bindings::AudioContextState::Suspended;
JS::GCPtr<AudioDestinationNode> m_destination;
};
}

View file

@ -2,6 +2,7 @@
#import <DOM/EventHandler.idl>
#import <WebAudio/AudioBuffer.idl>
#import <WebAudio/AudioBufferSourceNode.idl>
#import <WebAudio/AudioDestinationNode.idl>
#import <WebAudio/DynamicsCompressorNode.idl>
#import <WebAudio/GainNode.idl>
#import <WebAudio/OscillatorNode.idl>
@ -16,7 +17,7 @@ enum AudioContextState { "suspended", "running", "closed" };
// https://webaudio.github.io/web-audio-api/#BaseAudioContext
[Exposed=Window]
interface BaseAudioContext : EventTarget {
[FIXME] readonly attribute AudioDestinationNode destination;
readonly attribute AudioDestinationNode destination;
readonly attribute float sampleRate;
readonly attribute double currentTime;
[FIXME] readonly attribute AudioListener listener;