Ozeki Bulk Messenger
Quick Start
Online manual
Product Information
Command line caller
Config steps
Source code
Address book
Authentication providers
How to use custom data in outgoing messages
Ozeki Cluster
Developer tools
Ozeki 10

Ozeki Bulk Messenger
Config steps Config steps | Address book Address book

Source code explanation for using Ozeki Command Line Caller example

This page is entitled to be a source code explanation page that explains the main parts of the source code for using Ozeki Command Line Caller example.

Ozeki Command Line Caller example can be obtained by
opening the download page:
Download Ozeki Command Line Caller example!

In this example, a command line application is used to demonstrate how to attach the MP3 playback to your phone call.

At the beginning of the Main method, the sample program is initializing the default values.

  static void Main(string[] args)
			displayName = "CommandLineCaller";
			domainServerPort = 5060;
			registerPassword = string.Empty;
			registrationRequired = false;
			localAddress = SoftPhoneFactory.GetLocalIP().ToString();
			mp3FilePath = "..\\..\\Resources\\test.mp3";
					. . .

The next step is parsing the command line arguments. The ParseArgs() method returns true if the arguments are valid, and returns false if arguments are missing or they are misconfigured.

If the parsing of the arguments are failed, the command line help is printed out.


Next try to open the .mp3 file. If an error occurs, the occurred exception is catched.

                mp3StreamPlayback = new MP3StreamPlayback(mp3FilePath);
            catch (Exception ex)

A new instance of the phoneCallMediaSender and the MediaConnector class is created and the mp3StreamPlayback is connected to the phoneCallMediaSender via the Connect() method.

            phoneCallMediaSender = new PhoneCallMediaSender();
            mediaConnector = new MediaConnector();
            mediaConnector.Connect(mp3StreamPlayback, phoneCallMediaSender);

A softPhone and a phoneLine are created based on the predefined values and the command line arguments.

softPhone = SoftPhoneFactory.CreateSoftPhone(localAddress, 5000, 5100, 5060);
phoneLine = softPhone.CreatePhoneLine(new SIPAccount(registrationRequired, displayName, userName, registerName,
                                                         registerPassword, domainServerHost, domainServerPort));

These lines create a new event handler for the event when the state of the phone line is changed. This event handler is the phoneLine_PhoneLineStateChanged. After this, the phone line is registered.

 phoneLine.PhoneLineStateChanged += phoneLine_PhoneLineStateChanged;

Now let's see the phoneLine_PhoneLineStateChanged event handler:
First, the state of the phone line is written into the console. Then the phone line state is checked: If no registration is needed or the phone line is successfully registered, the CreateCall() method is invoked.

        static void phoneLine_PhoneLineStateChanged(object sender, VoIPEventArgs<PhoneLineState> e)
            Console.WriteLine("Phone line state has changed to {0}.", e.Item);
            if (e.Item == PhoneLineState.NoRegNeeded || e.Item == PhoneLineState.RegistrationSucceded)

The source code of the CreateCall method:
A call object is created based on the phone line and the number to dial. A new event handler is created for handling the call state change and the occurred errors. Then, the phoneCallMediaSender object is attached to the phoneCall object. Finally, the call is started.

        static void CreateCall()
            if (phoneCall != null)
            Console.WriteLine("Creating new call ...");
            phoneCall = softPhone.CreateCallObject(phoneLine, dialNumber);
            phoneCall.CallErrorOccured += phoneCall_CallErrorOccured;
            phoneCall.CallStateChanged += phoneCall_CallStateChanged;

The source code of the phoneCall_CallStateChanged event handler:
The state of the call is written into the console. Next, the status of the call is checked. If the callstate is InCall, the MP3 file is played for the called party by invoking the mp3StreamPlayback.StartStreaming() method.

        static void phoneCall_CallStateChanged(object sender, VoIPEventArgs e)
            Console.WriteLine("Call state has changed to {0}", e.Item);
            if (e.Item == CallState.InCall)

Copyright © 2000- - Ozeki Informatics Ltd. | | Tel: +36 1 371 0150
Home > Products > Ozeki Bulk Messenger > Online manual > Command line caller > Source code
Page: 1205 | Login