Adesh Patel
Adesh Patel

Reputation: 31

Webrtc Screen Sharing for p2p

I have setup the source using by below git repo. Audio/video calling is working fine, but there is not an option for screen sharing.

I have added one button for screen sharing but that does not display a shared screen to the destination person, it displays to the shared person only. How can I fix this?

https://github.com/webrtc/apprtc

https://github.com/webrtc/apprtc/tree/master/src/collider

Call.prototype.maybeGetMediaForScreenSharing_ = function() {
  var needStream = (this.params_.mediaConstraints.audio !== false || this.params_.mediaConstraints.video !== false);
  var mediaPromise = null;
  if (needStream) {
    var mediaConstraints = '{"audio":true,"video":{"optional":[{"minWidth":"1280"},{"minHeight":"720"},{"mediaSource":"screen"}],"mandatory":{}}}';
    mediaPromise = navigator.mediaDevices.getDisplayMedia({
      audio: true,
      video: true
    }).catch(function(error) {
      if (error.name !== 'NotFoundError') {
        throw error;
      }

      return navigator.mediaDevices.getDisplayMedia({
        audio: true,
        video: true
      });
    }).then(function(stream) {
      var videoTracks = this.localStream_.getVideoTracks();
      var audioTracks = this.localStream_.getAudioTracks();

      //this.onlocalstreamadded(stream);
      this.onremotestreamadded(stream);
    }.bind(this)).catch(function(error) {
      alert("Error");
      this.onError_('Error getting user media: ' + error.message);
      this.onUserMediaError_(error);
    }.bind(this));
  } else {
    mediaPromise = Promise.resolve();
  }
  return mediaPromise;
};

Upvotes: 2

Views: 172

Answers (0)

Related Questions