Streams : Create a stream with a selected resolution and use it for the call establishment

Here is a description of the different steps to create a stream with a defined resolution and to use it during a peer to peer call.

Create the stream with a selected resolution

Use constraints parameter on createStreamOptions to set the resolution to use :

        var createStreamOptions = {};
        createStreamOptions.constraints = {
            audio: true,
            video: {
                width: {min: 320, ideal: 1920, max: 1920},
                height: {min: 240, ideal: 1080, max: 1080}
            }
        };
        ua.createStream(createStreamOptions)
            .then(function (stream) {
                // Stream is available
                [...]
                localStream = stream;
            })
            .catch(function (err) {
                console.error('create stream error', err);
             });
    

Use your stream during call :

Use your stream when establishing a call :

        call = contact.call(localStream)
            .on('accepted', function () {
                // Display hangup button
                document.getElementById('hangup').style.display = 'inline-block';
            })
            .on('declined', function () {
                console.warn('User has declined your call invitation');
            });
    

Use your stream when accepting an incoming call :

        invitation.accept(localStream)
            .then(function (inCall) {
                call = inCall;
                setCallListeners();
            });
    

Live Demo