OpenVidu屏幕共享停止事件侦听器不起作用

时间:2020-04-09 12:50:58

标签: ionic4 openvidu

我正在一个ionic 4项目中进行OpenVidu屏幕共享。它的工作正常,但我试图听不起作用的停止共享按钮单击。他们的文档here中提到的代码无效。

initPublisher() {

    this.publisherToggle = this.OV.initPublisher(undefined, {
      audioSource: undefined, // The source of audio. If undefined default microphone
      videoSource: undefined, // The source of video. If undefined default webcam
      publishAudio: this.publishAudio, // Whether you want to start publishing with your audio unmuted or not
      publishVideo: this.publishVideo, // Whether you want to start publishing with your video enabled or not
      resolution: VideoResolution.low, // '640x480', // The resolution of your video
      frameRate: this.videoFramerate, // The frame rate of your video
      insertMode: 'APPEND', // How the video is inserted in the target element 'video-container'
      mirror: true, // Whether to mirror your local video or not

    });
    // this.publisherToggle = publisher;
    console.log('this.OV.initPublisher');
    // --- 6) Publish your stream ---
    if (this.newPublisher) {
      this.publisherToggle.once('accessAllowed', () => {
        this.session.unpublish(this.newPublisher);
        // this.session.publish(this.publisherToggle);
      });
    }

    this.session.publish(this.publisherToggle).then(() => {
      console.log('session.publish');
      // Store our Publisher
      this.publisher = this.publisherToggle;
    })
      .catch(error => {
        console.log('init publisher error', error.code, error.message);
      }); 
    
  }
Code to share screen:

shareScreen() {

    if (this.isScreenShared) {
      this._util.showToast('Screen sharing is on. Please stop it first.');
    } else {



       this.OV.initPublisherAsync(undefined, {
         videoSource: "screen"
       }).then(publisher => {
         publisher.stream.getMediaStream().addEventListener('inactive', () => {
           console.log('User pressed the "Stop sharing" button');
           this.initPublisher();
           this.isScreenShared = false;
         });
       }); 
      
      

      this.isScreenShared = true;
    }
  }

0 个答案:

没有答案