示例#1
0
        private bool HTTPGetAnswers()
        {
            HttpWebRequest request =
                (HttpWebRequest)WebRequest.Create($"{m_url}/signaling/answer?fromtime={m_lastTimeGetAnswerRequest}");

            request.Method      = "GET";
            request.ContentType = "application/json";
            request.Headers.Add("Session-Id", m_sessionId);
            request.KeepAlive = false;

            HttpWebResponse   response = HTTPGetResponse(request);
            AnswerResDataList list     = HTTPParseJsonResponse <AnswerResDataList>(response);

            if (list == null)
            {
                return(false);
            }

            m_lastTimeGetAnswerRequest = DateTimeExtension.ParseHttpDate(response.Headers[HttpResponseHeader.Date])
                                         .ToJsMilliseconds();

            foreach (var answer in list.answers)
            {
                m_mainThreadContext.Post(d => OnAnswer?.Invoke(this, answer), null);
            }

            return(true);
        }
示例#2
0
        private bool HTTPGetCandidates()
        {
            HttpWebRequest request =
                (HttpWebRequest)WebRequest.Create($"{m_url}/signaling/candidate?fromtime={m_lastTimeGetCandidateRequest}");

            request.Method      = "GET";
            request.ContentType = "application/json";
            request.Headers.Add("Session-Id", m_sessionId);
            request.KeepAlive = false;

            HttpWebResponse response = HTTPGetResponse(request);
            CandidateContainerResDataList containers = HTTPParseJsonResponse <CandidateContainerResDataList>(response);

            if (containers == null)
            {
                return(false);
            }
            m_lastTimeGetCandidateRequest = DateTimeExtension.ParseHttpDate(response.Headers[HttpResponseHeader.Date])
                                            .ToJsMilliseconds();

            foreach (var candidateContainer in containers.candidates)
            {
                foreach (var candidate in candidateContainer.candidates)
                {
                    candidate.connectionId = candidateContainer.connectionId;
                    m_mainThreadContext.Post(d => OnIceCandidate?.Invoke(this, candidate), null);
                }
            }

            return(true);
        }
        private bool HTTPConnect()
        {
            HttpWebRequest request =
                (HttpWebRequest)WebRequest.Create($"{m_url}/signaling/connection");

            request.Method      = "PUT";
            request.ContentType = "application/json";
            request.Headers.Add("Session-Id", m_sessionId);
            request.KeepAlive = false;

            HttpWebResponse         response = HTTPGetResponse(request);
            CreateConnectionResData data     = HTTPParseJsonResponse <CreateConnectionResData>(response);

            if (data == null)
            {
                return(false);
            }

            m_lastTimeGetOfferRequest = DateTimeExtension.ParseHttpDate(response.Headers[HttpResponseHeader.Date])
                                        .ToJsMilliseconds();

            OnCreateConnection?.Invoke(this, data.connectionId);

            return(true);
        }