Skip to content

Commit

Permalink
Initial pass at fixing navigator.mediaDevices
Browse files Browse the repository at this point in the history
  • Loading branch information
pjkundert committed Jun 21, 2024
1 parent fff94c5 commit 2cfbc9a
Showing 1 changed file with 30 additions and 4 deletions.
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

0 comments on commit 2cfbc9a

Please sign in to comment.