代码之家  ›  专栏  ›  技术社区  ›  Maciej Wojcik

WEBRTC-屏幕共享,无任何扩展

  •  1
  • Maciej Wojcik  · 技术社区  · 8 年前

    我有一个简单的问题。有没有可能在大多数设备和浏览器上实现屏幕共享?

    最好的解决方案是当我可以从navigator获得流时,就像我的相机捕捉一样。

    从摄像机获取视频的代码

    this.navig.getUserMedia =  ( this.navig.getUserMedia || this.navig.webkitGetUserMedia || this.navig.mozGetUserMedia || this.navig.msGetUserMedia );
    this.navig.getUserMedia({video: true, audio: true}, (stream) => {
            this.videoElement.nativeElement.src = window.URL.createObjectURL(stream);
            this.videoElement.nativeElement.play();
    }, (error) => console.warn('video error' + error))
    

    所以我想用我的屏幕捕捉流对象。这可能吗?

    我在网上找到了这个,但这给了我一些错误。。。

    navigator.mediaDevices.getDisplayMedia({ video: true })
    .then(stream => {
        // we have a stream, attach it to a feedback video element
        videoElement.srcObject = stream;
      }, error => {
        console.log("Unable to acquire screen capture", error);
      });
    
    2 回复  |  直到 8 年前
        1
  •  4
  •   Igor Vujovic    6 年前

    2019年更新:是的,这是可能的。 在Chrome、Firefox和Safari上使用 getDisplayMedia

    let displayMediaOptions = {video: true, audio: false};
    navigator.mediaDevices.getDisplayMedia(displayMediaOptions)
    .then(function(stream){
      video_el.srcObject = stream;
    })
    

    演示工作地点: thescreenshare.com

        2
  •  2
  •   Dr. Alex Gouaillard    8 年前

    在这个阶段,只有firefox允许你使用屏幕共享,而不需要额外的安全插件或服务。