4

I have a task, but I can't seem to get it done. I've created a very simple WebRTC stream on a Raspberry Pi which will function as a videochat-camera. With ionic I made a simple mobile application which can display my WebRTC stream when the phone is connected to the same network. This all works.

So right now I have my own local stream which shows on my app. I now want to be able to broadcast this stream from my phone to a live server, so other people can spectate it.

I know how to create a NodeJS server which deploys my webcam with the 'getUserMedia' function. But I want to 'push' my WebRTC stream to a live server so I can retrieve a public URL for it.

Is there a way to push my local Websocket to a live environment? I'm using a local RTCPeerConnection to create a MediaStream object

this.peerconnection = new RTCPeerConnection(this.peerservers);
    this.peerconnection.onicecandidate = (event) => {
      if (event.candidate && event.candidate.candidate) {
        var candidate = {
          sdpMLineIndex: event.candidate.sdpMLineIndex,
          sdpMid: event.candidate.sdpMid,
          candidate: event.candidate.candidate
        };
        var request = {
          what: "addIceCandidate",
          data: JSON.stringify(candidate)
        };
        this.websockets.send(JSON.stringify(request));
      } else {
        console.log("End of candidates.");
      }
    };

And to bind the stream object to my HTML Video tag I'm using this

onTrack(event) {
    this.remoteVideo.srcObject = event.streams[0];
  }

My stream url is something like: MyLocalIP:port/streams/webrtc So I want to create a public URL out of it to broadcast it.

Jason van der Zeeuw
  • 923
  • 1
  • 11
  • 29

2 Answers2

3

Is there a way to push my local Websocket to a live environment?

It's not straightforward because you need more than vanilla webrtc (which is peer-to-peer). What you want is an SFU. Take a look at mediasoup.

To realize why this is needed think about how the webrtc connection is established in your current app. It's a negotiation between two parties (facilitated by a signaling server). In order to turn this into a multi-cast setup you will need a proxy of sorts that then establishes separate peer-to-peer connections to all senders and receivers.

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71
  • Okay this is clear to me for most part, but I don't know where to start. Is there any way for you to help me with pushing my ws:// websocket URL forward to a remote server? We can pay for it (don't know if I'm allowed to respond like this here) but I'm desperate to get this done! – Jason van der Zeeuw Dec 13 '21 at 09:53
  • 1
    I'm open to talking about that. Can you contact me via email/linkedin? Info in my profile. – Christian Fritz Dec 13 '21 at 16:26
2

You can do it with Socket.io & WebRTC, see the sample here

var offerer = new PeerConnection('http://domain:port', 'message', 'offerer');
offerer.onStreamAdded = function(e) {
   document.body.appendChild(e.mediaElement);
};
var answerer = new PeerConnection('http://domain:port', 'message', 'answerer');
answerer.onStreamAdded = function(e) {
   document.body.appendChild(e.mediaElement);
};
answerer.sendParticipationRequest('offerer');
Transformer
  • 6,963
  • 2
  • 26
  • 52