forked from mironator/Sip-Phone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.cs
161 lines (138 loc) · 4.79 KB
/
MainWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Net.Sockets;
using SIPLib;
namespace Phone
{
public partial class MainWindow : Form
{
SIPLib.Del DelOutput;
SIPLib.DelRequest DelRequest1;
SIPLib.Listener Phone;
SIPLib.Player player = new Player("127.0.0.1", portplayer);
public DelCloseSession DelClosesession;
SIPLib.DelStopListener DelStoplistener;
static int portplayer = 4000;
static int port = 5060;
public MainWindow()
{
InitializeComponent();
DelOutput += funcOutput;
DelRequest1 += ReceivedInvite;
DelClosesession += CloseSession;
DelStoplistener += DelStoplistener;
}
public void funcOutput(string Info, string Caption)
{
MessageBox.Show(Info, Caption);
}
public bool ReceivedInvite(string a)
{
if (DialogResult.Yes == MessageBox.Show("Хотите принять вызов от: " + a, "Входящий вызов", MessageBoxButtons.YesNo))
{
player.SetOptions(a.Remove(0, a.IndexOf('@') + 1), portplayer);
player.Start();
this.btnMakeDirectCall.Enabled = false;
this.btnHangUpDirectCall.Enabled = true;
this.btnPause.Enabled = true;
this.btnResume.Enabled = false;
return true;
}
else
{
player.Stop();
return false;
}
}
public void CloseSession(string Name)
{
ListView.ListViewItemCollection items = new ListView.ListViewItemCollection(new ListView());
}
private void btnMakeDirectCall_Click(object sender, EventArgs e)
{
Phone.MakeCall(this.tbTargetIP.Text, this.tbTargetUserNameDirect.Text, tbAccountUser.Text);
player.SetOptions(this.tbTargetIP.Text, portplayer);
player.Start();
this.btnMakeDirectCall.Enabled = false;
this.btnHangUpDirectCall.Enabled = true;
this.btnLogOut.Enabled = false;
this.btnPause.Enabled = true;
this.btnResume.Enabled = false;
this.tbTargetIP.Enabled = false;
this.tbTargetUserNameDirect.Enabled = false;
}
private void btnHangUpDirectCall_Click(object sender, EventArgs e)
{
this.btnMakeDirectCall.Enabled = true;
this.btnHangUpDirectCall.Enabled = false;
this.btnLogOut.Enabled = true;
this.btnPause.Enabled = false;
this.btnResume.Enabled = false;
this.tbTargetIP.Enabled = true;
this.tbTargetUserNameDirect.Enabled = true;
Phone.StopPhone();
player.Stop();
}
public void StopListenerFunc()
{
Phone.StopPhone();
}
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
Phone.StopPhone();
player.Stop();
Application.Exit();
}
catch (Exception)
{
return;
}
}
private void btnLogIn_Click(object sender, EventArgs e)
{
Phone = new SIPLib.Listener(port, DelRequest1, this.tbAccountUser.Text, DelClosesession, DelOutput, DelStoplistener); //класс слушателя
btnMakeDirectCall.Enabled = true;
btnHangUpDirectCall.Enabled = false;
btnLogIn.Enabled = false;
btnLogOut.Enabled = true;
tbAccountUser.Enabled = false;
}
private void выйтиToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Phone != null)
Phone.StopPhone();
Application.Exit();
}
private void btnPause_Click(object sender, EventArgs e)
{
player.Stop();
this.btnPause.Enabled = false;
this.btnResume.Enabled = true;
}
private void btnResume_Click(object sender, EventArgs e)
{
player.Start();
this.btnPause.Enabled = true;
this.btnResume.Enabled = false;
}
private void btnLogOut_Click(object sender, EventArgs e)
{
Phone.StopPhone();
btnMakeDirectCall.Enabled = false;
btnHangUpDirectCall.Enabled = false;
btnLogIn.Enabled = true;
btnLogOut.Enabled = false;
tbAccountUser.Enabled = true;
}
}
}