c# - CALL_STATE.CS_OFFERING not works at TAPI programming -


i using tapi programming in order communicate device , send-receive calls. @ moment able make external calls, , "see" calling me when pick phone. reason can't see number @ event < call_state.cs_offering > (when phone rings). post code below (it similar 1 found on internet). appreciated!

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms;  namespace tapisample { public partial class form1 : form {     static public iasyncresult result;     public form1()     {         initializecomponent();          tapi = new tapi3lib.tapiclass();         tapi.initialize();         foreach (tapi3lib.itaddress ad in (tapi.addresses tapi3lib.itcollection))         {             cblines.items.add(ad.addressname);         }          tapi.eventfilter = (int)(tapi3lib.tapi_event.te_callnotification |         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);     }      tapi3lib.tapiclass tapi = null;     tapi3lib.itaddress line = null;     int cn = 0;     private void button1_click(object sender, eventargs e)     {         if (line != null)         {             line = null;             if (cn != 0) tapi.unregisternotifications(cn);         }         foreach (tapi3lib.itaddress ad in (tapi.addresses tapi3lib.itcollection))         {             if (ad.addressname == cblines.text)             {                 line = ad;                 break;             }         }         if (line != null)         {             cn = tapi.registercallnotifications(line, true, true, tapi3lib.tapiconstants.tapimediatype_audio, 2);         }     }      private void form1_formclosed(object sender, formclosedeventargs e)     {         if (cn != 0) tapi.unregisternotifications(cn);     }      delegate void addlogdelegate(string text);     private void addlog(string text)     {         if (this.invokerequired)         {             result = this.begininvoke(new addlogdelegate(addlog), new object[] { text });         }         listbox1.items.insert(0, text);     }      private void tapi_ittapieventnotification_event_event(tapi3lib.tapi_event tapievent, object pevent)     {         try         {             switch (tapievent)             {                 case tapi3lib.tapi_event.te_callnotification:                     addlog("call notification event has occured");                     break;                 case tapi3lib.tapi_event.te_callstate:                     tapi3lib.itcallstateevent tcallstateevent = (tapi3lib.itcallstateevent)pevent;                     tapi3lib.itcallinfo b = tcallstateevent.call;                     switch (b.callstate)                     {                         case tapi3lib.call_state.cs_offering:                             string str2 = b.get_callinfostring(tapi3lib.callinfo_string.cis_calleridnumber);                             addlog("number calling:" + str2); //doesn't work                             return;                         case tapi3lib.call_state.cs_connected:                             string str = b.get_callinfostring(tapi3lib.callinfo_string.cis_calleridnumber);                             addlog("communicating with: " + str);                             return;                         case tapi3lib.call_state.cs_disconnected:                             this.endinvoke(result);                             addlog("call disconnected");                             return;                     }                     break;             }         }         catch (exception ex)         {             console.writeline(ex.message);         }     }      private void button2_click(object sender, eventargs e)     {         if (line == null) return;         tapi3lib.itbasiccallcontrol bc = line.createcall(tenumber.text, tapi3lib.tapiconstants.lineaddresstype_phonenumber, tapi3lib.tapiconstants.tapimediatype_audio);         bc.connect(false);     }      private void form1_load(object sender, eventargs e)     {      }    } } 

for same kind of problem used managed c# wrapper tapi written julmar , can download dll, using sample can record incoming call in .wav format

    tphone tphone;     ttapi tobj;     tterminal recordterminal;     tcall currcall;       void initializetapi()     {         tobj = new ttapi();         tobj.initialize();          tobj.te_callnotification += new system.eventhandler<julmar.tapi3.tapicallnotificationeventargs>(this.onnewcall);         tobj.te_callstate += new system.eventhandler<julmar.tapi3.tapicallstateeventargs>(this.oncallstate);                tobj.te_callinfochange += tobj_te_callinfochange;           foreach (tphone tp in tobj.phones)         {             tphone = tp;             tphone.open(phone_privilege.pp_owner);          }           foreach (taddress addr in tobj.addresses)         {             if (addr.querymediatype(tapimediatypes.audio))             {                 try                 {                     addr.open(tapimediatypes.audio);                 }                 catch (tapiexception ex)                 {                     if (ex.errorcode == unchecked((int)0x80040004))                     {                         try                         {                             addr.open(tapimediatypes.datamodem);                          }                         catch (exception ex2)                         {                         }                     }                 }             }         }     }         void tobj_te_callinfochange(object sender, tapicallinfochangeeventargs e)     {         try         {              currcall = e.call;             txtcallerid.text = e.call.get_callinfo(callinfo_string.cis_calleridnumber).tostring();             objcalllog.callerid = txtcallerid.text;              task.factory.startnew(() => answercall());                          }         catch (exception ex)         {          }     }      void onnewcall(object sender, tapicallnotificationeventargs e)     {         currcall = e.call;     }      void oncallstate(object sender, eventargs e)     {         try         {             tapicallstateeventargs e = e tapicallstateeventargs;             currcall = e.call;               tapiphoneeventargs ev = e tapiphoneeventargs;              switch (e.state)             {                  case call_state.cs_offering:                      break;                  case call_state.cs_connected:                       break;                  case call_state.cs_disconnected:                      try                     {                         if (recordterminal != null)                             recordterminal.stop();                         recordterminal = null;                          currcall.dispose();                      }                     catch (exception ex)                     {                     }                                         {                         currcall = null;                     }                        break;             }           }         catch (exception ex)         {          }     }      void oncallchangeevent(object sender, tapicallinfochangeeventargs e)     {         currcall = e.call;     }    private void answercall()     {         try         {             lock (lockanswer)             {                 if (callstat == callstate.offering)                 {                     currcall.answer();                     recordconversation();                 }                 else                 {                 }             }         }         catch (exception ex)         {         }     }       void recordconversation()     {           if (currcall != null)         {             try             {                 recordterminal = currcall.requestterminal(                 tterminal.filerecordingterminal,                 tapimediatypes.multitrack, terminal_direction.td_render);                 if (recordterminal != null)                 {                     recordterminal.recordfilename = "filename.wav";                     currcall.selectterminaloncall(recordterminal);                     recordterminal.start();                 }                 else                 {                     messagebox.show("error in recording file.");                 }             }             catch (tapiexception ex)             {                 messagebox.show(ex.tostring());             }          }      } 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -