Exemplo n.º 1
0
 def reject_contact(self, username):
     """
     Rejects a contact request.
     :param username: str, the name of the user who asked to be contacts.
     """
     reject_contact_message = Common_Elements.RejectContactMessage(username)
     self.send_message(reject_contact_message)
Exemplo n.º 2
0
 def __init__(self):
     """
     Constructs a CommunicationHandler object and its AESCipher object which
     allows it to encrypt and decrypt messages.
     """
     super(Common_Elements.BasicCommunicator, self).__init__()
     self.cipher = Common_Elements.AESCipher()  # prevent crash
Exemplo n.º 3
0
 def stop_calling_user(self, username):
     """
     Send a user a message that tells him that this client stopped calling him through the server.
     :param username: str, the name of the user who stopped being called.
     """
     stop_calling_message = Common_Elements.StopCallingMessage(username)
     self.send_message(stop_calling_message)
Exemplo n.º 4
0
 def accept_contact(self, username):
     """
     Accepts a contact request.
     :param username: str, the name of the user who asked to be contacts.
     """
     accept_contact_message = Common_Elements.AcceptContactMessage(username)
     self.send_message(accept_contact_message)
Exemplo n.º 5
0
 def reject_current_call(self):
     """
     Rejects the last call that the user got.
     This function will only be summoned after the user got a CalledByMessage.
     """
     reject_call_message = Common_Elements.RejectCallMessage()
     self.send_message(reject_call_message)
Exemplo n.º 6
0
 def send_successful_register_message(self, client_socket):
     """
     Sends a message that informs a user about a successful register.
     :param client_socket: socket, the socket of the registering user.
     """
     successful_register_message = Common_Elements.SuccessfulRegisterMessage()
     self.send_full_message(client_socket, successful_register_message)
Exemplo n.º 7
0
 def close_communication(self):
     """
     Sends a message to the server that informs about the closing of the communication and
     closes the socket.
     """
     disconnect_message = Common_Elements.DisconnectMessage()
     self.send_message(disconnect_message)
     self.client_socket.close()
Exemplo n.º 8
0
 def request_delete_contact(self, contact_name):
     """
     Requests the server to delete a contact.
     :param contact_name: str, the name of the contact.
     """
     delete_contact_message = Common_Elements.DeleteContactMessage(
         contact_name)
     self.send_message(delete_contact_message)
Exemplo n.º 9
0
 def request_add_contact(self, username):
     """
     Requests the server to add a contact.
     :param username: str, the name of the user who needs to be asked to be a contact.
     """
     request_add_contact_message = Common_Elements.RequestAddContactMessage(
         username)
     self.send_message(request_add_contact_message)
Exemplo n.º 10
0
 def ask_for_user_information(self, username):
     """
     Sends a message to the server that asks to get the information about a specific user.
     :param username: str, the username of the user.
     """
     request_user_info_message = Common_Elements.RequestUserInformationMessage(
         username)
     self.send_message(request_user_info_message)
Exemplo n.º 11
0
 def send_new_open_ports_message(self, new_open_ports):
     """
     Informs the server about new open ports.
     :param new_open_ports: [ports], a list of newly open ports.
     """
     new_open_ports_message = Common_Elements.NewOpenPortsMessage(
         new_open_ports)
     self.send_message(new_open_ports_message)
Exemplo n.º 12
0
 def accept_current_call(self):
     """
     Accepts the last call that the user got.
     This function will only be summoned after the user got a CalledByMessage.
     """
     accept_call_message = Common_Elements.AcceptCallMessage()
     self.send_message(accept_call_message)
     print "DEBUG - accepted call"
Exemplo n.º 13
0
 def send_calling_failed_message(self, client_socket, error_message):
     """
     Inform a user about a failed calling attempt.
     :param client_socket: socket, the socket of the user who started calling
     :param error_message: str, the error message.
     """
     calling_failed_message = Common_Elements.CallingFailedMessage(error_message)
     self.send_full_message(client_socket, calling_failed_message)
Exemplo n.º 14
0
 def send_login_failed_message(self, client_socket, message):
     """
     Informs a client about a failed login.
     :param client_socket: socket, the socket of the client who tried to log in
     :param message: str, the error message that will be shown to the client
     """
     failed_login_message = Common_Elements.LoginFailedMessage(message)
     self.send_full_message(client_socket, failed_login_message)
Exemplo n.º 15
0
 def send_popup_message(self, client_socket, message):
     """
     Pop up a message for a specific user.
     :param client_socket: socket, the socket of the user
     :param message: str, the message that will be displayed to the user.
     """
     popup_message = Common_Elements.PopupMessage(message)
     self.send_full_message(client_socket, popup_message)
Exemplo n.º 16
0
 def send_user_went_offline_message_to_all_contacts(self, connected_contacts_list, username):
     """
     Informs the contacts of a user that the user has disconnected.
     :param connected_contacts_list: [User], a list of the user's contacts.
     :param username: str, the name of the connected user.
     """
     contact_went_offline_message = Common_Elements.ContactWentOfflineMessage(username)
     self.broadcast_message_to_users_list(connected_contacts_list, contact_went_offline_message)
Exemplo n.º 17
0
 def send_asked_to_be_contact_message(self, client_socket, asked_by_username):
     """
     Informs a user that another user asked to add him as a contact.
     :param client_socket: socket, the socket of the asked user.
     :param asked_by_username: str, the name of the asking user.
     """
     asked_to_be_contact_message = Common_Elements.AskedToBeContactMessage(asked_by_username)
     self.send_full_message(client_socket, asked_to_be_contact_message)
Exemplo n.º 18
0
 def send_failed_register_message(self, client_socket, message):
     """
     Sends a message that informs a user about a failed register.
     :param client_socket: socket, the socket of the registering user.
     :param message: str, the error message.
     """
     register_failed_message = Common_Elements.RegisterFailedMessage(message)
     self.send_full_message(client_socket, register_failed_message)
Exemplo n.º 19
0
 def send_delete_contact_message(self, client_socket, contact_name):
     """
     Tells a user to delete a contact.
     :param client_socket: socket, the socket of the user.
     :param contact_name: str, the name of the contact.
     """
     delete_contact_message = Common_Elements.DeleteContactMessage(contact_name)
     self.send_full_message(client_socket, delete_contact_message)
Exemplo n.º 20
0
 def send_call_rejected_message(self, called_user, actual_calling_user):
     """
     Informs calling users about a call reject via a CallRejectedMessage
     :param called_user: User, the user who is being called
     :param actual_calling_user: User, the user who actually started the call.
     """
     call_rejected_message = Common_Elements.CallRejectedMessage()
     self.send_full_message(actual_calling_user.client_socket, call_rejected_message)
     called_user.stop_being_called()
Exemplo n.º 21
0
 def relay_request_call_message(self, called_user, participant_names, call_group_name, host_name, not_in_call_members):
     """
     relays a request call message to the called user.
     :param called_user: User, the user who is being called
     :param participant_names:  [str], the names of the current voice chat participants
     """
     called_user.start_being_called(participant_names, call_group_name, host_name, not_in_call_members)
     called_by_message = Common_Elements.CalledByMessage(participant_names, call_group_name)
     self.send_full_message(called_user.client_socket, called_by_message)
Exemplo n.º 22
0
 def request_join_call(self, call_group_name, host_name):
     """
     Requests the server to join a call which this client is already a part of its call group.
     :param call_group_name: str, the name of the call group.
     :param host_name: str, the name of the host of the call.
     """
     request_join_call_message = Common_Elements.RequestJoinCallMessage(
         call_group_name, host_name)
     self.send_message(request_join_call_message)
Exemplo n.º 23
0
 def broadcast_participant_changed_picture_message(self, participants_list, username, encoded_picture_bytes):
     """
     Informs all participants of a user's voice chat that the user changed his profile picture.
     :param participants_list: [User], a list of the users who are in a voice chat with said user.
     :param username: str, the name of the user.
     :param encoded_picture_bytes: str, the bytes of the new picture encoded in base64.
     """
     participant_changed_picture_message = Common_Elements.ParticipantChangedPictureMessage(username, encoded_picture_bytes)
     self.broadcast_message_to_users_list(participants_list, participant_changed_picture_message)
Exemplo n.º 24
0
 def send_contact_changed_picture_message_to_all_contacts(self, connected_contacts_list, username, encoded_picture_bytes):
     """
     Informs all contacts of a user that the user changed his profile picture.
     :param connected_contacts_list: [User], a list of the user's contacts.
     :param username: str, the name of the user.
     :param encoded_picture_bytes: str, the bytes of the new picture encoded in base64.
     """
     contact_changed_picture_message = Common_Elements.ContactChangedPictureMessage(username, encoded_picture_bytes)
     self.broadcast_message_to_users_list(connected_contacts_list, contact_changed_picture_message)
Exemplo n.º 25
0
 def send_add_contacts_message(self, client_socket, contact_info_list):
     """
     Tells a user to add another user as a contact.
     :param client_socket: socket, the socket of the user.
     :param contact_info_list: [ContactInfo], a list of ContactInfo object which conatain information about
     the new contact.
     """
     add_contact_message = Common_Elements.AddContactsMessage(contact_info_list)
     self.send_full_message(client_socket, add_contact_message)
Exemplo n.º 26
0
 def send_stop_being_called_message(self, called_user):
     """
     Sends a message that informs a user that he is not being called anymore so
     his choice to accept / reject the call would do nothing.
     :param called_user: User, the user who is no longer being called.
     """
     stop_being_called_message = Common_Elements.StopBeingCalledMessage()
     self.send_full_message(called_user.client_socket, stop_being_called_message)
     called_user.stop_being_called()
Exemplo n.º 27
0
 def send_p2p_call_message_to_calling_users(self, calling_users_peers_dict, call_name):
     """
     Handles the sending of all CallMessages to the calling users in order to
     let them start a call with the new participant.
     Also distinguishes between the need to start a completely new call or the need to just add
     a new participant to an already existing call.
     :param calling_users_peers_dict: {calling_user(User):VoiceChatPeer}, a dictionary that contains the calling
     users as keys and VoiceChatPeer objects of the called user as values.
     :param call_name: str, the name of the call group.
     """
     if len(calling_users_peers_dict) == 1:  # only one caller, should start new call
         calling_user = calling_users_peers_dict.keys()[0]
         calling_user_start_call_message = Common_Elements.StartNewCallMessage([calling_users_peers_dict[calling_user]], call_name)
         self.send_full_message(calling_user.client_socket, calling_user_start_call_message)
     else:  # multiple participants, should add new participant
         for calling_user in calling_users_peers_dict.keys():
             calling_user_add_participant_message = Common_Elements.AddParticipantToCallMessage(calling_users_peers_dict[calling_user], call_name)
             self.send_full_message(calling_user.client_socket, calling_user_add_participant_message)
Exemplo n.º 28
0
 def send_invited_to_call_message(self, called_user, call_name, in_call_participants):
     """
     Informs the user about an invite to join a call when he is already a part of the call's group.
     :param called_user: User, the user who is invited to the call.
     :param call_name: str, the name of the call.
     :param in_call_participants: [str], the names of all the participants who are in the call.
     """
     invited_to_call_message = Common_Elements.InvitedToCallMessage(call_name, in_call_participants)
     self.send_full_message(called_user.client_socket, invited_to_call_message)
Exemplo n.º 29
0
 def relay_call_join_request(self, call_name, group_host, requesting_username):
     """
     Sends a request to join an existing call by a call group member.
     :param call_name: str, the name of the call group.
     :param group_host: str, the name of the call host.
     :param requesting_username: str, the username of the requesting user
     """
     group_member_requested_join_message = Common_Elements.GroupMemberRequestedJoinMessage(call_name, requesting_username)
     self.send_full_message(group_host.client_socket, group_member_requested_join_message)
Exemplo n.º 30
0
 def send_remove_group_member_message(self, call_name, other_group_members_list, remove_username):
     """
     Instructs all group members to remove a user from the group.
     :param call_name: str, the name of the call group
     :param other_group_members_list: [User], a list of all the group members
     :param remove_username: str, the name of the user who should be removed.
     """
     remove_group_member_message = Common_Elements.RemoveGroupMemberMessage(call_name, remove_username)
     self.broadcast_message_to_users_list(other_group_members_list, remove_group_member_message)