📄 mainform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Project
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public int SND_ASYNC = 0x0001;
public int SND_NODEFAULT = 0x0002;
public int SND_LOOP = 0x0008;
public int SND_FILENAME = 0x00020000;
[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName, int hModule, int dwFlags);
private void ErrorMessages()
{
int nVaxObjectError = VaxSIPUserAgentOCX.GetVaxObjectError();
switch (nVaxObjectError)
{
case 10:
MessageBox.Show("You are not Online, please click the 'Online' button first.", "VaxVoIP SDK");
break;
case 11:
MessageBox.Show("Cann't open local communication port. Another softphone (x-Ten, x-lite or skype etc) is already running. Please close it first.", "VaxVoIP SDK");
break;
case 12:
MessageBox.Show("License Key is not valid.", "VaxVoIP SDK");
break;
case 13:
MessageBox.Show("Fail to initialize VaxVoIP task window.", "VaxVoIP SDK");
break;
case 14:
MessageBox.Show("Cann't access Input/Mic device or device is already in use.", "VaxVoIP SDK");
break;
case 15:
MessageBox.Show("Cann't access Output/Speaker device or device is already in use.", "VaxVoIP SDK");
break;
case 16:
MessageBox.Show("Input/Mic device is not open.", "VaxVoIP SDK");
break;
case 17:
MessageBox.Show("Output/Speaker device is not open.", "VaxVoIP SDK");
break;
case 18:
MessageBox.Show("Your sound device does not support mic volume.", "VaxVoIP SDK");
break;
case 19:
MessageBox.Show("Your sound device does not support speaker volume.", "VaxVoIP SDK");
break;
case 20:
MessageBox.Show("Recording media initialization fail.", "VaxVoIP SDK");
break;
case 21:
MessageBox.Show("Cann't open the wave file.", "VaxVoIP SDK");
break;
case 22:
MessageBox.Show("Provided SIP URI is not valid.", "VaxVoIP SDK");
break;
case 23:
MessageBox.Show("Codec is not supported.", "VaxVoIP SDK");
break;
case 24:
MessageBox.Show("Error to create SDP (Session Description Protocol) request.", "VaxVoIP SDK");
break;
case 25:
MessageBox.Show("Error to create CONNECTION request. Please check the provided SIP URI is valid.", "VaxVoIP SDK");
break;
case 26:
MessageBox.Show("Error to create REGISTER request. Please check the provided SIP URI is valid.", "VaxVoIP SDK");
break;
case 27:
MessageBox.Show("Error to create UN-REGISTER request. Please check the provided SIP URI is valid.", "VaxVoIP SDK");
break;
case 28:
MessageBox.Show("Error to create DISCONNECT request.", "VaxVoIP SDK");
break;
case 29:
MessageBox.Show("Line No is not valid.", "VaxVoIP SDK");
break;
case 30:
MessageBox.Show("Line is already busy.", "VaxVoIP SDK");
break;
case 31:
MessageBox.Show("Line is not open.", "VaxVoIP SDK");
break;
case 32:
MessageBox.Show("Invalid Call-Id.", "VaxVoIP SDK");
break;
case 33:
MessageBox.Show("Provided value is not valid.", "VaxVoIP SDK");
break;
case 34:
MessageBox.Show("Selected line is not in voice session.", "VaxVoIP SDK");
break;
case 35:
MessageBox.Show("Fail to read wave file.", "VaxVoIP SDK");
break;
case 36:
MessageBox.Show("Fail to write wave file.", "VaxVoIP SDK");
break;
case 37:
MessageBox.Show("Unsupported wave file format.", "VaxVoIP SDK");
break;
}
}
private Boolean InitVaxVoIPObject()
{
/********************************************************************
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.
*********************************************************************/
/****** Constructing SIP From URI for IP Telephony *******/
string sFromURI = EditLoginId.Text + " <sip:" + EditLoginId.Text + "@" + EditSIPProxy.Text + ">";
if(EditDisplayName.Text != "")
sFromURI = EditDisplayName.Text + " <sip:" + EditLoginId.Text + "@" + EditSIPProxy.Text + ">";
String sMyIP = VaxSIPUserAgentOCX.GetMyIP();
Boolean bResult = true;
int nListenPort = 5060;
for(nListenPort = 5060; nListenPort < 7000; nListenPort++)
{
if (!VaxSIPUserAgentOCX.Initialize(false, sMyIP, nListenPort, sFromURI, EditOutBoundProxy.Text, EditSIPProxy.Text, EditLoginId.Text, EditLoginPwd.Text, true, 7))
{
if(11 != VaxSIPUserAgentOCX.GetVaxObjectError())
{
bResult = false;
ErrorMessages();
break;
}
}
else
{
break;
}
}
if(nListenPort >= 7000)
{
MessageBox.Show("Cann't open SIP communication port.", "VaxVoIP SDK");
bResult = false;
}
return bResult;
}
private Boolean OpenLines(int nTotalNoOfLine)
{
Boolean bResult = true;
int nListenPort = 7000;
int nErrorCount = 0;
String sMyIP = VaxSIPUserAgentOCX.GetMyIP();
for (int nLineNo = 0; nLineNo < nTotalNoOfLine; nLineNo++)
{
if (!VaxSIPUserAgentOCX.OpenLine(nLineNo, false, sMyIP, nListenPort))
{
if (VaxSIPUserAgentOCX.GetVaxObjectError() != 11)
{
bResult = false;
ErrorMessages();
break;
}
else
{
nErrorCount += 1;
nLineNo = nLineNo - 1;
}
}
nListenPort += 2; //It is importent to increament RTP Listen port by 2
if (nErrorCount >= (nTotalNoOfLine + 1000)) // If unable to open more than 1000 ports.
{
MessageBox.Show("Unable to open RTP communication port.", "VaxVoIP SDK");
bResult = false;
break;
}
}
return bResult;
}
private void BtnOnline_Click(object sender, EventArgs e)
{
if( BtnOnline.Text == "Offline")
{
VaxSIPUserAgentOCX.UnInitialize();
BtnOnline.Text = "Online";
TimerTick.Enabled = false;
ProgressTimer.Enabled = false;
ComboAudioOut.Items.Clear();
ComboAudioIn.Items.Clear();
SpkProgBar.Value = 0;
MicProgBar.Value = 0;
return;
}
if( EditLoginId.Text == "")
{
MessageBox.Show("Please enter the SIP proxy Login Id.", "VaxVoIP SDK");
return;
}
if( EditSIPProxy.Text == "" )
{
MessageBox.Show("Please enter the SIP proxy address or URI.", "VaxVoIP SDK");
return;
}
VaxSIPUserAgentOCX.SetLicenceKey("TRIAL-LICENSE-KEY");
if(!InitVaxVoIPObject())
return;
if(!OpenLines(7))
return;
if (CheckRegisterToProxy.Checked)
{
if (!VaxSIPUserAgentOCX.RegisterToProxy(3600))
{
ErrorMessages();
return;
}
AddToStatusLog("Registering to SIP Proxy.");
}
if (CheckEchoCancel.Checked)
VaxSIPUserAgentOCX.EnableEchoNoiseCancellation();
else
VaxSIPUserAgentOCX.DisableEchoNoiseCancellation();
VaxSIPUserAgentOCX.DeselectAllVoiceCodec();
if (CheckGSM610.Checked)
VaxSIPUserAgentOCX.SelectVoiceCodec(0);
if (CheckiLBC.Checked)
VaxSIPUserAgentOCX.SelectVoiceCodec(1);
if (CheckG711A.Checked)
VaxSIPUserAgentOCX.SelectVoiceCodec(2);
if (CheckG711U.Checked)
VaxSIPUserAgentOCX.SelectVoiceCodec(3);
VaxSIPUserAgentOCX.EnableKeepAlive(10);
BtnOnline.Text = "Offline";
UpdateSoundDevice();
TimerTick.Enabled = true;
ProgressTimer.Enabled = true;
}
private void UpdateSoundDevice()
{
ComboAudioIn.Items.Clear();
ComboAudioIn.Items.Add("Default Device");
for(int nDeviceId = 0; nDeviceId < VaxSIPUserAgentOCX.GetAudioInDevTotal(); nDeviceId++)
{
ComboAudioIn.Items.Add(VaxSIPUserAgentOCX.GetAudioInDevName(nDeviceId));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -