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

Add BroadcastChannel #817

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,16 @@ Body[JT] def bodyUsed: Boolean
Body[JT] def formData(): js.Promise[FormData]
Body[JT] def json(): js.Promise[js.Any]
Body[JT] def text(): js.Promise[String]
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
BroadcastChannel[JC] def close(): Unit
BroadcastChannel[JC] def dispatchEvent(evt: Event): Boolean
BroadcastChannel[JC] def name: String
BroadcastChannel[JC] var onmessage: js.Function1[MessageEvent, _]
BroadcastChannel[JC] var onmessageerror: js.Function1[MessageEvent, _]
BroadcastChannel[JC] def postMessage(message: Any): Unit
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
CDATASection[JC] def appendChild(newChild: Node): Node
Expand Down
10 changes: 10 additions & 0 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,16 @@ Body[JT] def bodyUsed: Boolean
Body[JT] def formData(): js.Promise[FormData]
Body[JT] def json(): js.Promise[js.Any]
Body[JT] def text(): js.Promise[String]
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
BroadcastChannel[JC] def close(): Unit
BroadcastChannel[JC] def dispatchEvent(evt: Event): Boolean
BroadcastChannel[JC] def name: String
BroadcastChannel[JC] var onmessage: js.Function1[MessageEvent, _]
BroadcastChannel[JC] var onmessageerror: js.Function1[MessageEvent, _]
BroadcastChannel[JC] def postMessage(message: Any): Unit
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
CDATASection[JC] def appendChild(newChild: Node): Node
Expand Down
33 changes: 33 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/BroadcastChannel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation.JSGlobal

/** A named channel that any browsing context of a given origin can subscribe to. It allows communication between
* different documents (in different windows, tabs, frames or iframes) of the same origin. Messages are broadcasted via
* a message event fired at all BroadcastChannel objects listening to the channel, except the object that sent the
* message.
*/
@js.native
@JSGlobal
class BroadcastChannel(channelName: String) extends EventTarget {

/** Uniquely identifies the given channel with its name */
def name: String = js.native

/** terminates the connection to the underlying channel, allowing the object to be garbage collected */
def close(): Unit = js.native

/** Sends a message, which can be of any kind of Object, to each listener in any browsing context with the same origin
*/
def postMessage(message: Any): Unit = js.native

/** The message event is fired on a BroadcastChannel object when a message arrives on that channel */
var onmessage: js.Function1[MessageEvent, _] = js.native

/** The messageerror event is fired on a BroadcastChannel object when a message that can't be deserialized arrives on
* the channel
*/
var onmessageerror: js.Function1[MessageEvent, _] = js.native

}
Loading