0

I am having trouble accessing a function from within my then in a promise. gotStream(stream) is showing as undefined. I have tried NgZone, and that hasn't helped as well. Thank you very much.

gotStream(stream) {
    this.localVideo.nativeElement.srcObject = stream;
    this.localStream = stream;
    this.callButton.nativeElement.disabled = false;
  }

  start() {
    navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then(function (e) {
      debugger;
        this.gotStream(e);
    }).catch(function (e) {
      alert('getUserMedia() error: ' + e.name);
    });
  }

Defining the function as an arrow function also shows gotstream as undefined:

navigator.mediaDevices.getUserMedia({ audio: true, video: true }).then((e) => {
      debugger;
        this.gotStream(e);
    }).catch(function (e) {
      alert('getUserMedia() error: ' + e.name);
    });
Kevin192291
  • 1,925
  • 4
  • 26
  • 43

0 Answers0