Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial pass at fixing navigator.mediaDevices #862

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions lib/RTCSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
});
}

Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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;
});
}

Expand Down