How to implement conference calling for a SIP softphone in C#?


/ Published in: C#
Save to your folder(s)

A conference call is a meeting, conducted over the phone using audio, between two or more people and usually for the purposes of discussing a particular topic. In my former snippets I dealt with text-to-speech and speech-to-text functionalities. So the implementation of conference calling can sound a little bit strange as compared with my previous tutorials. But I thought it provides a good opportunity for a new challange, so I thought I share my upshot expectedly that it will be useful for you.

A softphone with built-in conference call feature can be greatly used in business communication as well as in companionship. The source code below is ready for use, so you only need to copy&paste it to your Visual Studio, then modify the necessary fields. (Do not forget to add the necessary DLL file providing the VoIP background to your references: http://www.voip-sip-sdk.com)

This program will be a console application that functions as a softphone making conference calling possible. This solution assumes that you have a PBX with some SIP extensions installed previously. After creating the necessary using lines and objects, you need to define your PBX and provide the appropriate SIP account details in order to be able to register your application to the phone system. When you have created all the required methods for SIP calling, you need to initialize the conference room and handle the related events. AddToConference is used to add new party to the conference room and RemoveFromConference is used when the call is ended.

Have a good time!


Copy this code and paste it in your HTML
  1. using System;
  2. using Ozeki.Media;
  3. using Ozeki.VoIP;
  4. using Ozeki.VoIP.SDK;
  5.  
  6. namespace Conference_Call
  7. {
  8. class Program
  9. {
  10. static ISoftPhone softphone;
  11. static IPhoneLine phoneLine;
  12.  
  13. static ConferenceRoom conferenceRoom;
  14.  
  15. private static void Main(string[] args)
  16. {
  17. softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000);
  18.  
  19. var registrationRequired = true;
  20. var userName = "715";
  21. var displayName = "715";
  22. var authenticationId = "715";
  23. var registerPassword = "715";
  24. var domainHost = "192.168.115.100";
  25. var domainPort = 5060;
  26.  
  27. var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort);
  28.  
  29. RegisterAccount(account);
  30.  
  31. Console.ReadLine();
  32. }
  33.  
  34. static void RegisterAccount(SIPAccount account)
  35. {
  36. try
  37. {
  38. phoneLine = softphone.CreatePhoneLine(account);
  39. phoneLine.RegistrationStateChanged += line_RegStateChanged;
  40. softphone.IncomingCall += softphone_IncomingCall;
  41. softphone.RegisterPhoneLine(phoneLine);
  42. }
  43. catch (Exception ex)
  44. {
  45. Console.WriteLine("Error during SIP registration: " + ex);
  46. }
  47. }
  48.  
  49. static void InitializeConferenceRoom()
  50. {
  51. conferenceRoom = new ConferenceRoom();
  52. conferenceRoom.StartConferencing();
  53. }
  54.  
  55. static void softphone_IncomingCall(object sender, VoIPEventArgs<IPhoneCall> e)
  56. {
  57. IPhoneCall call = e.Item;
  58. call.CallStateChanged += call_CallStateChanged;
  59. call.Answer();
  60. }
  61.  
  62. static void line_RegStateChanged(object sender, RegistrationStateChangedArgs e)
  63. {
  64. if (e.State == RegState.NotRegistered || e.State == RegState.Error)
  65. Console.WriteLine("Registration failed!");
  66.  
  67. if (e.State == RegState.RegistrationSucceeded)
  68. {
  69. Console.WriteLine("Registration succeeded - Online!");
  70. InitializeConferenceRoom();
  71. }
  72. }
  73.  
  74. static void call_CallStateChanged(object sender, CallStateChangedArgs e)
  75. {
  76. IPhoneCall call = sender as IPhoneCall;
  77.  
  78. if (e.State == CallState.Answered)
  79. conferenceRoom.AddToConference(call);
  80. else if (e.State.IsCallEnded())
  81. conferenceRoom.RemoveFromConference(call);
  82. }
  83.  
  84. }
  85. }

URL: http://www.voip-sip-sdk.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.