0

So I've built in to a solution a very basic TAPI function that makes a phone call to a given number. I'm not particularly strong with TAPI code, and was wondering if there is any way to record a phone call length using the c# functions? My initial thought was if there is a call started and call ended watch event, I could start and end a timer respectively, but documentation seems thin on the ice.

Does anybody know if this is possible, and if so, how?

Thanks,

Ryan

Current Code:

Global Variables:

TAPI3Lib.ITAddress line;

Form initialisation code:

 public Outbound()
    {
        InitializeComponent();
        #region TAPI Initialize
        TAPIClass tapi = new TAPIClass();
        tapi.Initialize();
        foreach (TAPI3Lib.ITAddress ad in (tapi.Addresses as TAPI3Lib.ITCollection))
        {
            line = ad;
        }
        tapi.EventFilter = (int)(TAPI_EVENT.TE_CALLNOTIFICATION | //All events you could need, probably
        TAPI3Lib.TAPI_EVENT.TE_CALLINFOCHANGE |
        TAPI3Lib.TAPI_EVENT.TE_DIGITEVENT |
        TAPI3Lib.TAPI_EVENT.TE_PHONEEVENT |
        TAPI3Lib.TAPI_EVENT.TE_CALLSTATE |
        TAPI3Lib.TAPI_EVENT.TE_GENERATEEVENT |
        TAPI3Lib.TAPI_EVENT.TE_GATHERDIGITS |
        TAPI3Lib.TAPI_EVENT.TE_REQUEST);
        tapi.ITTAPIEventNotification_Event_Event += new TAPI3Lib.ITTAPIEventNotification_EventEventHandler(tapi_ITTAPIEventNotification_Event_Event);
        #endregion
    }

TAPI Functions:

        private void btncall_Click(object sender, EventArgs e)
    {
        if (line == null) return;
        TAPI3Lib.ITBasicCallControl bc = line.CreateCall(txttelephone.Text, TAPI3Lib.TapiConstants.LINEADDRESSTYPE_PHONENUMBER, TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO);
        bc.Connect(false);
    }

    private void tapi_ITTAPIEventNotification_Event_Event(TAPI_EVENT TapiEvent, object pEvent)
    {
        try
        {
            switch (TapiEvent)
            {
                case TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION:
                    TAPI3Lib.ITCallNotificationEvent cn = pEvent as TAPI3Lib.ITCallNotificationEvent;
                    if (cn.Call.CallState == TAPI3Lib.CALL_STATE.CS_OFFERING)
                    {
                        string c = cn.Call.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER);
                    }
                    break;
            }
        }
        catch (Exception ex)
        {
        }
    }
Ryan Hargreaves
  • 267
  • 3
  • 16

1 Answers1

0

SOLVED: So I did some digging on the documentation I found a way. There is an event called TAPI3Lib.TAPI_EVENT.TE_CALLSTATE that, if you attach to a watcher, can track if the call state changes. So, for me, this activated when a phone call started and a phone call ended. All I have to do is control a timer with a flag in here and ill get a phone call length.

Ryan Hargreaves
  • 267
  • 3
  • 16