?? mainform.vb
字號:
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 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, True, 7)
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"
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, 7)
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)
If CheckRegisterToProxy.Checked = 1 Then
Result = VaxSIPUserAgentOCX.RegisterToProxy(3600)
If Result = False Then
ErrorMessages()
Exit Sub
End If
AddToStatusLog("Registering to SIP Proxy.")
End If
If CheckEchoCancel.Checked Then
VaxSIPUserAgentOCX.EnableEchoNoiseCancellation()
Else
VaxSIPUserAgentOCX.DisableEchoNoiseCancellation()
End If
VaxSIPUserAgentOCX.DeselectAllVoiceCodec()
If CheckGSM610.Checked Then
VaxSIPUserAgentOCX.SelectVoiceCodec(0)
End If
If CheckiLBC.Checked Then
VaxSIPUserAgentOCX.SelectVoiceCodec(1)
End If
If CheckG711A.Checked Then
VaxSIPUserAgentOCX.SelectVoiceCodec(2)
End If
If CheckG711U.Checked Then
VaxSIPUserAgentOCX.SelectVoiceCodec(3)
End If
BtnOnline.Text = "Offline"
TimerTick.Enabled = True
ProgressTimer.Enabled = True
UpdateSoundDevices()
TimerTick.Enabled = True
ProgressTimer.Enabled = True
End Sub
Private Sub BtnDial_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDial.Click
Dim LineNo As Integer
Dim ToURI As String
Dim Result As Boolean
If EditPhoneNo.Text = "" Then
MsgBox("Please enter a phone number.")
Exit Sub
End If
'*******************************************************
' Constructing SIP To URI for IP Telephony:
' sip:PhoneNumber@SIP Proxy
'********************************************************
ToURI = "sip:" & EditPhoneNo.Text & "@" & EditSIPProxy.Text
LineNo = FindLine()
If LineNo = -1 Then
MsgBox("No line is free")
Exit Sub
End If
Result = VaxSIPUserAgentOCX.Connect(LineNo, ToURI, ComboAudioIn.SelectedIndex - 1, ComboAudioOut.SelectedIndex - 1)
If Result = False Then
ErrorMessages()
Else
AddToStatusLog("Line-" & Str(LineNo + 1) & ": Dialing.")
ListLines.Items.Item(LineNo) = "Line-" + Trim(Str(LineNo + 1)) + " : CONNECTING"
End If
End Sub
Private Sub BtnClearLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClearLog.Click
ListStatusLog.Items.Clear()
End Sub
Private Sub BtnDialPad1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDialPad1.Click
EditPhoneNo.Text = EditPhoneNo.Text + "1"
VaxSIPUserAgentOCX.DigitDTMF(ListLines.SelectedIndex, "1")
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -