title: I would like to intercept the MS Teams notifications about poor network quality, during calls
body: <p>In order to diagnose a network condition I am trying to intercept (at least on Windows) the notifications about poor network quality that Teams pops-up sometimes, during a call.
  For testing, I am using &quot;clumsy&quot;, in order to generate iffiness in the network, while in a teams audiovideo call to my phone.
  I was wondering if an API would provide a local interface to teams an allow me to subscribe to those events.</p>
  <p>So far if found a type library in  C:\Users\xxx\AppData\Local\Microsoft\TeamsPresenceAddin\Uc.tlb that looks promising because of the idl file that the oleviewer generates from it:</p>
  <p>ModalityProperty in uc.tlb is an enum and contains these two values:</p>
  <pre><code>ucAVModalityAudioNetworkQuality = 0x300b001d,
  ucAVModalityVideoNetworkQuality = 0x300b0021,
  </code></pre>
  <p>That enum is used by the interface _IAVModalityEvents and that looks to be fired by the coclass AVModality:</p>
  <pre><code>    [
        uuid(BA2BD6F3-7676-42E3-89C6-10CEB3F7E106),
        helpstring(&quot;AVModality class defines the audio video modality.This class handles the events defined in the interface IAVModalityEvents.&quot;),
        noncreatable,
        custom(5047D0E3-86FD-4EB4-A500-AC4F5B4E17E1, &quot;relns=Conversation.AudioVideo&quot;)
      ]
      coclass AVModality {
          [default] interface IAVModality;
          interface IAVModality2;
          **[default, source] dispinterface _IAVModalityEvents;**
      };
  </code></pre>
  <p>Does anyone have an idea on how to connect to the running Teams instance (tried ROT but it doesn't seem to be registered) and how to enum modalities in order to get to the AVModality and subscribe to its events ?</p>
  <p>Update 1:</p>
  <p>I actually got some partial results with the Uc.tlb.
  First I ran: <strong>TlbImp.exe Uc.tlb</strong> to create a C# assembly from it.</p>
  <p>I then built the following C# app to intercept conversation changes:</p>
  <pre><code>using Microsoft.Win32;
  using System;
  using System.Collections.Generic;
  using System.IO;
  using System.Runtime.InteropServices;
  using System.Runtime.InteropServices.ComTypes;
  using System.Xml;
  
  using  UCCollaborationLib;
  
  
  class Program
  {
      //Teams CLSID harvested from registry
      // Take a looksie at: https://stackoverflow.com/questions/56865704/com-object-for-teams-client-microsoft-office-uc
      [ComImport, Guid(&quot;00425F68-FFC1-445F-8EDF-EF78B84BA1C7&quot;)]
      public class TeamsOfficeIntegration
      {
      }
  
      static void Main(string[] args)
      {
          var version = &quot;15.0.0.0&quot;;
          IUCOfficeIntegration teamsOfficeIntegration = (IUCOfficeIntegration) new TeamsOfficeIntegration();
  
          if (teamsOfficeIntegration == null) {
              Console.WriteLine(&quot;Cannot instantiate UCOfficeIntegration for Teams&quot;);
              return;
          }
  
          IClient teamsClient = (IClient) teamsOfficeIntegration.GetInterface(version, OIInterface.oiInterfaceILyncClient);
          if (teamsClient == null) {
              Console.WriteLine(&quot;Cannot retrieve Teams Client interface&quot;);
              return;
          }
  
          var teamsConversationManager = teamsClient.ConversationManager;
          if (teamsConversationManager == null) {
              Console.WriteLine(&quot;Cannot retrieve Teams ConversationManager interface&quot;);
              return;
          }
  
  
          // Handle Teams Conversation Collection events 
          teamsConversationManager.OnConversationAdded += (ConversationManager _eventSource, ConversationManagerEventData _eventData) =&gt; {  Console.WriteLine(&quot;Conversation added&quot;);};
          teamsConversationManager.OnConversationRemoved += (ConversationManager _eventSource, ConversationManagerEventData _eventData) =&gt; {  Console.WriteLine(&quot;Conversation removed&quot;);};
          
          //iterate SelfParticipant or Modalities -&gt; iterate IAVModality -&gt; IConnectionPoint
  
      }
  }
  </code></pre>
  <p>The good news is that, when Teams is stopped it tries to start it so it does CoCreateInstance on the Teams LocalServer so it should be able to interact with it. The bad news is that even if the Teams app starts or is being attached to the creation fails with the following entry in the EventViewer/AdministrativeEvents:</p>
  <p><strong>&quot;The server {00425F68-FFC1-445F-8EDF-EF78B84BA1C7} did not register with DCOM within the required timeout.&quot;</strong></p>