How to make conference call?

This article is about to introduce how to create a softphone which is able to handle multiple incoming calls, and connect them together. To fully understand this guide, you might need to study the How to accept incoming call article first.

client mixed conference call
Figure 1 - Client mixed conference calls

What is client mixed conference call?

Conference calling is a basic requirement for VoIP systems. This is because the spread of voice over IP technology increased the wish for digitizing more advanced communication forms like lectures or conferences.

Conference calls are basically made by using client mixing meaning that all the clients can hear anything any of the other clients tells (Figure 1).

How to implement conference call using C#?

The audio conferencing is supported by a special tool in the Ozeki VoIP SIP SDK called ConferenceRoom. It is a MediaHandler that makes all the background work and you only need to add the calls to it - and remove them, when needed.

All you have to do is to create a ConferenceRoom instance, and call its StartConferencing() method after the phone line has been successfully registered. Since now you have a conference room, when an incoming call occurs and that enters into Answered call state, you have to add the call to the conference room with the AddToConference() method, and if a call ends, you have to remove that with the RemoveFromConference() method.

The example softphone of this guide will only create the conference room for the callers, but you could also communicate them using this softphone through microphone and speaker by using the ConnectSender() and ConnectReceiver() methods.

Client mixed conference call in C#

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

namespace Conference_Call
{
    class Program
    {
        static ISoftPhone softphone;   // softphone object
        static IPhoneLine phoneLine;   // phoneline object

        static ConferenceRoom conferenceRoom;

        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 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);
        }

    }
}

Related Pages

More information