title: TypeError while using navigator.mediaDevices.getUserMedia
body: <p>I'm trying to substitute the deprecated <code>navigator.getUserMedia</code> with <code>navigator.mediaDevices.getUserMedia</code> but while trying I get this error: </p>
  
  <blockquote>
    <p><em>TypeError: Cannot set property 'localStream' of undefined</em></p>
  </blockquote>
  
  <p>This is my HTML:</p>
  
  <pre><code>   &lt;video ref="videoPlayer" hide.bind="screenSharing" id="videoPlayer" autoplay muted&gt;&lt;/video&gt;
  </code></pre>
  
  <p>I'm using Aurelia Environment and my javascript is this:</p>
  
  <pre><code>attached() {
  
   if (!this.localStream) {
    this.getLocalMedia();
   }
  }    
  
  getLocalMedia() {
   let constraints: MediaStreamConstraints = {
     video: true,
     audio: true
   };
  
  navigator.mediaDevices.getUserMedia(constraints)
    .then(function (stream) {
      console.log('Got mic+video stream', stream);
      this.localStream = stream;
      this.videoPlayer.srcObject = this.localStream;
      this.videoPlayer.srcObject = stream;
     })
     .catch (function (err) {
       console.error(err);
   });
  // navigator.getUserMedia(constraints, (stream) =&gt; {
  //   console.log('Got mic+video stream', stream);
  //   this.localStream = stream;
  //   this.videoPlayer.srcObject = this.localStream;
  // },
  //   (err) =&gt; {
  //     console.error(err);
  //   }
  // );
  
    }
  </code></pre>
  
  <p>Someone can imagine what's the problem? I'm creating an app using Electron.</p>
  
  <p>I've seeen on Internet othershaving a similar problem so I printed stream: </p>
  
  <pre><code>Got mic+video stream 
  MediaStream {id: "EIGkOQeyfsaRpweVgRG8eQiZfiuJ2HV3QZqW", active: true,     onaddtrack: null, onremovetrack: null, onactive: null…}
  active: true
  id: "EIGkOQeyfsaRpweVgRG8eQiZfiuJ2HV3QZqW"
  onactive: null
  onaddtrack: null
  oninactive: null
  onremovetrack: null
  __proto__: MediaStream
  </code></pre>
  
  <p>I've tried also to add an EventListener when document is ready but I still have this problem; if I use the commented part with the deprecated navigator.getUserMedia everything's working</p>