⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vbtapi.vb

📁 transmit the video over the netwrk
💻 VB
字号:
Imports TAPI3Lib

Namespace VBCity.TAPI

    Public Class VBTAPI

        Private Const MediaAudio As Integer = 8
        Private Const MediaModem As Integer = 16
        Private Const MediaFax As Integer = 32
        Private Const MediaVideo As Integer = 32768

        Private WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
        Private oAddress As ITAddress ' will hold our selected address (you can hold many address in an array)
        Private RegCookie As Integer

        Sub New()

            Try

                ' creating a new instance to first initialize TAPI befor attaching the events
                Dim m_TAPI As New TAPIClass
                ' a variable to hold supported media types for the address
                Dim MediaTypes As Integer
                ' initializing TAPI
                m_TAPI.Initialize()
                ' attaching event sink
                oTAPI = m_TAPI
                ' getting red of the private instance as we have another global instance (oTAPI)
                m_TAPI = Nothing

                Dim AddressCollection As ITCollection = oTAPI.Addresses()

                For Each Address As ITAddress In AddressCollection ' looping through address collection

                    If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if address is working 

                        Dim MediaSupport As ITMediaSupport = Address ' extracting meida support interface from the address

                        MediaTypes = MediaSupport.MediaTypes ' extracting media types supporting

                        MediaSupport = Nothing ' dispose of the object

                        If MediaTypes And MediaModem = MediaModem Then
                            ' the address is a data Modem
                            If MediaTypes And MediaAudio = MediaAudio Then
                                'the address supports Audio
                                oAddress = Address ' select this address
                                MsgBox("we have selected this address: " + oAddress.AddressName) ' show the selected address name
                                Exit For
                            End If
                        End If

                    End If

                Next Address

                If Not oAddress Is Nothing Then
                    ' registering notifications for the selected address
                    RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False, MediaTypes, 1)
                    ' Note: this registration can be done on as many adresses as you want

                    ' we will not receive notifications unless we spacify which type of events we are interested in
                    oTAPI.EventFilter = (TAPI_EVENT.TE_CALLNOTIFICATION Or TAPI_EVENT.TE_CALLSTATE Or TAPI_EVENT.TE_CALLINFOCHANGE)
                Else
                    MsgBox("no address selected")
                End If

            Catch ex As Exception
                MsgBox("Error occured:" & vbCrLf & ex.Message, MsgBoxStyle.Critical, "VBCITY.VBTAPI")
            End Try

            ' by now we are done for the initialization and registration and the events should fire 
            ' Note: you must dispose of tapi befor you destroy the class and i will leave this for now
        End Sub

        Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object) Handles oTAPI.Event

            ' making a thread to asynchronosly process the event
            Dim thAsyncCall As System.Threading.Thread

            Select Case TapiEvent
                Case TAPI_EVENT.TE_CALLNOTIFICATION 'Call Notification Arrived

                    ' assigning our sub's delegate to the thread
                    thAsyncCall = New Threading.Thread(AddressOf CallNotificationEvent)
                    'passing the variable for the thread
                    CallNotificationObject = CType(pEvent, ITCallNotificationEvent)
                    ' starting the thread
                    thAsyncCall.Start()

                Case TAPI_EVENT.TE_CALLSTATE 'Call State Changes

                    ' assigning our sub's delegate to the thread
                    thAsyncCall = New Threading.Thread(AddressOf CallStateEvent)
                    'passing the variable for the thread
                    CallStateObject = CType(pEvent, ITCallStateEvent)
                    ' starting the thread
                    thAsyncCall.Start()

                Case TAPI_EVENT.TE_CALLINFOCHANGE 'Call Info Changes

                    ' assigning our sub's delegate to the thread
                    thAsyncCall = New Threading.Thread(AddressOf CallInfoEvent)
                    'passing the variable for the thread
                    CallInfoObject = CType(pEvent, ITCallInfoChangeEvent)
                    ' starting the thread
                    thAsyncCall.Start()

            End Select

        End Sub

        Private CallNotificationObject As ITCallNotificationEvent
        Private Sub CallNotificationEvent()
            ' here we should check to see various notifications of new and ended calls

            Select Case CallNotificationObject.Event

                Case CALL_NOTIFICATION_EVENT.CNE_MONITOR
                    ' the notification is for a monitored call

                Case CALL_NOTIFICATION_EVENT.CNE_OWNER
                    ' the notification is for an owned call
            End Select

        End Sub

        Private CallStateObject As ITCallStateEvent
        Private Sub CallStateEvent()
            ' here we should check to see call state and handle connects and disconnects

            Select Case CallStateObject.State
                Case CALL_STATE.CS_IDLE

                Case CALL_STATE.CS_INPROGRESS

                Case CALL_STATE.CS_OFFERING
                    ' a call  is offering so if you dont want it then pass it 

                    ' the code to pass the call is the following
                    'Dim CallControl As ITBasicCallControl = CallStateObject.Call
                    'CallControl.HandoffIndirect (CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)

                Case CALL_STATE.CS_CONNECTED
                    ' call  is connected 

                Case CALL_STATE.CS_QUEUED
                    ' call is beeing queued

                Case CALL_STATE.CS_HOLD
                    ' call is on hold 

                Case CALL_STATE.CS_DISCONNECTED
                    ' call is disconnected

            End Select

        End Sub

        Private CallInfoObject As ITCallInfoChangeEvent
        Private Sub CallInfoEvent()
            ' here you can extract information from the call 

            'the code to extract the caller ID
            Dim CallerID As String
            CallerID = CallInfoObject.Call.CallInfoString(CALLINFO_STRING.CIS_CALLERIDNAME)

        End Sub

    End Class

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -