diff --git a/lib/RTCSession.js b/lib/RTCSession.js index 7a1dfd63..bd9ebc7c 100644 --- a/lib/RTCSession.js +++ b/lib/RTCSession.js @@ -663,6 +663,14 @@ module.exports = class RTCSession extends EventEmitter // Audio and/or video requested, prompt getUserMedia. else if (mediaConstraints.audio || mediaConstraints.video) { + if ( ! navigator.mediaDevices ) + { + const error = new Error('Media inaccessible; Secure context required (eg. https://, file://)'); + + //this._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); + //this.emit('getusermediafailed', error); + throw error; + } this._localMediaStreamLocallyGenerated = true; return navigator.mediaDevices.getUserMedia(mediaConstraints) @@ -793,12 +801,12 @@ module.exports = class RTCSession extends EventEmitter }) .catch((error) => { + logger.warn(`getUserMedia error: ${JSON.stringify(error)}`); if (this._status === C.STATUS_TERMINATED) { return; } - - logger.warn(error); + throw error; }); } @@ -2630,11 +2638,28 @@ module.exports = class RTCSession extends EventEmitter // Request for user media access. else if (mediaConstraints.audio || mediaConstraints.video) { + if ( ! navigator.mediaDevices ) + { + const error = new Error('Media inaccessible; Secure context required (eg. https://, file://)'); + + //this._failed('local', null, JsSIP_C.causes.USER_DENIED_MEDIA_ACCESS); + //this.emit('getusermediafailed', error); + throw error; + } this._localMediaStreamLocallyGenerated = true; + logger.warn(`getUserMedia requesting ${JSON.stringify( mediaConstraints )} from ${JSON.stringify( navigator.mediaDevices )}`); + return navigator.mediaDevices.getUserMedia(mediaConstraints) + .then((stream) => + { + logger.warn(`getUserMedia gives ${JSON.stringify( stream )}`); + + return stream; + }) .catch((error) => { + logger.warn(`getUserMedia error ${JSON.stringify( error )}`); if (this._status === C.STATUS_TERMINATED) { throw new Error('terminated'); @@ -2652,6 +2677,7 @@ module.exports = class RTCSession extends EventEmitter }) .then((stream) => { + logger.warn(`getUserMedia returned stream ${JSON.stringify( stream )}`); if (this._status === C.STATUS_TERMINATED) { throw new Error('terminated'); @@ -2699,12 +2725,12 @@ module.exports = class RTCSession extends EventEmitter }) .catch((error) => { + logger.warn(`getUserMedia error: ${JSON.stringify(error)}`); if (this._status === C.STATUS_TERMINATED) { return; } - - logger.warn(error); + throw error; }); }