def send_call_messages_for_call_start(self, called_user, calling_users, call_name, database_access): """ Handles the sending of all CallMessage object to allow a new voice chat call. This function uniquely requires access to the database in order to send user pictures. :param called_user: User, the user who is being called. :param calling_users: [User], list of the calling users (the calling user and the users who are already in a call with him). :param call_name: str, the name of the call group that the voice chat belongs to. :param database_access: DataBaseHandler, access to the database object. """ called_user_peers_list, calling_users_peers_dict = database_access.create_voice_chat_peers(called_user, calling_users) self.send_p2p_call_message_to_calling_users(calling_users_peers_dict, call_name) called_user_start_call_message = Common_Elements.StartNewCallMessage(called_user_peers_list, call_name) self.send_full_message(called_user.client_socket, called_user_start_call_message)
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)