While waiting for browsers to actually support this, I patched the library to close the peer connection and start a new one when a re-invite is sent/received and media has changed. It's working surprisingly well and only creates annoying permissions dialogs if you aren't using HTTPS, which you should be using in production anyways.
(all of this code is from 0.7.0, I haven't seen what 0.7.1 changed)
First, you'll likely want to let the app know a re-invite was received so it can create/destroy video elements. Inside receiveRequest add an event emission here:
case SIP.C.INVITE:
if(this.status === C.STATUS_CONFIRMED) {
this.emit('reinvite', request); //****alert app that a reinvite has been received
this.logger.log('re-INVITE received');
// Switch these two lines to try re-INVITEs:
this.receiveReinvite(request);
// request.reply(488, null, ['Warning: 399 sipjs "Cannot update media description"']);
}
Next, my receiveReinvite function has this added (text above and below provided for context):
if (request.getHeader('Content-Type') !== 'application/sdp') {
this.logger.warn('invalid Content-Type');
request.reply(415);
return;
}
//******close peerconnection and start a new one if media has changed
if( request.getHeader('Subject') === 'Media change'){
this.mediaHandler.close();
this.mediaHint.constraints.video = /(m=video)/.test(request.body);
this.mediaHandler = this.mediaHandlerFactory(this, {
RTCConstraints: {"optional": [{'DtlsSrtpKeyAgreement': 'true'}]}
});
}
//************
this.mediaHandler.setDescription(request.body)
-------
Lastly, my sendReinvite has this added:
this.receiveResponse = this.receiveReinviteResponse;
//*****check if media has changed on call
if( options.video !== this.mediaHint.constraints.video ){
extraHeaders.push('Subject: Media change');
this.mediaHandler.close();
this.mediaHint.constraints.video = options.video;
this.mediaHandler = this.mediaHandlerFactory(this, {
RTCConstraints: {"optional": [{'DtlsSrtpKeyAgreement': 'true'}]}
});
}
//*******
//REVISIT
this.mediaHandler.getDescription(self.mediaHint)
--------
That said, I'd love to know if there's a better way of doing this and if you (or anyone) has been successful in getting actual renegotiations working.
Best,
Kyle