CodAri
CodAri

Reputation: 353

Return new incoming call uri

I'm using this simple code to get incoming call and Uri of caller. If user have multiple Lync sessions open it always return first one because of static index. How I'm able to get new connection index so that I would get proper uri of caller?

    Imports Microsoft.Lync.Model
Imports Microsoft.Lync.Model.Conversation
Imports Lync = Microsoft.Lync.Model.Conversation


Public Class myLync
    Private _LyncClient As LyncClient
    Public WithEvents _ConversationMgr As Microsoft.Lync.Model.Conversation.ConversationManager
    Public WithEvents _conv As Conversation

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            _LyncClient = LyncClient.GetClient()
            _ConversationMgr = _LyncClient.ConversationManager
        Catch ex As Exception
        End Try
 End Sub

 Private Sub _ConversationMgr_ConversationAdded(ByVal sender As Object, ByVal e As Microsoft.Lync.Model.Conversation.ConversationManagerEventArgs) Handles _ConversationMgr.ConversationAdded
        AddHandler e.Conversation.Modalities(ModalityTypes.AudioVideo).ModalityStateChanged, AddressOf AVModalityStateChanged
 End Sub

 Private Sub AVModalityStateChanged(ByVal sender As Object, ByVal e As ModalityStateChangedEventArgs)
        Select Case e.NewState
            Case ModalityState.Notified
                Dim Uri = _ConversationMgr.Conversations.Item(0).Participants.Item(1).Contact.Uri
        End Select
 End Sub

Upvotes: 1

Views: 169

Answers (1)

Paul Hodgson
Paul Hodgson

Reputation: 959

In AVModalityStateChanged(ByVal sender As Object, ByVal e As ModalityStateChangedEventArgs) the sender parameter can be cast to type AVModality from there you can access participant.

Excuse my c# but it would look something like:-

  private void Participant_ModalityStateChanged(object sender, ModalityStateChangedEventArgs e)
    {
        if (e.NewState == ModalityState.Connected)
        {
            var modality = (AVModality) sender;
            var participant = modality.Participant;
            var uri = participant.Contact.Uri;
        }
    }

Upvotes: 1

Related Questions