Reputation: 671
I have an application to log call state and call info into a Database table. I use the interop.TAPI3Lib dll and a TAPI3 driver to connect to the call information.
Below is the parts of the code that I think are relevant
I listen for CallState events
tapi.EventFilter = (int)(TAPI3Lib.TAPI_EVENT.TE_CALLSTATE);
tapi.ITTAPIEventNotification_Event_Event += new
TAPI3Lib.ITTAPIEventNotification_EventEventHandler(tapi_ITTAPIEventNotification_Event_Event);
And register each device (address) I want to monitor
RegEventsResult[line] =
tapi.RegisterCallNotifications(
address,
true,
false,
TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO, 2);
I then log the result of call state changes
private void tapi_ITTAPIEventNotification_Event_Event(TAPI3Lib.TAPI_EVENT TapiEvent, object pEvent)
{
string callerID, group, extension;
long origin;
TAPI3Lib.ITAddress address;
switch (TapiEvent)
{
case TAPI3Lib.TAPI_EVENT.TE_CALLSTATE:
TAPI3Lib.ITCallStateEvent callStateEvent = (TAPI3Lib.ITCallStateEvent)pEvent;
TAPI3Lib.ITCallInfo call = callStateEvent.Call;
extension = call.Address.DialableAddress;
address = call.Address;
switch (call.CallState)
{
case TAPI3Lib.CALL_STATE.CS_INPROGRESS:
callerID = call.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER);
group = call.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLEDIDNAME);
AddLog("InProgress", callerID, group, extension);
break;
case TAPI3Lib.CALL_STATE.CS_CONNECTED:
callerID = call.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER);
group = call.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLEDIDNAME);
AddLog("Connected", callerID, group, extension);
break;
case TAPI3Lib.CALL_STATE.CS_OFFERING:
callerID = call.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER);
group = call.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLEDIDNAME);
AddLog("Offering", callerID, group, extension);
break;
case TAPI3Lib.CALL_STATE.CS_DISCONNECTED:
AddLog("Disconnected", "", "", extension);
resetNotification(extension, address);
break;
case TAPI3Lib.CALL_STATE.CS_IDLE:
AddLog("Idle", "", "", extension);
break;
}
break;
}
}
This works fine - especially as I re-register the device every time it disconnects.
However If the user changes to Hands free on the device - so that calls come through automatically, the call state event does not fire.
If I manually re-register the device during that call, I get a connected call state event.
Any ideas why the device being in hands free would make any difference to the call state event?
Upvotes: 0
Views: 1477
Reputation: 671
I have ended up using TraySoft's AddTapi.Net library, this seems to work very smoothly and is easy to set up and use and documentation is excellent.
And I need to write very little code to achieve the same as above.
Upvotes: 0
Reputation: 255
This "Hands free" mode should not be affecting the events you get. I recommend you use a independent tool to check if other applications get the same result. Because you may have found a bug in your driver or PBX. If you don't have one, you can try the TAPI soft phone here:
Also re-registering after every call should not be necessary and may actually do more harm then good.
Upvotes: 2