Has someone ever tried to use WebRTC with Elm

I would like to build a video chat application that utilizes WebRTC. To stay responsive I will implement this application as a SPA.
Now, I know that Elm can handle the SPA use case well, and got even better with the 0.19 release. But I have nothing found about WebRTC yet. Has someone experience with this? Is there a blog post I did not found?

AFAIK there are no Elm libraries that currently make it ā€˜easy’ to work with WebRTC in Elm.

However, the WebRTC JavaScript calls are already quite high-level, and you could relatively easily interact with them using some Ports.

I just made an Elm app with camera, I render a normal empty video tag in Elm.
Then I inject the camera into that element in javascript.
Messages like start/screenshot ++ is handled via ports.

You can also create a custom ā€œelm-videoā€ element and listen to events directly in elm on that node. Without ports.

Elm code:

Html.video
  [ Html.Attributes.id "videoTag" ]  [ ]

Javascript

// CAMERA
  video = document.getElementById("videoTag");
  if (navigator.mediaDevices.getUserMedia) {
    navigator.mediaDevices
      .getUserMedia({
        video: {
          facingMode: "environment"
        }
      })
      .then(function(stream) {
        video.srcObject = stream;
        video.play();
      })
      .catch(function(error) {
        console.log("Could not open camera",error);
      });
  }
1 Like

I’ve been using a custom element for media capture and it works well. If I can figure out how to represent the constraints well I’ll publish soon.

A few of us were just talking about WebRTC over drinks but I’m fairly certain it hasn’t yet been attempted.

4 Likes

I have been using WebRTC for data transfer in my soon-to-be SaaS (with ports), but it didn’t end up very reliable (probably due to the hand-written Node signaling server though).

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.