示例#1
0
 void timerHandshakeTimeout_Elapsed(object sender, ElapsedEventArgs e)
 {
     timerHandshakeTimeout.Stop();
     timerHandshakeTimeout.Enabled = false;
     connected = false;
     if (OnStateChange != null)
     {
         ConnectionStateChangeEventArgs cscea = new ConnectionStateChangeEventArgs(false);
         OnStateChange(this, cscea);
     }
     //Console.WriteLine("Connection to furiko-server is lost: Timeout");
 }
示例#2
0
        public void getFurikoResponse(Message msg)
        {
            if (msg.From.Bare == Util.FurikoJID)
            {
                FurikoResponse fr;
                try
                {
                    fr = JsonConvert.DeserializeObject<FurikoResponse>(msg.Body);
                }
                catch (JsonReaderException e)
                {
                    Console.WriteLine("!! JsonReaderException: {0}", e);
                    return;
                }
                //fr = JsonConvert.DeserializeObject<FurikoResponse>(msg.Body);
                switch (fr.Action)
                {
                    case "Handshake":
                        if (fr.Success)
                        {
                            Console.WriteLine("Successfully handshaked with {0}", Util.FurikoJID);
                            connected = true;
                            timerHandshakeTimeout.Enabled = false;
                            if (OnStateChange != null)
                            {
                                ConnectionStateChangeEventArgs cscea = new ConnectionStateChangeEventArgs(true);
                                OnStateChange(this, cscea);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Error handshaking with {0}", Util.FurikoJID);
                            // wait 30 sec and
                            // then send HandshakeAction
                        }
                        break;
                    case "History":
                        if (fr.Success)
                        {
                            //HistoryEventArgs e = new HistoryEventArgs(f);
                            Console.WriteLine("History recieved: {0}", msg.Body);
                            HistoryResponse hr = JsonConvert.DeserializeObject<HistoryResponse>(msg.Body);
                            HistoryEventArgs hea = new HistoryEventArgs(hr);
                            if (OnHistoryRecieved != null)
                                OnHistoryRecieved(this, hea);
                        }
                        else
                        {
                            Console.WriteLine("Error getting history with {0}", Util.FurikoJID);
                        }
                        break;
                    case "OutgoingCall":
                        OutgoingCallResponse ocr = JsonConvert.DeserializeObject<OutgoingCallResponse>(msg.Body);
                        Console.WriteLine("OutgoingCall response recieved");
                        OutgoingCallEventArgs ocea = new OutgoingCallEventArgs(ocr);
                        if (OnOutgoingCallRecieved != null)
                            OnOutgoingCallRecieved(this, ocea);
                        break;
                    case "BridgeEvent":
                        if (fr.Success)
                        {
                            BridgeEvent be = JsonConvert.DeserializeObject<BridgeEvent>(msg.Body);
                            BridgeEventArgs e = new BridgeEventArgs(be);
                            if (OnBridgeEvent != null)
                                OnBridgeEvent(this, e);
                        }
                        break;
                    case "HangupEvent":
                        if (fr.Success)
                        {
                            HangupEvent he = JsonConvert.DeserializeObject<HangupEvent>(msg.Body);
                            HangupEventArgs e = new HangupEventArgs(he);
                            if (OnHangupEvent != null)
                                OnHangupEvent(this, e);
                        }
                        break;
                    case "IncomingCallEvent":
                        if (fr.Success)
                        {
                            IncomongCallEvent ice = JsonConvert.DeserializeObject<IncomongCallEvent>(msg.Body);
                            IncomingCallEventArgs e = new IncomingCallEventArgs(ice);
                            if (OnIncomingCallRecieved != null)
                                OnIncomingCallRecieved(this, e);
                        }
                        break;
                    case "TransferCall":
                        if (fr.Success)
                        {
                            TransferCallEvent tce = JsonConvert.DeserializeObject<TransferCallEvent>(msg.Body);
                            TransferCallEventArgs e = new TransferCallEventArgs(tce);

                            if (OnTransferCallRecieved != null)
                                OnTransferCallRecieved(this, e);
                        }
                        break;
                    default:
                        Console.WriteLine("Default case");
                        break;
                }
            }
        }