Esempio n. 1
0
        //receiver methods

        public void AnswerCall()
        {
            if (ConnectedClient != null)
            {
                StreamWriter streamWriter = new StreamWriter(ConnectedClient.GetStream())
                {
                    AutoFlush = true
                };

                //odesłanie DH razem z komunikatem DH
                if (EncryptedCallReceiver)
                {
                    streamWriter.WriteLine(Commands.Ack + ":" + PrepareDHResponseString(DHRequest));
                }
                else
                {
                    streamWriter.WriteLine(Commands.Ack);
                }

                Trace.WriteLine("Ack");

                if (UDPSenderStart != null)
                {
                    UDPSenderStart.Invoke(remoteEndPointToSendVoice);
                }

                if (UDPListenerStart != null)
                {
                    UDPListenerStart.Invoke(localEndPoint);
                }
            }
        }
Esempio n. 2
0
        //sender methods

        public async void MakeCall(IPEndPoint endPoint, string userName, string receiverName)
        {
            Trace.WriteLine("username: "******"receiver: " + receiverName);

            if (!isCalling)
            {
                remoteEndPointToSendVoice = endPoint;

                isCalling = true;

                if (MakeCallEvent != null)
                {
                    MakeCallEvent.Invoke("Dzwonię do: " + receiverName);
                }

                try
                {
                    Connect(endPoint);
                    string localIp = (((IPEndPoint)hostTcpClient.Client.LocalEndPoint).Address.ToString());
                    if (EncryptedCallSender)
                    {
                        SendText(Commands.Invite + ":" + localIp + ":" + userName + ":" + PrepareDHRequestString());
                    }
                    else
                    {
                        SendText(Commands.Invite + ":" + localIp + ":" + userName);
                    }

                    while (isCalling)
                    {
                        var msg = await ReceiveTextAsync();

                        if (msg.StartsWith(Commands.Busy))
                        {
                            ErrorEvent.Invoke("Zajęte");
                            BusyUserInfoEvent.Invoke("Użytkownik jest w trakcie rozmowy!");
                        }
                        else if (msg.StartsWith(Commands.Reject))
                        {
                            BreakCall();
                        }
                        else if (msg.StartsWith(Commands.Ack))
                        {
                            var msgAfterSplit = msg.Split(new char[] { ':' }, 2);
                            if (msgAfterSplit.Length == 2)
                            {
                                DHServer.HandleResponse(msgAfterSplit[1]);
                                DHKey = DHServer.Key;
                            }

                            if (UDPSenderStart != null)
                            {
                                UDPSenderStart.Invoke(remoteEndPointToSendVoice);
                            }

                            if (UDPListenerStart != null)
                            {
                                UDPListenerStart.Invoke(localEndPoint);
                            }

                            //Akceptacja połączenia - zmiana gui
                            if (TalkEvent != null)
                            {
                                TalkEvent.Invoke(receiverName);
                            }
                        }
                        else
                        {
                            ErrorEvent.Invoke(msg);
                        }
                    }
                }
                catch (Exception e)
                {
                    isCalling = false;

                    if (ErrorEvent != null)
                    {
                        ErrorEvent.Invoke(e.Message);
                    }

                    if (EndCall != null)
                    {
                        EndCall.Invoke();
                    }
                }
            }
        }