title: Webcam streaming client to client
body: <p>The task is that the client <code>A</code> can stream from web camera to other clients <code>B</code>, <code>C</code>, etc via server <code>S</code>.</p>
  
  <p>I configured the <strong>HLS</strong> streaming server using <strong>NGINX</strong> + <strong>nginx-rtmp-module</strong>. It works fine. Now my server can do streaming. Executing this command on the server I create the stream.</p>
  
  <pre><code>$ ffmpeg -f video4linux2 -video_size 640x480 -i /dev/video0 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/live/stream
  </code></pre>
  
  <p>This command captures the webcam and creates a stream that is accessible by URL: <code>rtmp://localhost:1935/live/stream</code>.</p>
  
  <p>And now I can watch this stream in any video player.</p>
  
  <p>But I need to capture video from browser of the client <code>A</code> and transfer it to the url <code>rtmp://localhost:1935/live/stream</code> to create a stream.</p>
  
  <p>In JS script I capture the stream from the web camera and display it in <code>&lt;video&gt;</code> tag.</p>
  
  <p><strong>HTM</strong>L code:</p>
  
  <pre><code>&lt;div class="box-body"&gt;
      &lt;div class="row"&gt;
          &lt;div class="col-xs-12"&gt;
              &lt;video controls muted&gt;&lt;/video&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>JS</strong> code:</p>
  
  <pre><code>let recordingPlayer = $('video');
  let videoStream = null;
  
  let successCallback = function (stream) {
      recordingPlayer[0].srcObject = stream;
      recordingPlayer[0].play();
  
      videoStream = stream;
  
      // I think I need to somehow transfer this stream to the address:
      // rtmp://localhost:1935/live/stream
  };
  
  let errorCallback = function (error) {
      console.log(error);
  };
  
  let mediaConstraints = { video: true, audio: true };
  
  // Doing webcam capture
  navigator.mediaDevices
      .getUserMedia(mediaConstraints)
      .then(successCallback)
      .catch(errorCallback);
  </code></pre>
  
  <p>But I absolutely can not understand how I can transfer the stream from the client <code>A</code> webcam to the my <strong>HLS</strong> streaming server.</p>
  
  <p>As I understand, the <code>ffmpeg</code> command captures video from the server webcam, then converts it to the suitable format (mp4 with video codec libx264), then sends data to this url <code>rtmp://localhost:1935/live/stream</code>.</p>
  
  <p>I think I need to send the stream from the web camera to the server using web sockets, and then on the server, using that command <code>ffmpeg</code>, send data to that address.</p>
  
  <p>Can you please help me, how to send captured stream from the webcam to the <strong>HLS</strong> streaming server?</p>