TAPI Ninja Softphone, telefonat erkennen

  • VB.NET

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von XBrainBug.

    TAPI Ninja Softphone, telefonat erkennen

    Hallo zusammen,

    ich habe schon viel im Internet zu dem Thema gefunden aber das meiste ist uralt. Leider finde ich kein Beispiel was mir irgendwie weiterhilft, wahrscheinlich liegts daran das ich noch Anfänger bin.

    Ich möchte einfach nur erkennen ob jemand gerade telefoniert oder ein Rufzeichen ertönt, das ist alles.

    Ich habe etwas gefunden was mir zumindest schon mal sagt, das es den richtig TAPI ausgewählt hat aber ab da komme ich nicht weiter. Egal was ich ausprobiere, ich kriege bei nichts einen Rückmeldung oder auch nur eine Reaktion wenn ich anrufe etc.

    Code:

    VB.NET-Quellcode

    1. Imports TAPI3Lib
    2. Public Class Form1
    3. Private Const MediaAudio As Integer = 8
    4. Private Const MediaModem As Integer = 16
    5. Private Const MediaFax As Integer = 32
    6. Private Const MediaVideo As Integer = 32768
    7. Private WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
    8. Private oAddress As ITAddress ' will hold our selected address (you can hold many address in an array)
    9. Private RegCookie As Integer
    10. Sub New()
    11. Try
    12. ' creating a new instance to first initialize TAPI befor attaching the events
    13. Dim m_TAPI As New TAPIClass
    14. ' a variable to hold supported media types for the address
    15. Dim MediaTypes As Integer
    16. ' initializing TAPI
    17. m_TAPI.Initialize()
    18. ' attaching event sink
    19. oTAPI = m_TAPI
    20. ' getting red of the private instance as we have another global instance (oTAPI)
    21. m_TAPI = Nothing
    22. Dim AddressCollection As ITCollection = oTAPI.Addresses()
    23. For Each Address As ITAddress In AddressCollection ' looping through address collection
    24. If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if address is working
    25. Dim MediaSupport As ITMediaSupport = Address ' extracting meida support interface from the address
    26. MediaTypes = MediaSupport.MediaTypes ' extracting media types supporting
    27. MediaSupport = Nothing ' dispose of the object
    28. If MediaTypes And MediaModem = MediaModem Then
    29. ' the address is a data Modem
    30. If MediaTypes And MediaAudio = MediaAudio Then
    31. 'the address supports Audio
    32. oAddress = Address ' select this address
    33. MsgBox("we have selected this address: " + oAddress.AddressName) ' show the selected address name
    34. Exit For
    35. End If
    36. End If
    37. End If
    38. Next Address
    39. If Not oAddress Is Nothing Then
    40. ' registering notifications for the selected address
    41. RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False, MediaTypes, 1)
    42. ' Note: this registration can be done on as many adresses as you want
    43. ' we will not receive notifications unless we spacify which type of events we are interested in
    44. oTAPI.EventFilter = (TAPI_EVENT.TE_CALLNOTIFICATION Or TAPI_EVENT.TE_CALLSTATE Or TAPI_EVENT.TE_CALLINFOCHANGE)
    45. Else
    46. MsgBox("no address selected")
    47. End If
    48. Catch ex As Exception
    49. MsgBox("Error occured:" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "VBCITY.VBTAPI")
    50. End Try
    51. ' by now we are done for the initialization and registration and the events should fire
    52. ' Note: you must dispose of tapi befor you destroy the class and i will leave this for now
    53. End Sub
    54. Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles oTAPI.Event
    55. ' making a thread to asynchronosly process the event
    56. Dim thAsyncCall As System.Threading.Thread
    57. Select Case TapiEvent
    58. Case TAPI_EVENT.TE_CALLNOTIFICATION 'Call Notification Arrived
    59. ' assigning our sub's delegate to the thread
    60. thAsyncCall = New Threading.Thread(AddressOf CallNotificationEvent)
    61. 'passing the variable for the thread
    62. CallNotificationObject = CType(pEvent, ITCallNotificationEvent)
    63. ' starting the thread
    64. thAsyncCall.Start()
    65. Case TAPI_EVENT.TE_CALLSTATE 'Call State Changes
    66. ' assigning our sub's delegate to the thread
    67. thAsyncCall = New Threading.Thread(AddressOf CallStateEvent)
    68. 'passing the variable for the thread
    69. CallStateObject = CType(pEvent, ITCallStateEvent)
    70. ' starting the thread
    71. thAsyncCall.Start()
    72. Case TAPI_EVENT.TE_CALLINFOCHANGE 'Call Info Changes
    73. ' assigning our sub's delegate to the thread
    74. thAsyncCall = New Threading.Thread(AddressOf CallInfoEvent)
    75. 'passing the variable for the thread
    76. CallInfoObject = CType(pEvent, ITCallInfoChangeEvent)
    77. ' starting the thread
    78. thAsyncCall.Start()
    79. End Select
    80. End Sub
    81. Private CallNotificationObject As ITCallNotificationEvent
    82. Private Sub CallNotificationEvent()
    83. ' here we should check to see various notifications of new and ended calls
    84. Select Case CallNotificationObject.Event
    85. Case CALL_NOTIFICATION_EVENT.CNE_MONITOR
    86. ' the notification is for a monitored call
    87. Case CALL_NOTIFICATION_EVENT.CNE_OWNER
    88. ' the notification is for an owned call
    89. End Select
    90. End Sub
    91. Private CallStateObject As ITCallStateEvent
    92. Private Sub CallStateEvent()
    93. ' here we should check to see call state and handle connects and disconnects
    94. Select Case CallStateObject.State
    95. Case CALL_STATE.CS_IDLE
    96. Case CALL_STATE.CS_INPROGRESS
    97. Case CALL_STATE.CS_OFFERING
    98. ' a call is offering so if you dont want it then pass it
    99. ' the code to pass the call is the following
    100. 'Dim CallControl As ITBasicCallControl = CallStateObject.Call
    101. 'CallControl.HandoffIndirect(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
    102. Case CALL_STATE.CS_CONNECTED
    103. ' call is connected
    104. Case CALL_STATE.CS_QUEUED
    105. ' call is beeing queued
    106. Case CALL_STATE.CS_HOLD
    107. ' call is on hold
    108. Case CALL_STATE.CS_DISCONNECTED
    109. ' call is disconnected
    110. End Select
    111. End Sub
    112. Private CallInfoObject As ITCallInfoChangeEvent
    113. Private Sub CallInfoEvent()
    114. ' here you can extract information from the call
    115. 'the code to extract the caller ID
    116. Dim CallerID As String
    117. CallerID = CallInfoObject.Call.CallInfoString(CALLINFO_STRING.CIS_CALLERIDNAME)
    118. End Sub
    119. End Class