コード例 #1
0
        private static DialogInfo Configure(string sourceIp, string sourceNumber, string destinationNumber, string destinationIp, string originalCalledNumber)
        {
            var dlg = new DialogInfo
            {
                From           = sourceNumber + "@" + sourceIp,
                To             = destinationNumber + "@" + destinationIp,
                LocalEndpoint  = new IPEndPoint(IPAddress.Parse(sourceIp), 5060),
                RemoteEndpoint = new IPEndPoint(IPAddress.Parse(destinationIp), 5060)
            };

            if (!string.IsNullOrWhiteSpace(originalCalledNumber))
            {
                dlg.OriginalCalledNumber = new Contact(originalCalledNumber);
            }

            return(dlg);
        }
コード例 #2
0
ファイル: Dialog.cs プロジェクト: inrg/sipstack
        public static Dialog InitSipCall(DialogInfo dialogInfo, EventHandler <DialogState> stateChanged = null)
        {
            var dlg    = new Dialog(Guid.NewGuid() + "@" + dialogInfo.LocalEndpoint, dialogInfo.RemoteEndpoint, dialogInfo.LocalEndpoint.Port, stateChanged);
            var invite = new InviteMessage(dlg.CallId, dialogInfo.To, dialogInfo.From, dialogInfo.From);

            dialogInfo.Fill(invite);
            var localEp = dialogInfo.LocalRtpEndpoint ?? dialogInfo.LocalEndpoint;

            localEp = new IPEndPoint(localEp.Address, MediaGateway.GetNextPort());

            // TODO: select which codec will be used based on 183 session progress or prack
            dlg.rtp = new RtpStream(localEp, MediaGateway.CreateMedia(MediaGateway.AudioCodec.G711Alaw));

            var availableCodecs = MediaGateway.GetRegisteredCodecs().Select(MediaCodecDescriptor.Describe).ToList();

            var parameters = availableCodecs.SelectMany(a => a.Parameters).ToList();

            invite.SdpData = new Sdp();
            invite.SdpData.AddParameter("o", string.Format("- {0} 0 IN IP4 {1}", Interlocked.Increment(ref sdpIds), localEp.Address))
            .AddParameter("s", "-")
            .AddParameter("c", string.Format("IN IP4 {0}", localEp.Address))
            .AddParameter("t", "0 0")
            .AddParameter("m", string.Format("audio {0} RTP/AVP {1}", localEp.Port, string.Join(" ", availableCodecs.SelectMany(a => a.Identifiers).OrderBy(a => a))));

            foreach (var kvp in parameters)
            {
                invite.SdpData.AddParameter(kvp.Key, kvp.Value);
            }

            invite.SdpData.AddParameter("a", "sendrecv");

            invite.Headers["Via"]  = string.Format("SIP/2.0/UDP {0}:{2};rport;branch=z9hG4bK7fe{1}", dialogInfo.LocalEndpoint.Address, DateTime.Now.Ticks.ToString("X8").ToLowerInvariant(), dlg.sipPort);
            invite.Headers["CSeq"] = Interlocked.Increment(ref dlg.callSequence) + " INVITE";

            dlg.WaitForMessage(invite, dlg.HandleInviteResponse, 100, 500, 1000, 2000, 5000);

            dlg.Send(invite);
            dlg.stateChanged(dlg, DialogState.Dialing);


            return(dlg);
        }