Advertisement
Guest User

Untitled

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