Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8e0b102c23d6c5777a2c746af05c91d7d6a151725aa84c3b1e77335923a4c501
md5=e24e6b6aafc3a15a0df5cd0c4bdafb4c
Description
The BroadcastChannel interface represents 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.
Added to opam-repository:
README
Jsoo_broadcastchannel
Jsoo_broadcastchannel is a binding for the BroadcastChannel Api.
Example of use
Creating a channel an post message (on a first file) :
let channel = Broadcast_channel.create "my_first_channel"
let _ = Broadcast_channel.post channel (Js.string "Hello World")Receiving message from the channel my_first_channel on another file with onmessage
(* Retreive the channel *)
let channel : Js.string Js.t Broadcast_channel.t =
Broadcast_channel.create "my_first_channel"
(* You have to fix the type of the channel, you can also use [Broadcast_channel.create_with] *)
let _ =
Broadcast_channel.on
channel
(fun ev ->
(* Use the ev object *)
Js._true
)Receiving message from the channel my_first_channel on an another file with addEventListener
(* Retreive the channel *)
let channel : Js.string Js.t Broadcast_channel.t =
Broadcast_channel.create "my_first_channel"
(* You have to fix the type of the channel, you can also use [Broadcast_channel.create_with] *)
let _ =
Broadcast_channel.addEventListener
channel
(Broadcast_channel.message channel)
(Dom.handler (fun ev -> ... Js._true))
Js._trueOr you can use Broadcast_channel.create_with (for a more convenient usage, without type annotation)
(* Retreive the channel *)
let (channel, message_event) =
Broadcast_channel.create_with
"my_first_channel"
(Js.string "a sample")
let _ =
Broadcast_channel.addEventListener
channel
message_event
(Dom.handler (fun ev -> ... Js._true))
Js._trueReceiving message from the channel my_first_channel on an another file with Lwt_js_events
(* Retreive the channel *)
let channel : Js.string Js.t Broadcast_channel.t =
Broadcast_channel.create "my_first_channel"
let _ =
Lwt_js_events.async_loop
Broadcast_channel.lwt_js_message
channel
(fun ev _ ->
...
Lwt.return_unit
)Special thanks
I would like to sincerely thank @drup for his advice on the implementation and the design of the API !
Sample
Dependencies (5)
-
dune
>= "1.11" - lwt
- js_of_ocaml-ppx
-
js_of_ocaml
>= "2.8.4" -
ocaml
>= "4.02.0"
Dev Dependencies
None
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building jsoo_broadcastchannel with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 2.0.0 (this version) | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure