Ejemplo n.º 1
0
 public void SetRemoteSessionDescription(RTCSessionDescription description, Callback callback)
 {
     if (callback is null)
     {
         throw new ArgumentNullException(nameof(callback));
     }
     MustNotDisposed();
     _peerConnectionImpl.SetRemoteSessionDescription(
         description.Type,
         description.Sdp,
         new Callback().OnSuccess(delegate
     {
         try
         {
             // TODO: move this,
             // AddPeerConnection() should be called right after the peer connection
             // factory returns the newly created PeerConnection.
             //
             // To accomplish this, make sure VideoRouter listens to PeerConnection's track events,
             // because when PeerConnection has just been created, it has no track, however
             // SetRemoteSessionDescription() above adds track after the PeerConnection is added to the router.
             if (Interlocked.CompareExchange(
                     ref _addedToRouterState,
                     (int)AddedToRouterState.Added,
                     (int)AddedToRouterState.NotAdded) == (int)AddedToRouterState.NotAdded)
             {
                 // As per webRTC example, the answerer will SetRemoteSessionDescription() first,
                 // then followed by AddTrack();
                 //
                 // and AddPeerConnectionAsync() will call AddTrack() under the hood,
                 // therefore we call AddPeerConnectionAsync() right after SetRemoteSessionDescription();
                 _videoRouter.AddPeerConnection(Device, this);
             }
             callback.Success();
         }
         catch (Exception ex)
         {
             _logger.Error(ex);
             callback.Error(ex.Message);
         }
     }).OnError(msg => callback.Error(msg)));
 }