Пример #1
0
        public void Fill(InviteMessage invite)
        {
            var isup = new IsupInitialAddress();

            invite.IsupData = isup;
            isup.NatureOfConnectionIndicator.EchoControlIncluded = false;
            isup.NatureOfConnectionIndicator.SatelliteIndicator  = NatureOfConnection.SatelliteIndicatorFlags.One;
            isup.ForwardCallIndicator.LoadParameterData(new byte[] { 0x20, 0x01 });
            isup.CallingPartyCategory.LoadParameterData(new byte[] { 0xe0 });

            isup.CalledNumber.Number = new string(invite.To.Address.TakeWhile(a => a != '@').ToArray());

            isup.CalledNumber.NumberingFlags = NAIFlags.RoutingNotAllowed | NAIFlags.Isdn;
            isup.CalledNumber.Flags          = PhoneFlags.NAINationalNumber;

            var callingNumber = invite.IsupData.AddOptionalParameter(new IsupPhoneNumberParameter(IsupParameterType.CallingPartyNumber)
            {
                Number = invite.From.Address.Split('@').FirstOrDefault()
            });

            callingNumber.NumberingFlags |= NAIFlags.ScreeningVerifiedAndPassed | NAIFlags.NetworProvided;

            if (this.OriginalCalledNumber != null)
            {
                isup.AddOptionalParameter(IsupParameter.OriginalCalledNumber(this.OriginalCalledNumber, callingNumber.Flags));

                isup.AddOptionalParameter(IsupParameter.RedirectingNumber(this.OriginalCalledNumber, callingNumber.Flags));

                isup.AddRedirInfo();
            }
        }
Пример #2
0
        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);
        }