angular를 2.x에서 4.x로 업그레이드하고 typescript를 2.x로 업그레이드 한 후 이전 버전에서 잘 작동하는 다음 오류가 발생하기 시작했습니다.
형식에 호출 서명이없는 식을 호출 할 수 없습니다. 유형 '((onfulfilled ?: (값 : MediaStream) => TResult1 | Prom ...'에 호환되는 호출 서명이 없습니다.
내 코드는 다음과 같습니다.
getMediaStream(options:{video: boolean, audio: boolean}) {
let self: Caller = this;
return self.getUserMedia(options)
.then(stream => {
console.log('got our media stream:', stream);
self.privateMedia = createObjectURL(stream);
self.privateStream = stream;
return stream;
})
.catch(() => {
console.log('Could not get access to microphone & camera');
});
}
public getUserMedia(constraints) {
if (window.navigator.mediaDevices && window.navigator.mediaDevices.getUserMedia) {
return window.navigator.mediaDevices.getUserMedia(constraints);
}
return new Promise((resolve, reject) => {
const getMedia = window.navigator.getUserMedia;
if (!getMedia) reject(new Error('Browser unsupported'));
getMedia.call(navigator, constraints, resolve, reject);
});
}
타입 캐스팅 self.getUserMedia(options)
에 any
/이 Promise
문제를 해결.
그래서 다음 코드를 사용했고 작동했습니다.
getMediaStream(options:{video: boolean, audio: boolean}) {
let self = this;
return (<Promise>self.getUserMedia(options))// in place of promise 'any' or other any superclass to promise will work as well
.then(stream => {
console.log('got our media stream:', stream);
self.privateMedia = createObjectURL(stream);
self.privateStream = stream;
return stream;
}).catch(() => {
console.log('Could not get access to microphone & camera');
});
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다