【WebRtc】获取分享屏幕

2023-03-13  本文已影响0人  HeloWxl

分享前页面

image.png

获取分享屏幕

image.png

Code

 /**
     * 开始屏幕共享
     */
    openShareScreen() {
      var that = this
      // 判断是否支持获取本地屏幕分享数据
      if (!navigator.mediaDevices || !navigator.mediaDevices.getDisplayMedia) {
        that.$notify({
          title: '警告',
          message: '浏览器不支持本地屏幕设备',
          type: 'warning'
        });
        return;
      }
      const constraints = {
        audio: true,
        video: true
      };
      this.loading = true
      this.getLocalDisplayMedia(constraints).then(stream => {
        // 拿到流数据后,将流显示在video标签内
        this.setDomVideoStream('localVideo', stream);
        // 监听流
        stream.getVideoTracks()[0].onended = () => {
          //监听以后的处理逻辑……
          this.$notify({
            title: '提示',
            message: '屏幕共享已关闭',
            type: 'success'
          });
          that.closeUserMedia('localVideo')
        }
      });
    }

期待更新,麻烦点个赞,点个关注,栓Q !

上一篇下一篇

猜你喜欢

热点阅读