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

📄 mainform.vb

📁 VaxSIPUserAgentSDK
💻 VB
📖 第 1 页 / 共 3 页
字号:
Public Class MainForm

    Private Const SND_FILENAME As Integer = &H20000
    Private Const SND_LOOP As Short = &H8S
    Private Const SND_ASYNC As Short = &H1S
    Private Const SND_NODEFAULT As Short = &H2

    Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Boolean

    Private Sub ErrorMessages()

        Dim VaxObjectError As Object
        VaxObjectError = VaxSIPUserAgentOCX.GetVaxObjectError

        If VaxObjectError = 10 Then
            MsgBox("You are not Online, please click the 'Online' button first.")
        End If

        If VaxObjectError = 11 Then
            MsgBox("Cann't open local communication port. Another softphone (x-Ten, x-lite or skype etc) is already running. Please close it first.")
        End If

        If VaxObjectError = 12 Then
            MsgBox("License Key is not valid.")
        End If

        If VaxObjectError = 13 Then
            MsgBox("Fail to initialize VaxVoIP task window.")
        End If

        If VaxObjectError = 14 Then
            MsgBox("Cann't access Input/Mic device or device is already in use.")
        End If

        If VaxObjectError = 15 Then
            MsgBox("Cann't access Output/Speaker device or device is already in use.")
        End If

        If VaxObjectError = 16 Then
            MsgBox("Input/Mic device is not open.")
        End If

        If VaxObjectError = 17 Then
            MsgBox("Output/Speaker device is not open.")
        End If

        If VaxObjectError = 18 Then
            MsgBox("Your sound device does not support mic volume.")
        End If

        If VaxObjectError = 19 Then
            MsgBox("Your sound device does not support speaker volume.")
        End If

        If VaxObjectError = 20 Then
            MsgBox("Recording media initialization fail.")
        End If

        If VaxObjectError = 21 Then
            MsgBox("Cann't open the wave file.")
        End If

        If VaxObjectError = 22 Then
            MsgBox("Provided SIP URI is not valid.")
        End If

        If VaxObjectError = 23 Then
            MsgBox("Codec is not supported.")
        End If

        If VaxObjectError = 24 Then
            MsgBox("Error to create SDP (Session Description Protocol) request.")
        End If

        If VaxObjectError = 25 Then
            MsgBox("Error to create CONNECTION request. Please check the provided SIP URI is valid.")
        End If

        If VaxObjectError = 26 Then
            MsgBox("Error to create REGISTER request. Please check the provided SIP URI is valid.")
        End If

        If VaxObjectError = 27 Then
            MsgBox("Error to create UN-REGISTER request. Please check the provided SIP URI is valid.")
        End If

        If VaxObjectError = 28 Then
            MsgBox("Error to create DISCONNECT request.")
        End If

        If VaxObjectError = 29 Then
            MsgBox("Line No is not valid.")
        End If

        If VaxObjectError = 30 Then
            MsgBox("Line is already busy.")
        End If

        If VaxObjectError = 31 Then
            MsgBox("Line is not open.")
        End If

        If VaxObjectError = 32 Then
            MsgBox("Invalid Call-Id.")
        End If

        If VaxObjectError = 33 Then
            MsgBox("Provided value is not valid.")
        End If

        If VaxObjectError = 34 Then
            MsgBox("Selected line is not in voice session.")
        End If

        If VaxObjectError = 35 Then
            MsgBox("Fail to read wave file.")
        End If

        If VaxObjectError = 36 Then
            MsgBox("Fail to write wave file.")
        End If

        If VaxObjectError = 37 Then
            MsgBox("Unsupported wave file format.")
        End If

    End Sub

    Private Sub FillComboBox()

        Dim LineNo As Integer

        ComboDial.Items.Clear()
        ComboRecord.Items.Clear()
        ComboPlayWave.Items.Clear()
        ComboIncomingCall.Items.Clear()
        ComboTransferCall.Items.Clear()

        For LineNo = 0 To (Int(EditTotalLines.Text) - 1)

            ComboDial.Items.Add("Line-" & Str(LineNo + 1))
            ComboRecord.Items.Add("Line-" & Str(LineNo + 1))
            ComboPlayWave.Items.Add("Line-" & Str(LineNo + 1))
            ComboIncomingCall.Items.Add("Line-" & Str(LineNo + 1))
            ComboTransferCall.Items.Add("Line-" & Str(LineNo + 1))

        Next LineNo

        ComboDial.SelectedIndex = 0
        ComboRecord.SelectedIndex = 0
        ComboPlayWave.SelectedIndex = 0
        ComboIncomingCall.SelectedIndex = 0
        ComboTransferCall.SelectedIndex = 0

    End Sub

    Private Function InitVaxVoIPObject(ByVal MyIP As String, ByVal FromURI As String) As Boolean

        Dim ListenPort As Short
        Dim Result As Boolean

        Result = False
        ListenPort = 5060

        Do While ListenPort < 7000

            Result = VaxSIPUserAgentOCX.Initialize(False, MyIP, ListenPort, FromURI, EditOutBoundProxy.Text, EditSIPProxy.Text, EditLoginId.Text, EditLoginPwd.Text, CheckEnableSoundDevice.CheckState, Int(CDbl(EditTotalLines.Text)))
            If Result = False Then

                If 11 <> VaxSIPUserAgentOCX.GetVaxObjectError() Then
                    ErrorMessages()
                    Exit Do
                End If

            Else
                Exit Do
            End If

            ListenPort = ListenPort + 1
        Loop

        If ListenPort >= 7000 Then
            MsgBox("Cann't open SIP communication port.")
            Result = False
        End If

        Return Result

    End Function

    Private Function OpenLines(ByVal MyIP As String, ByVal TotalNoOfLine As Short) As Boolean

        Dim LineNo As Integer
        Dim ListenPort As Short
        Dim Result As Boolean
        Dim ErrorCount As Integer

        Result = False
        ListenPort = 7000
        ErrorCount = 0

        For LineNo = 0 To (TotalNoOfLine - 1)

            Result = VaxSIPUserAgentOCX.OpenLine(LineNo, False, MyIP, ListenPort)
            If Result = False Then

                If 11 <> VaxSIPUserAgentOCX.GetVaxObjectError() Then
                    ErrorMessages()
                    Exit For
                Else
                    ErrorCount = ErrorCount + 1
                    LineNo = LineNo - 1
                End If

            End If

            ListenPort = ListenPort + 2 ' It is importent to increament RTP Listen port by 2

            If ErrorCount >= (TotalNoOfLine + 1000) Then  ' If unable to open more than 1000 ports.
                MsgBox("Unable to open RTP communication port.")
                Result = False
                Exit For
            End If

        Next LineNo

        Return Result

    End Function

    Private Sub BtnOnline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOnline.Click

        Dim Result As Boolean
        Dim MyIP As String
        Dim FromURI As String

        If BtnOnline.Text = "Offline" Then

            TimerTick.Enabled = False
            ProgressTimer.Enabled = False

            SpkProgBar.Value = 0
            MicProgBar.Value = 0

            VaxSIPUserAgentOCX.UnInitialize()

            BtnOnline.Text = "Online"
            EditTotalLines.Enabled = True

            ListViewLineStatus.Items.Clear()

            Exit Sub

        End If

        If EditLoginId.Text = "" Then
            MsgBox("Please enter the SIP proxy Login Id.")
            Exit Sub
        End If

        If EditSIPProxy.Text = "" Then
            MsgBox("Please enter the SIP proxy address or URI.")
            Exit Sub
        End If

        VaxSIPUserAgentOCX.SetLicenceKey("TRIAL-LICENSE-KEY")

        '****** Constructing SIP From URI for IP Telephony *******
        If EditDisplayName.Text = "" Then
            FromURI = EditLoginId.Text & " <sip:" & EditLoginId.Text & "@" & EditSIPProxy.Text & ">"
        Else
            FromURI = EditDisplayName.Text & " <sip:" & EditLoginId.Text & "@" & EditSIPProxy.Text & ">"
        End If

        '********************************************************************
        '   Listen Port: default SIP port 5060.
        '     SIP Proxy: SIP Proxy IP or FQDN provided by your service provider.
        ' OutboundProxy: SIP outbound/NAT proxy IP or FQDN provided by your
        '                service provider to use SIP phone behind the NAT.
        '
        '*********************************************************************

        MyIP = VaxSIPUserAgentOCX.GetMyIP()

        Result = InitVaxVoIPObject(MyIP, FromURI)
        If Result = False Then
            Exit Sub
        End If

        Result = OpenLines(MyIP, Int(CDbl(EditTotalLines.Text)))
        If Result = False Then
            Exit Sub
        End If

        If CheckRegisterToProxy.Checked Then
            Result = VaxSIPUserAgentOCX.RegisterToProxy(3600)
            If Result = False Then
                ErrorMessages()
                Exit Sub
            End If
            AddToStatusLog("Registering to SIP Proxy.")
        End If

        VaxSIPUserAgentOCX.EnableKeepAlive(10)

        CheckEchoCancel.Checked = True
        CheckGSM610.Checked = True
        CheckiLBC.Checked = True
        CheckG711A.Checked = True
        CheckG711U.Checked = True

        BtnOnline.Text = "Offline"
        EditTotalLines.Enabled = False

        TimerTick.Enabled = True
        ProgressTimer.Enabled = True

        FillComboBox()

        UpdateAudioIn()
        UpdateAudioOut()

    End Sub

    Private Sub UpdateAudioIn()

        Dim DeviceId As Integer

        ListAudioIn.Items.Clear()
        ListAudioIn.Items.Add("Default Device")

        For DeviceId = 0 To VaxSIPUserAgentOCX.GetAudioInDevTotal() - 1
            ListAudioIn.Items.Add(VaxSIPUserAgentOCX.GetAudioInDevName(DeviceId))
        Next DeviceId

        ListAudioIn.SelectedIndex = 0

    End Sub

    Private Sub UpdateAudioOut()

        Dim DeviceId As Integer

        ListAudioOut.Items.Clear()
        ListAudioOut.Items.Add("Default Device")

        For DeviceId = 0 To VaxSIPUserAgentOCX.GetAudioOutDevTotal() - 1
            ListAudioOut.Items.Add(VaxSIPUserAgentOCX.GetAudioOutDevName(DeviceId))
        Next DeviceId

        ListAudioOut.SelectedIndex = 0

    End Sub


⌨️ 快捷键说明

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