function ChangeDevices()

in WebPortal/Scripts/multivideo.js [380:456]


function ChangeDevices(meetingUri) {
    var stopAudio;
    var changedMicrophone = null, changedSpeaker = null;
    var chosenCameraId = $('#cameras').val();
    var chosenMicId = $('#mics').val();
    var chosenSpeakerId = $('#speakers').val();
    window.skypeWebApp.devicesManager.cameras.get().then(function (list) {
        console.log("get Camera");
        for (var i = 0; i < list.length; i++) {
            var camera = list[i];
            if (camera.id() == chosenCameraId) {
                window.skypeWebApp.devicesManager.selectedCamera.set(camera);
            }
        }
    });

    window.skypeWebApp.devicesManager.microphones.get().then(function (list) {
        console.log("get Mic");
        for (var i = 0; i < list.length; i++) {
            var microphone = list[i];
            if (microphone.id() == chosenMicId) {
                changedMicrophone = microphone;
                stopAduio = true;
                window.skypeWebApp.devicesManager.selectedMicrophone.set(microphone);
            }
        }
    });

    window.skypeWebApp.devicesManager.speakers.get().then(function (list) {
        console.log("get Speaker");
        for (var i = 0; i < list.length; i++) {
            var speaker = list[i];
            if (speaker.id() == chosenSpeakerId) {
                changedSpeaker = speaker;
                stopAudio = true;
                window.skypeWebApp.devicesManager.selectedSpeaker.set(speaker);
            }
        }
    });
    window.skypeWebApp.devicesManager.selectedMicrophone.changed(function (device) {
        console.log("mic changed");
        appInsights.trackEvent("Skype device changed", { type: "microphone" });
        if (stopAudio) {
            var conv = window.skypeWebApp.conversationsManager.getConversationByUri(meetingUri);
            if (conv != null) {
                conv.audioService.stop().then(function () {
                    console.log("audio service stopped and again starting.");
                    conv.audioService.start().then(function () {
                        console.log("audio service started again.");
                        stopAudio = false;
                    });
                });
            }
        }
    });
    window.skypeWebApp.devicesManager.selectedSpeaker.changed(function (device) {
        console.log("speaker changed");
        appInsights.trackEvent("Skype device changed", { type: "speaker" });
        if (stopAudio) {
            var conv = window.skypeWebApp.conversationsManager.getConversationByUri(meetingUri);
            if (conv != null) {
                conv.audioService.stop().then(function () {
                    console.log("audio service stopped and again starting.");
                    conv.audioService.start().then(function () {
                        console.log("audio service started again.");
                        stopAudio = false;
                    });
                });
            }
        }
    });

    window.skypeWebApp.devicesManager.selectedCamera.changed(function (device) {
        console.log("camera changed");
        appInsights.trackEvent("Skype device changed", { type: "camera" });
    });
}