Пример #1
0
        public SIPRequest GetInviteRequest(string inviteURIStr, string fromURIStr, string body, int rtpPort)
        {
            SIPURI        inviteURI  = (inviteURIStr.StartsWith("sip:")) ? SIPURI.ParseSIPURI(inviteURIStr) : SIPURI.ParseSIPURI("sip:" + inviteURIStr);
            SIPFromHeader fromHeader = SIPFromHeader.ParseFromHeader(fromURIStr); // (fromURIStr.StartsWith("sip:")) ? SIPFromHeader.ParseFromHeader(fromURIStr) : SIPFromHeader.ParseFromHeader("sip:" + fromURIStr);
            SIPToHeader   toHeader   = new SIPToHeader(null, inviteURI, null);

            SIPRequest inviteRequest = new SIPRequest(SIPMethodsEnum.INVITE, inviteURI);

            IPEndPoint localSIPEndPoint = m_sipTransport.GetIPEndPointsList()[0];
            SIPHeader  inviteHeader     = new SIPHeader(fromHeader, toHeader, 1, CallProperties.CreateNewCallId());

            inviteHeader.From.FromTag = CallProperties.CreateNewTag();
            inviteHeader.Contact      = SIPContactHeader.ParseContactHeader("sip:" + localSIPEndPoint.ToString());
            inviteHeader.CSeqMethod   = SIPMethodsEnum.INVITE;
            //inviteHeader.UnknownHeaders.Add("BlueFace-Test: 12324");
            inviteRequest.Header = inviteHeader;

            SIPViaHeader viaHeader = new SIPViaHeader(localSIPEndPoint.Address.ToString(), localSIPEndPoint.Port, CallProperties.CreateBranchId());

            inviteRequest.Header.Via.PushViaHeader(viaHeader);

            rtpPort = (rtpPort != 0) ? rtpPort : Crypto.GetRandomInt(10000, 20000);
            string sessionId = Crypto.GetRandomInt(1000, 5000).ToString();

            if (body != null && body.Trim().Length > 0)
            {
                inviteRequest.Body = body;
            }
            else
            {
                inviteRequest.Body =
                    "v=0" + CRLF +
                    "o=- " + sessionId + " " + sessionId + " IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF +
                    "s=session" + CRLF +
                    "c=IN IP4 " + localSIPEndPoint.Address.ToString() + CRLF +
                    "t=0 0" + CRLF +
                    "m=audio " + rtpPort + " RTP/AVP 0 101" + CRLF +
                    "a=rtpmap:0 PCMU/8000" + CRLF +
                    "a=rtpmap:101 telephone-event/8000" + CRLF +
                    "a=fmtp:101 0-16" + CRLF +
                    "a=sendrecv";
            }

            inviteRequest.Header.ContentLength = inviteRequest.Body.Length;
            inviteRequest.Header.ContentType   = "application/sdp";

            return(inviteRequest);
        }