尝试使用webRTC从远程计算机上的元素流式传输视频

时间:2018-12-10 23:35:03

标签: javascript video-streaming webrtc

我正在尝试从div中提取视频,该div是来自网络上几台记录器之一。我知道它正在使用webRTC来流式传输视频-参见下文。

enter image description here

到目前为止,我对此的测试是流式传输本地网络摄像头,但是当我从本地网络摄像头(localstream)更改为指向远程录像机时,我遇到了问题。我对双向通讯或录音机的音频不感兴趣。下面是javascript代码段。

'use strict';

// Streaming only video (video: true).
const mediaStreamConstraints = {
  video: true,
};

// Video element where stream will be placed.
const localVideo = document.querySelector('video');

// Local stream that will be reproduced on the video.
let localStream;

// Handles success by adding the MediaStream to the video element.
function gotLocalMediaStream(mediaStream) {
  localStream = mediaStream;
  localVideo.srcObject = mediaStream;
}

// Handles error by logging a message to the console with the error message.
function handleLocalMediaStreamError(error) {
  console.log('navigator.getUserMedia error: ', error);
}

// Initializes media stream.
navigator.mediaDevices.getUserMedia(mediaStreamConstraints)
  .then(gotLocalMediaStream).catch(handleLocalMediaStreamError);

感谢您的任何建议:)

0 个答案:

没有答案