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

[FEATURE REQUEST] WebRTC bindings #757

Closed
monstasat opened this issue Mar 14, 2019 · 4 comments
Closed

[FEATURE REQUEST] WebRTC bindings #757

monstasat opened this issue Mar 14, 2019 · 4 comments

Comments

@monstasat
Copy link
Contributor

Hi!

I've recently done some work on implementing bindings for some browser API not present in js_of_ocaml standard library.

  1. WebRTC API
    The bindings are not complete and final, but I think they are sufficient for most users.
    The implementation can be found here.

  2. Promise API
    During the implementation of WebRTC bindings, I've found that this API heavily uses promises, but there is no support for promises in js_of_ocaml stdlib. Moreover, some existing js_of_ocaml bindings, e.g. for the mediaElement object, do not meet the modern browsers' API, which requires a promise to be returned for the play method.
    I've found the ocaml-promise-js project developed by @johnelse with Promise API bindings implemented. Unfortunately, it is not in the OPAM repository. I've slightly modified it by adding to_lwt and to_lwt_result functions, as I think that working with Lwt is far more convenient from the OCaml side. Maybe of_lwt and of_lwt_result functions may also be of interest. Here is the code.

  3. ResizeObserver API
    js_of_ocaml already has bindings for MutationObeserver API, but lacks bindings for ResizeObserver. Here is the code.

Is there any interest in merging this to js_of_ocaml repo? If yes, I can provide a PR.
Of course I will accept any advises on how the code can be improved and refactored to meet jsoo conventions.

@kevinji
Copy link
Contributor

kevinji commented Mar 23, 2019

There's some existing discussion about promises here: #609. TL;DR: JavaScript Promises are not type-safe and therefore binding directly to the Promise API would be unsound.

@hhugo
Copy link
Member

hhugo commented Dec 12, 2019

ResizeObserver is now included as part of #867

@adrien-n
Copy link
Contributor

In order to test stuff related to WebCrypto, I did a very quick wrapper around promises. It doesn't care about failures and it's not practical. But it's short and quick to copy-paste if you find yourself wanting to test something else before diving into promises support in jsoo. The code is below, comes with no guarantee and is remotely usable in practice only if you're doing some kind of FRP.

type 'a promise

let promise_cb =
  let module U = Js.Unsafe in
  let opr = U.js_expr "function(promise, f) { return promise.then(f); }" in
  fun (promise : 'a promise) (cb : 'a -> unit) ->
    ignore @@ U.fun_call opr [|
      U.inject @@ promise;
      U.inject @@ Js.wrap_callback cb;
    |]

@hhugo hhugo changed the title WebRTC, Promise, ResizeObserver bindings [FEATURE REQUEST] WebRTC, Promise, ResizeObserver bindings Sep 30, 2021
@hhugo hhugo added the Lib label Sep 30, 2021
@hhugo hhugo changed the title [FEATURE REQUEST] WebRTC, Promise, ResizeObserver bindings [FEATURE REQUEST] WebRTC bindings Jan 11, 2022
@hhugo
Copy link
Member

hhugo commented Mar 28, 2024

I'll document binding availability in #1217

@hhugo hhugo closed this as completed Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants