private void socketHelper_SocketDataReceived(string data) { if (socketHelper.IsHandshake) { BaseResponse <AccountInformation> response = JsonConvert.DeserializeObject <BaseResponse <AccountInformation> >(data); if (response != null && response.Status == 200) { this.accountInfo = response.Data; this.contacts = WebConnector.GetContactsData(accountInfo.Id); this.requests = WebConnector.GetAvailableRequests(accountInfo.Id); this.DisplayContactsAndRequests(); this.socketHelper.IsHandshake = false; this.socketHelper.IsAuthorized = true; this.UpdateClientMenu(true); } else { MessageBox.Show("An error occurred: " + response.ErrorMessage, "Error logging in", MessageBoxButtons.OK, MessageBoxIcon.Error); this.socketHelper.CloseConnection(); this.UpdateClientMenu(false); } return; } Message message = Message.CreateMessageObject(data); bool isCallContent = false; if (message == null || (message.Command.Equals("/disconnect") && message.Content.Equals("OK"))) { socketHelper.CloseConnection(); UpdateClientOnDisconnect(); return; } else if (message.Command.Equals(@"/online")) { string username = message.Content; ChangeOnlineStatus(username); return; } else if (message.Command.Equals(@"/request")) { RequestInformation request = null; try { //Console.WriteLine(message.Content); request = JsonConvert.DeserializeObject <RequestInformation>(message.Content); } catch (Exception ex) { Console.WriteLine("An error occurred while parsing request command: " + ex.Message); } if (request != null) { this.requests.Add(request); this.FillRequestsList(); } return; } else if (message.Command.Equals(@"/accept")) { AccountInformation contact = null; try { contact = JsonConvert.DeserializeObject <AccountInformation>(message.Content); } catch (Exception ex) { Console.WriteLine("An error occurred while parsing accept command: " + ex.Message); } if (contact != null) { this.contacts.ContactsList.Add(contact); this.AppendContact(contact); this.ChangeOnlineStatus(contact.Username); socketHelper.SendMessage(contact.Username, this.accountInfo.Username, this.accountInfo.Username, @"/online"); } return; } else if (message.Command.Equals(@"/offline")) { string username = message.Content; ChangeOnlineStatus(username); return; } else if (message.Command.Contains("call")) { isCallContent = true; // We set it to true to avoid dumping call ID's into the message box if (message.Command.Equals("/call")) { this.callSoundPlayer.PlayLooping(); MessengerContainer msgWindow = GetActiveMessengerContainer(message.Sender); if (msgWindow != null) { msgWindow.CreateCallDialog(message.Sender); msgWindow.callDialog.CallStateChanged += callDialog_CallStateChanged; } } else if (message.Command.Contains("/accept")) { MessengerContainer msgWindow = GetActiveMessengerContainer(message.Sender); if (msgWindow != null) { msgWindow.InitiatingCall = false; } this.socketHelper.EstablishCall(this.accountInfo.Username); } else if (message.Command.Contains("/close")) { if (this.socketHelper.CallHelper != null) { this.socketHelper.CloseCall(); } MessengerContainer msgWindow = GetActiveMessengerContainer(message.Sender); if (msgWindow != null) { msgWindow.InitiatingCall = false; msgWindow.UpdateCallState(); msgWindow.callDialog.CallStateChanged -= callDialog_CallStateChanged; } } } if (message.Content != string.Empty && !isCallContent) { if (message.Sender == this.accountInfo.Username) { this.DumpMessage(message, true); } else { this.DumpMessage(message); this.notificationSoundPlayer.Play(); SetContainerNotification(message.Sender); } } }