📄 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.");
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.");
break;
case 12:
MessageBox.Show("License Key is not valid.");
break;
case 13:
MessageBox.Show("Fail to initialize VaxVoIP task window.");
break;
case 14:
MessageBox.Show("Cann't access Input/Mic device or device is already in use.");
break;
case 15:
MessageBox.Show("Cann't access Output/Speaker device or device is already in use.");
break;
case 16:
MessageBox.Show("Input/Mic device is not open.");
break;
case 17:
MessageBox.Show("Output/Speaker device is not open.");
break;
case 18:
MessageBox.Show("Your sound device does not support mic volume.");
break;
case 19:
MessageBox.Show("Your sound device does not support speaker volume.");
break;
case 20:
MessageBox.Show("Recording media initialization fail.");
break;
case 21:
MessageBox.Show("Cann't open the wave file.");
break;
case 22:
MessageBox.Show("Provided SIP URI is not valid.");
break;
case 23:
MessageBox.Show("Codec is not supported.");
break;
case 24:
MessageBox.Show("Error to create SDP (Session Description Protocol) request.");
break;
case 25:
MessageBox.Show("Error to create CONNECTION request. Please check the provided SIP URI is valid.");
break;
case 26:
MessageBox.Show("Error to create REGISTER request. Please check the provided SIP URI is valid.");
break;
case 27:
MessageBox.Show("Error to create UN-REGISTER request. Please check the provided SIP URI is valid.");
break;
case 28:
MessageBox.Show("Error to create DISCONNECT request.");
break;
case 29:
MessageBox.Show("Line No is not valid.");
break;
case 30:
MessageBox.Show("Line is already busy.");
break;
case 31:
MessageBox.Show("Line is not open.");
break;
case 32:
MessageBox.Show("Invalid Call-Id.");
break;
case 33:
MessageBox.Show("Provided value is not valid.");
break;
case 34:
MessageBox.Show("Selected line is not in voice session.");
break;
case 35:
MessageBox.Show("Fail to read wave file.");
break;
case 36:
MessageBox.Show("Fail to write wave file.");
break;
case 37:
MessageBox.Show("Unsupported wave file format.");
break;
}
}
private void FillComboBox(int nTotalLine)
{
ComboDial.Items.Clear();
ComboRecord.Items.Clear();
ComboPlayWave.Items.Clear();
ComboIncomingCall.Items.Clear();
ComboTransferCall.Items.Clear();
for(int nLineNo = 1; nLineNo <= nTotalLine; nLineNo++)
{
ComboDial.Items.Add("Line-" + Convert.ToString(nLineNo));
ComboRecord.Items.Add("Line-" + Convert.ToString(nLineNo));
ComboPlayWave.Items.Add("Line-" + Convert.ToString(nLineNo));
ComboIncomingCall.Items.Add("Line-" + Convert.ToString(nLineNo));
ComboTransferCall.Items.Add("Line-" + Convert.ToString(nLineNo));
}
ComboDial.SelectedIndex = 0;
ComboRecord.SelectedIndex = 0;
ComboPlayWave.SelectedIndex = 0;
ComboIncomingCall.SelectedIndex = 0;
ComboTransferCall.SelectedIndex = 0;
}
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, CheckEnableSoundDevice.Checked, Convert.ToInt32(EditTotalLines.Text)))
{
if(11 != VaxSIPUserAgentOCX.GetVaxObjectError())
{
bResult = false;
ErrorMessages();
break;
}
}
else
{
break;
}
}
if(nListenPort >= 7000)
{
MessageBox.Show("Cann't open SIP communication port.");
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.");
bResult = false;
break;
}
}
return bResult;
}
private void BtnOnline_Click(object sender, EventArgs e)
{
if( BtnOnline.Text == "Offline")
{
VaxSIPUserAgentOCX.UnInitialize();
BtnOnline.Text = "Online";
EditTotalLines.Enabled = true;
ListViewLineStatus.Items.Clear();
ListAudioOut.Items.Clear();
ListAudioIn.Items.Clear();
TimerTick.Enabled = false;
ProgressTimer.Enabled = false;
SpkProgBar.Value = 0;
MicProgBar.Value = 0;
return;
}
if( EditLoginId.Text == "")
{
MessageBox.Show("Please enter the SIP proxy Login Id.");
return;
}
if( EditSIPProxy.Text == "" )
{
MessageBox.Show("Please enter the SIP proxy address or URI.");
return;
}
VaxSIPUserAgentOCX.SetLicenceKey("TRIAL-LICENSE-KEY");
if(!InitVaxVoIPObject())
return;
if(!OpenLines(Convert.ToInt32(EditTotalLines.Text)))
return;
if (CheckRegisterToProxy.Checked)
{
if (!VaxSIPUserAgentOCX.RegisterToProxy(3600))
{
ErrorMessages();
return;
}
AddToStatusLog("Registering to SIP Proxy.");
}
CheckEchoCancel.Checked = true;
CheckGSM610.Checked = true;
CheckiLBC.Checked = true;
CheckG711A.Checked = true;
CheckG711U.Checked = true;
VaxSIPUserAgentOCX.EnableKeepAlive(10);
BtnOnline.Text = "Offline";
EditTotalLines.Enabled = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -