如何使用Lync SDK启动视频调用



我的目标:我想从一开始就启动视频调用。

我的问题:它被启动到音频呼叫中,然后在最终用户回答呼叫之后,它将变成视频。

void ConversationManager_ConversationAdded_Video(object sender, ConversationManagerEventArgs e)
{
    Console.WriteLine("Inside  conversation added for Video");
    if (e.Conversation.Modalities[ModalityTypes.AudioVideo].State != ModalityState.Notified)
    {
        if (e.Conversation.CanInvoke(ConversationAction.AddParticipant))
        {
            try
            {
                e.Conversation.ParticipantAdded += Conversation_ParticipantAdded_Video;
                e.Conversation.AddParticipant(client.ContactManager.GetContactByUri(receipient));
            }
            catch (ItemAlreadyExistException ex)
            {
            }
        }
    }
}
void Conversation_ParticipantAdded_Video(object source, ParticipantCollectionChangedEventArgs data)
{
    if (data.Participant.IsSelf != true)
    {
        if (((Conversation)source).Modalities[ModalityTypes.AudioVideo].CanInvoke(ModalityAction.Connect))
        {
            object[] asyncState = { ((Conversation)source).Modalities[ModalityTypes.AudioVideo], "CONNECT" };
            try
            {
                ((Conversation)source).Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += _AVModality_ModalityStateChanged_Video;
                Console.WriteLine("entered video Satheesh participant added");
               // ((Conversation)source).Modalities[ModalityTypes.AudioVideo].BeginConnect(ModalityCallback, asyncState);
                ((Conversation)source).Modalities[ModalityTypes.AudioVideo].BeginConnect(ModalityCallback, asyncState);
                //((Conversation)source).Modalities[ModalityTypes.AudioVideo].EndConnect(ModalityCallback, asyncState);
                Thread.Sleep(6000);
                Console.WriteLine(source);

                Console.WriteLine("entered video participant added");
            }
            catch (LyncClientException lce)
            {
                throw new Exception("Lync Platform Exception on BeginConnect: " + lce.Message);
            }
        }
    }
}

public void ModalityCallback(IAsyncResult ar)
{
    Object[] asyncState = (Object[])ar.AsyncState;
    try
    {
        if (ar.IsCompleted == true)
        {
            if (asyncState[1].ToString() == "RETRIEVE")
            {
                ((AVModality)asyncState[0]).EndRetrieve(ar);
            }
            if (asyncState[1].ToString() == "HOLD")
            {
                ((AVModality)asyncState[0]).EndHold(ar);
            }
            if (asyncState[1].ToString() == "CONNECT")
            {
                Console.WriteLine("inside connect method CONNECT");
                ((AVModality)asyncState[0]).EndConnect(ar);
            }
            if (asyncState[1].ToString() == "FORWARD")
            {
                ((AVModality)asyncState[0]).EndForward(ar);
            }
            if (asyncState[1].ToString() == "ACCEPT")
            {
                ((AVModality)asyncState[0]).Accept();
            }
        }
    }
    catch (LyncClientException)
    { }
}
public void _AVModality_ModalityStateChanged_Video(object sender, ModalityStateChangedEventArgs e)
{
    Console.WriteLine(sender);
    Console.WriteLine("entered video modality changed");
    switch (e.NewState)
    {
        case ModalityState.Connected:
            if (_VideoChannel == null)
            {
                _VideoChannel = ((AVModality)sender).VideoChannel;
                _VideoChannel.StateChanged += new EventHandler<ChannelStateChangedEventArgs>(_VideoChannel_StateChanged);
            }
            if (_VideoChannel.CanInvoke(ChannelAction.Start))
            {
                Console.WriteLine("entered video modality changed123");
                _VideoChannel.BeginStart(MediaChannelCallback, _VideoChannel);
            }
            break;
        case ModalityState.OnHold:
            break;
        case ModalityState.Connecting:
        case ModalityState.Forwarding:
            break;
        case ModalityState.Transferring:
            break;
    }
}
private void MediaChannelCallback(IAsyncResult ar)
{
    ((VideoChannel)ar.AsyncState).EndStart(ar);
}

我认为这是因为您在参与者中调用_avmodality_modalitystatechanged_video。

这意味着当您致电的人(新参与者)加入对话时,您可以启动视频。这就是为什么它被启动到音频通话中,然后在最终用户接听电话后变成视频。

解决方案是开发一个新事件: ConvertyStateChangedEvent

这是我做的,而且工作正常:

/// <summary>
/// Handles event raised when New meetNow window change it's state 
/// </summary>
private void _NewMeetNowConversation_StateChanged(object sender, ConversationStateChangedEventArgs e)
{
    Conversation conference = (Conversation)sender;
    switch(e.NewState)
    {
        case ConversationState.Active:
            conference.Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += AVConferenceModalityStateChanged;
            conference.ParticipantAdded += ConfParticipantAdded;
            break;
        case ConversationState.Terminated:      //conversation window completely closed
            break;
        case ConversationState.Inactive:   
            break;
        case ConversationState.Parked:
            break;
        case ConversationState.Invalid:
            break;
    }
}

相关内容

  • 没有找到相关文章

最新更新