示例#1
0
        public RtspResponse Send(RtspRequest request, TimeSpan timeout)
        {
            AsyncResponse asyncRes = null;

            try
            {
                if (_authResponse != null && _credentials != null)
                {
                    // Set the authorization header if we have a cached auth response.
                    request.Authorization = _authResponse.Generate(request.Method, request.URI);
                }

                asyncRes = DoSend(request);
                RtspResponse response = asyncRes.Get(timeout);

                var status = response.ResponseStatus;
                if (status.Is(RtspResponse.Status.Unauthorized) && _credentials != null)
                {
                    _authResponse = AuthChallenge.Parse(_credentials, response.WWWAuthenticate);

                    if (_authResponse != null)
                    {
                        LOG.Warn($"Received RTSP Unauthorized response re-trying with creds {_credentials.Username}:{_credentials.Password}");

                        request.Authorization = _authResponse.Generate(request.Method, request.URI);
                        asyncRes = DoSend(request);
                        response = asyncRes.Get(timeout);
                    }
                }

                return(response);
            }
            catch (Exception e)
            {
                if (asyncRes != null)
                {
                    RemoveCallback(asyncRes.CSeq);
                }

                throw e;
            }
        }
示例#2
0
        /// <summary>
        /// Asynchronously sends RTSP request.  Invokes callback if a response is received
        /// from the server.
        /// </summary>
        /// <param name="request">The request to send</param>
        /// <param name="callback">Callback to be called when a response is available</param>
        public void SendAsync(RtspRequest request, RtspResponseCallback callback)
        {
            AsyncResponse asyncRes = null;

            try
            {
                if (_authResponse != null && _credentials != null)
                {
                    // Set the authorization header if we have a cached auth response.
                    request.Authorization = _authResponse.Generate(request.Method, request.URI);
                }

                asyncRes = DoSend(request, (res) =>
                {
                    var status = res.ResponseStatus;
                    if (status.Is(RtspResponse.Status.Unauthorized) && _credentials != null)
                    {
                        _authResponse = AuthChallenge.Parse(_credentials, res.WWWAuthenticate);

                        if (_authResponse != null)
                        {
                            LOG.Warn($"Received RTSP Unauthorized response re-trying with creds {_credentials.Username}:{_credentials.Password}");

                            request.Authorization = _authResponse.Generate(request.Method, request.URI);
                            asyncRes = DoSend(request, callback);
                        }
                    }
                    else
                    {
                        callback.Invoke(res);
                    }
                });
            }
            catch (Exception e)
            {
                if (asyncRes != null)
                {
                    RemoveCallback(asyncRes.CSeq);
                }
                throw e;
            }
        }