How to reject incoming call with Ozeki VoIP SIP SDK using C#?
Download: | reject-incoming-call.zip |
This example demonstrates how to reject incoming calls via softphone, in other words;
how to respond to INVITE SIP request to reject the call. To fully understand this article,
you might have to study the
How to register to a SIP PBX chapter and the
How to ring a SIP extension chapter first.
To use this example, you need to have Ozeki VoIP SIP SDK installed,
and a reference to ozeki.dll should be added to your visual studio project.
How to respond to SIP INVITE request to reject the call?
Most of the softphones are able to get notified about incoming calls, which means they can receive the SIP INVITE message. When the phone is ringing, a 180 Ringing SIP message indicates that the INVITE request has successfully arrived, and a decision is about to be made about that.
The INVITE SIP request indicates a client is being invited to participate in a call session. When the INVITE SIP message arrives, the softphone has several options to respond: accept the call, reject the call, forward the call etc. In this example the softphone will reject the call, which means a 486 BUSY HERE SIP message is being set back to indicate that the call has been rejected.
The learn more about the INVITE SIP message and how to implement it, please visit the How to ring a SIP extension chapter.
How to reject incoming call using C#?
Using Ozeki VoIP SIP SDK, softphones are able to get notified when there is an incoming call,
by subscribing to the IncomingCall event of the softphone object. When the event occurs,
the call can be rejected.
By calling the call object's Reject() method, the call is being rejected and the SIP 486 BUSY HERE
message is being sent back, to the caller.
You can even create reject app, which would use a call reject list for the purpose to reject calls
from specified numbers.
Call reject example in C#
using System; using Ozeki.VoIP; namespace Reject_Incoming_Call { class Program { static ISoftPhone softphone; // softphone object static IPhoneLine phoneLine; // phoneline object static IPhoneCall call; private static void Main(string[] args) { // Create a softphone object with RTP port range 5000-10000 softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000); // SIP account registration data, (supplied by your VoIP service provider) var registrationRequired = true; var userName = "858"; var displayName = "858"; var authenticationId = "858"; var registerPassword = "858"; var domainHost = "192.168.115.100"; var domainPort = 5060; var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort); // Send SIP regitration request RegisterAccount(account); // Prevents the termination of the application Console.ReadLine(); } static void RegisterAccount(SIPAccount account) { try { phoneLine = softphone.CreatePhoneLine(account); phoneLine.RegistrationStateChanged += line_RegStateChanged; softphone.IncomingCall += softphone_IncomingCall; softphone.RegisterPhoneLine(phoneLine); } catch (Exception ex) { Console.WriteLine("Error during SIP registration: " + ex); } } static void line_RegStateChanged(object sender, RegistrationStateChangedArgs e) { if (e.State == RegState.NotRegistered || e.State == RegState.Error) Console.WriteLine("Registration failed!"); if (e.State == RegState.RegistrationSucceeded) Console.WriteLine("Registration succeeded - Online!"); } static void softphone_IncomingCall(object sender, VoIPEventArgs<IPhoneCall> e) { call = e.Item; call.Reject(); } } }
Communication through the network
When the INVITE sip message arrives to the softphone, it can decide how to react to it. When the call is being rejected, the sip message 486 Busy here is being sent back as an answer sip message, to the caller via PBX.
Step 1: Invite request arrives from caller via PBX (UDP message, PBX -> Softphone)
INVITE sip:1001@192.168.115.149:5060 SIP/2.0 Via: SIP/2.0/UDP 192.168.115.149:5060;branch=z9hG4bK7725f5b3-0d85-456c-8056- 2dd6a45bb13b;rport To: "1001"<sip:1001@192.168.115.149:5060> From: "1002"<sip:1002@192.168.115.149:5060>;tag=irqayimj CSeq: 1 INVITE Call-ID: edtcxswbjhfkuqjuyxnuoqgixijihqidgrfgateyuwhpmhftgt Max-Forwards: 70 Contact: <sip:1002@192.168.115.149:5060> User-Agent: Ozeki Phone System XE v5.2.1 Content-Type: application/sdp Content-Length: 292 Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REGISTER, SUBSCRIBE, NOTIFY, REFER, INFO, MESSAGE v=0 o=- 763177212 429111000 IN IP4 192.168.115.149 s=Ozeki Call c=IN IP4 192.168.115.149 t=0 0 m=audio 8653 RTP/AVP 8 0 3 101 9 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:3 GSM/8000 a=rtpmap:101 telephone-event/8000 a=rtpmap:9 G722/8000 a=fmtp:9 bitrate=64000 a=sendrecv
Step 2: Reply status message to indicate that the softphone is trying to be ringed (UDP message, Softphone -> PBX)
SIP/2.0 100 Trying Via: SIP/2.0/UDP 192.168.115.149:5060;branch=z9hG4bK7725f5b3-0d85-456c-8056- 2dd6a45bb13b;rport=5060; received=192.168.115.149 From: "1002"<sip:1002@192.168.115.149:5060>;tag=irqayimj Call-ID: edtcxswbjhfkuqjuyxnuoqgixijihqidgrfgateyuwhpmhftgt CSeq: 1 INVITE To: "1001"<sip:1001@192.168.115.149:5060> User-Agent: Ozeki VoIP SIP SDK v10.1.8 Content-Length: 0
Step 3: The called softphone rejects the call, which means a 486 busy here sip reply (UDP message, Softphone -> PBX)
SIP/2.0 486 Busy Here Via: SIP/2.0/UDP 192.168.115.149:5060;branch=z9hG4bK7725f5b3-0d85-456c-8056- 2dd6a45bb13b;rport=5060; received=192.168.115.149 From: "1002"<sip:1002@192.168.115.149:5060>;tag=irqayimj Call-ID: edtcxswbjhfkuqjuyxnuoqgixijihqidgrfgateyuwhpmhftgt CSeq: 1 INVITE To: "1001"<sip:1001@192.168.115.149:5060>;tag=hqihanei User-Agent: Ozeki VoIP SIP SDK v10.1.8 Content-Length: 0 Warning: 399 ozsdk "User reject"
Step 4: Acknowledgement of call rejection via the PBX (UDP message, Softphone -> Softphone)
ACK sip:1001@192.168.115.149:5060 SIP/2.0 Via: SIP/2.0/UDP 192.168.115.149:5060;branch=z9hG4bK7725f5b3-0d85-456c-8056- 2dd6a45bb13b;rport Call-ID: edtcxswbjhfkuqjuyxnuoqgixijihqidgrfgateyuwhpmhftgt From: "1002"<sip:1002@192.168.115.149:5060>;tag=irqayimj To: "1001"<sip:1001@192.168.115.149:5060>;tag=hqihanei CSeq: 1 ACK Max-Forwards: 70 Content-Length: 0
Related Pages
More information
- How to build a softphone voip sip client
- Register to SIP PBX
- Voip softphone development
- How to encrypt voip sip calls with sip encryption
- How to encrypt voip sip calls with rtp encryption
- How to ring a sip extension csharp example for sip invite
- How to make a sip voice call using csharp
- Voip multiple phone lines
- How to send stream of voice data into call using csharp microphone
- How to receive voice from SIP voice call using csharp speaker
- How to make conference voice call using voip sip
- How to play an mp3 file into a voice call using csharp
- How to convert text to speech and play that into a call using csharp
- How to use Microsoft Speech Platform 11 for TTS and STT
- How to record voip sip voice call
- How to accept incoming call using csharp
- How to reject incoming call using csharp
- How to read Headset buttons using Bluetooth
- How to implement auto answer using csharp
- How to recognize incoming voice using speech to text conversion
- Voip forward call
- Voip blind transfer
- Voip attended transfer
- Voip do not disturb
- Voip call hold
- SIP Message Waiting Indication
- Voip DTMF signaling
- How to work with sip and sdp in voip sip calls
- How to work with rtp in voip sip calls
- How to make voip video calls in csharp
- Voip video codec
- Shows how to use SpeechToText Google API
- How to convert Text to Speech using C# and Google
- Azure Text-to-Speech