After upgrading angular to 4.x from 2.x and typescript to 2.x started giving following error which was working fine with previous version
Cannot invoke an expression whose type lacks a call signature. Type '((onfulfilled?: (value: MediaStream) => TResult1 | Prom...' has no compatible call signatures.
My code is as following
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);
});
}
Typecasting self.getUserMedia(options)
to any
/Promise
resolved the problem.
So I used following code and it worked:
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');
});
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments