Skip to content

Commit f0c4f15

Browse files
authored
Merge pull request #817 from scala-js/feature/broadcast-channel
Add `BroadcastChannel`
2 parents c6139e6 + ecc7b05 commit f0c4f15

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

api-reports/2_12.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,16 @@ Body[JT] def bodyUsed: Boolean
612612
Body[JT] def formData(): js.Promise[FormData]
613613
Body[JT] def json(): js.Promise[js.Any]
614614
Body[JT] def text(): js.Promise[String]
615+
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
616+
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
617+
BroadcastChannel[JC] def close(): Unit
618+
BroadcastChannel[JC] def dispatchEvent(evt: Event): Boolean
619+
BroadcastChannel[JC] def name: String
620+
BroadcastChannel[JC] var onmessage: js.Function1[MessageEvent, _]
621+
BroadcastChannel[JC] var onmessageerror: js.Function1[MessageEvent, _]
622+
BroadcastChannel[JC] def postMessage(message: Any): Unit
623+
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
624+
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
615625
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
616626
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
617627
CDATASection[JC] def appendChild(newChild: Node): Node

api-reports/2_13.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,16 @@ Body[JT] def bodyUsed: Boolean
612612
Body[JT] def formData(): js.Promise[FormData]
613613
Body[JT] def json(): js.Promise[js.Any]
614614
Body[JT] def text(): js.Promise[String]
615+
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
616+
BroadcastChannel[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
617+
BroadcastChannel[JC] def close(): Unit
618+
BroadcastChannel[JC] def dispatchEvent(evt: Event): Boolean
619+
BroadcastChannel[JC] def name: String
620+
BroadcastChannel[JC] var onmessage: js.Function1[MessageEvent, _]
621+
BroadcastChannel[JC] var onmessageerror: js.Function1[MessageEvent, _]
622+
BroadcastChannel[JC] def postMessage(message: Any): Unit
623+
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
624+
BroadcastChannel[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
615625
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
616626
CDATASection[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
617627
CDATASection[JC] def appendChild(newChild: Node): Node
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.scalajs.dom
2+
3+
import scala.scalajs.js
4+
import scala.scalajs.js.annotation.JSGlobal
5+
6+
/** A named channel that any browsing context of a given origin can subscribe to. It allows communication between
7+
* different documents (in different windows, tabs, frames or iframes) of the same origin. Messages are broadcasted via
8+
* a message event fired at all BroadcastChannel objects listening to the channel, except the object that sent the
9+
* message.
10+
*/
11+
@js.native
12+
@JSGlobal
13+
class BroadcastChannel(channelName: String) extends EventTarget {
14+
15+
/** Uniquely identifies the given channel with its name */
16+
def name: String = js.native
17+
18+
/** terminates the connection to the underlying channel, allowing the object to be garbage collected */
19+
def close(): Unit = js.native
20+
21+
/** Sends a message, which can be of any kind of Object, to each listener in any browsing context with the same origin
22+
*/
23+
def postMessage(message: Any): Unit = js.native
24+
25+
/** The message event is fired on a BroadcastChannel object when a message arrives on that channel */
26+
var onmessage: js.Function1[MessageEvent, _] = js.native
27+
28+
/** The messageerror event is fired on a BroadcastChannel object when a message that can't be deserialized arrives on
29+
* the channel
30+
*/
31+
var onmessageerror: js.Function1[MessageEvent, _] = js.native
32+
33+
}

0 commit comments

Comments
 (0)