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

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

by Justin Warner   on Apr 03, 2015   Category: C#   |  Views: 647    |  Points: 25   |  Starter 


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!

--------------------


using System;
using Ozeki.Media;
using Ozeki.VoIP;
using Ozeki.VoIP.SDK;

namespace Conference_Call
{
class Program
{
static ISoftPhone softphone;
static IPhoneLine phoneLine;

static ConferenceRoom conferenceRoom;

private static void Main(string[] args)
{
softphone = SoftPhoneFactory.CreateSoftPhone(5000, 10000);

var registrationRequired = true;
var userName = "715";
var displayName = "715";
var authenticationId = "715";
var registerPassword = "715";
var domainHost = "192.168.115.100";
var domainPort = 5060;

var account = new SIPAccount(registrationRequired, displayName, userName, authenticationId, registerPassword, domainHost, domainPort);

RegisterAccount(account);

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 InitializeConferenceRoom()
{
conferenceRoom = new ConferenceRoom();
conferenceRoom.StartConferencing();
}

static void softphone_IncomingCall(object sender, VoIPEventArgs<IPhoneCall> e)
{
IPhoneCall call = e.Item;
call.CallStateChanged += call_CallStateChanged;
call.Answer();
}

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!");
InitializeConferenceRoom();
}
}

static void call_CallStateChanged(object sender, CallStateChangedArgs e)
{
IPhoneCall call = sender as IPhoneCall;

if (e.State == CallState.Answered)
conferenceRoom.AddToConference(call);
else if (e.State.IsCallEnded())
conferenceRoom.RemoveFromConference(call);
}

}
}



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts