private void _btnStartStop_Click(object sender, EventArgs e) { if (!_isStarted) { var ipEndPoint = SipUtil.ParseIpEndPoint(Configuration.BindIpEndPoint); var outboundProxy = SipUtil.ParseIpEndPoint(Configuration.OutboundProxyIpEndPoint); SipStack = new SipStack(); var listeningPoint = SipStack.CreateUdpListeningPoint(ipEndPoint); SipStack.MaxWorkerThreads = Configuration.MaxThreadPoolSize; SipStack.MinWorkerThreads = Configuration.MinThreadPoolSize; SipStack.OutBoundProxy = outboundProxy; SipStack.EnableThreadPoolPerformanceCounters = Configuration.EnableThreadPoolPerformanceCounters; //SipStack.IsStateFull = Configuration.IsStateFull; SipProvider = (SipProvider)SipStack.CreateSipProvider(listeningPoint); MainSipListener = new SipPipeLineListener(this); SipProvider.AddSipListener(MainSipListener); SipProvider.AddExceptionHandler(this); SipProvider.Start(); HeaderFactory = SipStack.CreateHeaderFactory(); MessageFactory = SipStack.CreateMessageFactory(); AddressFactory = SipStack.CreateAddressFactory(); ExecuteActionHelper.ExecuteAction(delegate() { FormsManager.OpenForm(typeof(LogForm), null); }); _lblIpAddress.Text = string.Format("IP:{0}", ipEndPoint.ToString()); } else { SipProvider.Stop(); } _isStarted = !_isStarted; _btnStartStop.Text = _isStarted ? "Stop" : "Start"; _grbNavigation.Enabled = _isStarted; }
protected SipRequest CreateRequest(string method) { /*create the 'INVITE' message*/ SipAddressFactory addressFactory = _stack.CreateAddressFactory(); SipHeaderFactory headerFactory = _stack.CreateHeaderFactory(); SipMessageFactory messageFactory = _stack.CreateMessageFactory(); SipUri senderSipUri = addressFactory.CreateUri(string.Empty, new IPEndPoint(_ipAddress, 12345).ToString()); SipAddress senderSipAddress = addressFactory.CreateAddress(string.Empty, senderSipUri); SipUri receiverSipUri = addressFactory.CreateUri(string.Empty, new IPEndPoint(_ipAddress, 23456).ToString()); SipAddress receiverSipAddress = addressFactory.CreateAddress(string.Empty, senderSipUri); SipToHeader toHeader = headerFactory.CreateToHeader(receiverSipAddress); SipFromHeader fromHeader = headerFactory.CreateFromHeader(senderSipAddress, SipUtil.CreateTag()); SipCSeqHeader cseqHeader = headerFactory.CreateSCeqHeader(method, 1); SipCallIdHeader callIdheader = headerFactory.CreateCallIdHeader(SipUtil.CreateCallId()); SipViaHeader viaHeader = headerFactory.CreateViaHeader(_ipAddress, 12345, SipConstants.Udp, SipUtil.CreateBranch()); SipMaxForwardsHeader maxForwardsHeader = headerFactory.CreateMaxForwardsHeader(); SipRequest request = messageFactory.CreateRequest( receiverSipUri, method, callIdheader, cseqHeader, fromHeader, toHeader, viaHeader, maxForwardsHeader); if (method == SipMethods.Invite) { SipContactHeader contactHeader = headerFactory.CreateContactHeader(senderSipUri); request.Contacts.Add(contactHeader); } return(request); }
public static ISoftPhone CreateSoftPhone(IPEndPoint listeningPoint) { var sipStack = new SipStack(); var sipListeningPoint = sipStack.CreateUdpListeningPoint(listeningPoint); var provider = sipStack.CreateSipProvider(sipListeningPoint); return(new SoftPhone(provider, sipStack.CreateMessageFactory(), sipStack.CreateHeaderFactory(), sipStack.CreateAddressFactory(), new SoftPhoneStateProvider(), new TimerFactory(), sipListeningPoint)); }