/* * Copyright (c) 2024, Jamie Mansfield * Copyright (c) 2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace Web::HTML { class BroadcastChannel final : public DOM::EventTarget { WEB_PLATFORM_OBJECT(BroadcastChannel, DOM::EventTarget); GC_DECLARE_ALLOCATOR(BroadcastChannel); public: [[nodiscard]] static GC::Ref construct_impl(JS::Realm&, FlyString const& name); // https://html.spec.whatwg.org/multipage/web-messaging.html#dom-broadcastchannel-name FlyString const& name() const { // The name getter steps are to return this's channel name. return m_channel_name; } WebIDL::ExceptionOr post_message(JS::Value message); void close(); void set_onmessage(GC::Ptr); GC::Ptr onmessage(); void set_onmessageerror(GC::Ptr); GC::Ptr onmessageerror(); private: BroadcastChannel(JS::Realm&, FlyString const& name); virtual void initialize(JS::Realm&) override; bool is_eligible_for_messaging() const; FlyString m_channel_name; bool m_closed_flag { false }; }; }