function meetingConversationAdded()

in WebPortal/Scripts/multivideo.js [115:238]


function meetingConversationAdded(conversation) {
    console.log("Conversation added!");
    var meetingUri = conversation.uri();

    // Handle conversation disconnections by removing them from memory.
    conversation.state.once("Disconnected", function () {
        console.log("Conversation disconnected. Removing it.");
        $('#loadingText').html("Doctor left the conference");
        hangUp();
    });

    var wasConnected = false;
    conversation.selfParticipant.state.changed(function (state) {
        console.log("self participant state: " + state);
        if (state == "InLobby") {
            appInsights.trackEvent("Skype self-participant conversation state changed", { state: state, participant: conversation.selfParticipant.person.id() });
            wasConnected = true;
            $('#signInStatus').html("In Lobby");
            $('#landingContent').show();
            $('#landingContent').css('height', $(window).height());
            $('#PatientQuestionnaire').css('height', $(window).height() - 70);
            $('#loadingText1').html("We will start your virtual visit soon. Please wait for a health care professional.");
        }
        if (state == 'Connected') {
            startConversationAV(conversation);
            wasConnected = true;
            $('#landingContent').hide();
            $('#allVideoControls').show();

            $('#signInStatus').html("Connected");
            if (conversation.participantsCount() == 0) {
                $('#loadingText').html("Please wait for the doctor to join the meeting.");
            }
            else {
                $('#loadingText').html("The meeting has started. Use the buttons at the bottom to share your video or see video of other participants.");
            }
        }
        else if (state == 'Disconnected' && wasConnected) {
            $('#loadingText').html('The call has been disconnected. Please refresh the page if you need to reconnect.').show();
            $('#allVideoControls').show();
        }
    });

    conversation.selfParticipant.video.state.changed(function (newState) {
        console.log("self participant video state: " + newState);
        appInsights.trackEvent("Skype self-participant video state changed", { state:newState });
        if (newState == 'Notified') {
            $('#signInStatus').html("Notified");
            conversation.videoService.accept();
        }
        if (newState == 'Connected') {
            $('#signInStatus').html("Connected");
            joined = true;
            if (conversation.participantsCount() == 0) {
                $('#loadingText').html("Please wait for the doctor to join the meeting.");
            }
            StartMyVideo();
        }
        if (newState == 'Disconnected') {
            $('#signInStatus').html("Disconnected");
        }
    });

    conversation.participants.added(function (skypeParticipant) {
        console.log("Participant " + skypeParticipant.displayName() + " added");
        skypeParticipant.state.changed(function (state) {
            console.log("participant " + skypeParticipant.displayName() + " state: " + state);
            appInsights.trackEvent("Skype participant state changed", { state: state, participant: skypeParticipant.person.id() });
            if (state == 'InLobby') {
                // TODO: You may want to take special actions here
            }
            if (state == 'Connected') {
                joined = true;
                $('#loadingText').html("The meeting has started. Use the buttons at the bottom to share your video or see video of other participants.");
            }
            if (state == 'Disconnected' && conversation.participantsCount() == 0) {
                if (joined) {
                    $('#loadingText').html("Doctor left the conference");
                }
            }
        });

        skypeParticipant.video.state.changed(onVideoStateChanged);

        function onVideoStateChanged(newState) {
            var channel = skypeParticipant.video.channels(0);
            console.log("participant video state changed for " + skypeParticipant.name() + ": " + newState);
            if (newState == 'Connected') {
                if (conversation.isGroupConversation()) {
                    // subscribe to isVideoOn changes
                    channel.isVideoOn.changed(onIsVideoOnChanged);
                }
            }
        }

        function onIsVideoOnChanged(val) {
            var channel = skypeParticipant.video.channels(0);
            var container = channel.stream.source.sink.container;
            if (val) {
                $('#videoWindow').show();
                // subscribe to remote video
                if (conversation.isGroupConversation() && !channel.isStarted()) {
                    var renderWindow = document.getElementById("video0");
                    renderWindow.innerHTML = '';
                    if (!container()) {
                        // if container is not set, set it and then call
                        // isStarted after that promise returns
                        container.set(renderWindow).then(function () {
                            channel.isStarted(true);
                        });
                    } else {
                        channel.isStarted(true);
                    }
                }
            } else {
                if (conversation.isGroupConversation() && channel.isStarted() && channel.isStarted.set.enabled()) {
                    // unsubscribe to remote video
                    channel.isStarted(false);
                    $('#videoWindow').hide();
                }
            }
        }
    });
}