Skip to content

Commit

Permalink
Merge pull request #817 from scala-js/feature/broadcast-channel
Browse files Browse the repository at this point in the history
Add `BroadcastChannel`
  • Loading branch information
armanbilge authored Sep 23, 2023
2 parents c6139e6 + ecc7b05 commit f0c4f15
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
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

}

0 comments on commit f0c4f15

Please sign in to comment.