private void BCall_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 0) { MessageBox.Show("Nie wybrano żadnego znajomego!", "Błąd!"); } else if (listView1.SelectedItems[0].ImageIndex == 0) { Program.client = new SynchronousClient(Program.serverAddress); Communique.CallState(Program.userLogin, listView1.SelectedItems[0].Text, DateTime.Now, TimeSpan.Zero); string[] historyDetails = new string[3]; historyDetails[0] = listView1.SelectedItems[0].Text; historyDetails[1] = DateTime.Now.ToString(); historyDetails[2] = "nieodebrane"; listView2.Items.Insert(0, (new ListViewItem(historyDetails))); listView2.Refresh(); MessageBox.Show("Znajomy nie jest dostępny! Wysłano powiadomienie o próbie nawiązania połączenia.", "Niedostępny znajomy!"); Program.client.Disconnect(); } else { LUserCallOut.Text = "z " + listView1.SelectedItems[0].Text.ToString(); gBCallOut.Visible = true; Program.voice.Call(); timerCallOut.Start(); gBChangePass.Enabled = false; gBDelAcc.Enabled = false; } }
private void BCancel_Click(object sender, EventArgs e) { timerCallOut.Stop(); Program.voice.CancelCall(); Program.client = new SynchronousClient(Program.serverAddress); Communique.CallState(Program.userLogin, listView1.SelectedItems[0].Text, DateTime.Now, TimeSpan.Zero); string[] historyDetails = new string[3]; historyDetails[0] = listView1.SelectedItems[0].Text; historyDetails[1] = DateTime.Now.ToString(); historyDetails[2] = "nieodebrane"; listView2.Items.Insert(0, (new ListViewItem(historyDetails))); listView2.Refresh(); Program.client.Disconnect(); gBChangePass.Enabled = true; gBDelAcc.Enabled = true; }
private void BDisconnect_Click(object sender, EventArgs e) { end = DateTime.Now; timerConv.Stop(); Program.voice.DropCall(); //wyslij do serwera Program.client = new SynchronousClient(Program.serverAddress); if (isReceiver == true) { Communique.CallState(LUserConv.Text.Remove(0, 2), Program.userLogin, begin, (end - begin)); } else { Communique.CallState(Program.userLogin, LUserConv.Text.Remove(0, 2), begin, (end - begin)); } Program.client.Disconnect(); isReceiver = false; }
/* * Commands are received asynchronously. OnReceive is the handler for them. */ private void OnReceive(IAsyncResult ar) { try { EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0); //Get the IP from where we got a message. clientSocket.EndReceiveFrom(ar, ref receivedFromEP); //Convert the bytes received into an object of type Data. string message = Encoding.ASCII.GetString(byteData); //Data msgReceived = new Data(byteData); //Act according to the received message. switch (message[0]) { //We have an incoming call. case (char)10: { if (Program.secConv.gBCallOut.Visible == true) { Program.secConv.Invoke((MethodInvoker) delegate { Program.secConv.timerCallOut.Stop(); Program.secConv.gBCallOut.Visible = false; player.Stop(); }); } player = new System.Media.SoundPlayer(); player.Stream = Properties.Resources.Call1; player.PlayLooping(); string msgTmp = string.Empty; if (bIsCallActive == false) { //split message //message = comm + " " + Program.userLogin + " " + vocoder + " <EOF>"; string [] msgTable = message.Split(' '); //We have no active call. //Ask the user to accept the call or not. //if (MessageBox.Show("Call coming from " + msgReceived.strName + ".\r\n\r\nAccept it?", // "VoiceChat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) Program.secConv.Invoke((MethodInvoker) delegate { Program.secConv.gBCallIn.Visible = true; Program.secConv.LUserCallIn.Text = msgTable[1]; Program.secConv.gBChangePass.Enabled = false; Program.secConv.gBDelAcc.Enabled = false; }); Program.secConv.callerEndPoint = receivedFromEP; Program.secConv.isReceiver = true; //Program.secConv.Refresh(); } else { DeclineCall(receivedFromEP); } break; } //OK is received in response to an Invite. case (char)5: { //callOut.Close(); //Start a call. Program.secConv.Invoke((MethodInvoker) delegate { Program.secConv.timerCallOut.Stop(); }); InitializeCall(); break; } //Remote party is busy. case (char)6: //FAIL { player.Stop(); //send msg to DB with history string[] historyDetails = new string[3]; if (Program.secConv.isReceiver == false) //somebody call - you decline { Program.client = new SynchronousClient(Program.serverAddress); Program.secConv.Invoke((MethodInvoker) delegate { Program.secConv.timerCallOut.Stop(); Communique.CallState(Program.userLogin, Program.secConv.listView1.SelectedItems[0].Text, DateTime.Now, TimeSpan.Zero); historyDetails[0] = Program.secConv.listView1.SelectedItems[0].Text; }); Program.client.Disconnect(); //Communique.CallState(Program.userLogin, Program.secConv.LUserCallIn.Text, DateTime.Now, TimeSpan.Zero); } else //somebody call - somebody decline { historyDetails[0] = Program.secConv.LUserCallIn.Text; } //{ Program.secConv.isReceiver = false; //} //refresh user panel with histories historyDetails[1] = DateTime.Now.ToString(); historyDetails[2] = "nieodebrane"; Program.secConv.listView2.Items.Insert(0, (new ListViewItem(historyDetails))); Program.secConv.listView2.Refresh(); //disconect with server //close ring panel Program.secConv.Invoke((MethodInvoker) delegate { Program.secConv.gBCallIn.Visible = false; Program.secConv.gBChangePass.Enabled = true; Program.secConv.gBDelAcc.Enabled = true; }); if (Program.secConv.gBCallOut.Visible == true) { Program.secConv.Invoke((MethodInvoker) delegate { Program.secConv.gBCallOut.Visible = false; }); //CancelCall(); MessageBox.Show("Połączenie odrzucone.", "SecConv", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } break; } case (char)12: //BYE { //Check if the Bye command has indeed come from the user/IP with which we have //a call established. This is used to prevent other users from sending a Bye, which //would otherwise end the call. if (receivedFromEP.Equals(otherPartyEP) == true) { //tu zatrzymaj timer Program.secConv.timerConv.Stop(); //if (conv != null && !conv.IsDisposed) //{ // conv.Close(); //} //End the call. UninitializeCall(); } break; } } byteData = new byte[1024]; //Get ready to receive more commands. clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null); } catch (Exception) { //MessageBox.Show("Wystąpił problem podczas odbierania pakietów!", "OnReceive", MessageBoxButtons.OK, MessageBoxIcon.Error); } }