SIP.js
SIP.js copied to clipboard
SDH: navigator.mediaDevices.getUserMedia is blocked in background
Is your feature request related to a problem? Please describe. Chrome now blocks the use of navigator.mediaDevices.getUserMedia in the background. So when SDH gets stuck because of this.
Describe the solution you'd like Allow using custom stream in accept
Additional context I can't open PR because my problem is in version 0.14.
Example code solution
/**
* SessionDescriptionHandler options.
* These options are provided to various UserAgent methods (invite() for example)
* and passed through on calls to getDescription() and setDescription().
*/
export interface SessionDescriptionHandlerOptions {
modifiers?: SessionDescriptionHandlerModifiers;
constraints?: { audio: boolean, video: boolean };
streams?: any;
}
Into Web/SessionDescriptionHandler.ts
private acquire(constraints: any, streams?: any): any {
// Default audio & video to true
constraints = this.checkAndDefaultConstraints(constraints);
return new Promise(async (resolve, reject) => {
/*
* Make the call asynchronous, so that ICCs have a chance
* to define callbacks to `userMediaRequest`
*/
this.logger.log("acquiring local media");
this.emit("userMediaRequest", constraints);
if (constraints.audio || constraints.video) {
try {
if (streams) {
this.logger.log("using custom media streams");
} else {
this.logger.log("using navigator.mediaDevices.getUserMedia");
streams = await navigator.mediaDevices.getUserMedia(constraints)
}
this.logger.log(`MediaStream active is ${streams.active}`)
this.observer.trackAdded();
this.emit("userMedia", streams);
resolve(streams);
} catch (e: any) {
this.emit("userMediaFailed", e);
reject(e);
}
} else {
// Local streams were explicitly excluded.
resolve([]);
}
.....
}
Simple use:
invite.accept({
sessionDescriptionHandlerOptions: {
streams: new MediaStream(),
constraints: {
audio: true,
video: false
}
}
})
Please refer to pull request #972 for resolution.