def handle_conference_media_stop(self, conference_event):

        #checking for media stop event only when some media of this conference was playing, checking flag for this
        if self.playback_flag != "none":

            #if esl.get_play_status(self.conference_name):
            if "Nothing is playing" in esl.get_play_status(
                    self.conference_name):

                print('the media of my conference has stopped')
                now = datetime.datetime.now()
                now = now.strftime("%Y-%m-%d %H:%M:%S")

                print("[event listener cohort - " + self.cohort_id +
                      "]current audio of my conference thread has stopped")
                data = {
                    'objective': 'media_stopped',
                    'case': self.playback_flag,
                    'media_order': self.playback_orderno,
                    'show_id': self.show_id,
                    'conference_name': self.conference_name,
                    'timestamp': now
                }

                json_data = json.dumps(data)
                broadcaster_publisher.send(json_data, self.broadcaster_no, "1")

                mongo.insert_play_pause_stats(data)

                self.playback_flag = "none"
                self.playback_orderno = "-1"
    def handle_channel_answer(self, conference_event):
        phone_number = conference_event.getHeader("Caller-Caller-ID-Number",
                                                  -1)

        if phone_number:
            phone_number = phone_number[len(phone_number) -
                                        10:]  #removing the locale
            if phone_number in self.cohort_members:
                #print("My turn ,  cohort  no", self.cohort_id)

                #adding to the conference connected listeners list
                self.conference_connected_listeners.append(phone_number)
                #print("connected listeners are ", self.conference_connected_listeners)

                name = connectSQL.get_use_name(phone_number)

                #if name != 'none':
                #	data = {'objective' : 'conf_member_status', 'show_id' : self.show_id,'conference_name': self.conference_name, 'phoneno' : name , 'task' : 'online'}
                #else:
                data = {
                    'objective': 'conf_member_status',
                    'show_id': self.show_id,
                    'conference_name': self.conference_name,
                    'phoneno': phone_number,
                    'task': 'online'
                }

                json_data = json.dumps(data)
                broadcaster_publisher.send(json_data, self.broadcaster_no, "2")

                controller.insert_listener_show_call_logs(
                    "conference_listener_call_answer", self.show_id,
                    self.conference_name, phone_number, self.cohort_id)

            elif phone_number == self.broadcaster_no:
                #print("broadcaster number",  self.cohort_id)
                self.conference_connected_listeners.append(phone_number)
                #print("HOST ANSWER adding into the list", str(self.conference_connected_listeners))
                controller.insert_broadcaster_show_call_logs(
                    "conference_host_call_answer", self.show_id,
                    self.conference_name, phone_number, self.cohort_id, "none")

            #else:
#print("Not Mine, cohort  no", self.cohort_id)

        else:
            print("[event listener cohort - " + self.cohort_id +
                  "] no phone number captured")
    def stop(self):
        #esl.conference_recording_action(self.show_id, self.conference_name, "stop")
        #        del mainthread.show_thread_dict[self.broadcaster_no]
        print("[event listener cohort - " + self.cohort_id +
              "] removing my thread object from the dictionary")
        if self.broadcaster_no in self.show_thread_dict.keys():
            #print('length is ', len(self.show_thread_dict))

            mylock.acquire()
            del self.show_thread_dict[self.broadcaster_no]
            #print('length is ', len(self.show_thread_dict))
            mylock.release()

        data = {"objective": "end_show_call_ack", "info": "OK"}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data, self.broadcaster_no, "1")

        self._is_running = False
    def handle_mute_unmute(self, conference_event, action):

        phone_number = conference_event.getHeader("Caller-Caller-ID-Number",
                                                  -1)

        if phone_number:

            phone_number = phone_number[len(phone_number) - 10:]
            if phone_number in self.cohort_members:
                if action == "unmute-member":
                    #	            data = {'objective' : 'mute_unmute_result', 'body' : 'OK', }
                    data = {
                        'objective': 'mute_unmute_response',
                        'info': 'OK',
                        'listener_phoneno': phone_number
                    }
                    json_data = json.dumps(data)
                    broadcaster_publisher.send(json_data, self.broadcaster_no,
                                               "1")

                    if phone_number in self.dtmf_1_member_list:

                        controller.freeswitch_conf_mute_unmute_logging(
                            self.show_id, self.conference_name, self.cohort_id,
                            phone_number, "unmute", "yes")
                    else:
                        controller.freeswitch_conf_mute_unmute_logging(
                            self.show_id, self.conference_name, self.cohort_id,
                            phone_number, "unmute", "no")

                elif action == "mute-member":
                    if phone_number in self.dtmf_1_member_list:
                        self.dtmf_1_member_list.remove(phone_number)
                        data = {
                            'objective': 'mute_unmute_response',
                            'info': 'OK',
                            'listener_phoneno': phone_number
                        }
                        json_data = json.dumps(data)
                        broadcaster_publisher.send(json_data,
                                                   self.broadcaster_no, "1")
                        controller.freeswitch_conf_mute_unmute_logging(
                            self.show_id, self.conference_name, self.cohort_id,
                            phone_number, "mute", "yes")
                    else:

                        data = {
                            'objective': 'mute_unmute_response',
                            'info': 'OK',
                            'listener_phoneno': phone_number
                        }
                        json_data = json.dumps(data)
                        broadcaster_publisher.send(json_data,
                                                   self.broadcaster_no, "1")
                        controller.freeswitch_conf_mute_unmute_logging(
                            self.show_id, self.conference_name, self.cohort_id,
                            phone_number, "mute", "no")
import broadcaster_publisher

broadcaster_publisher.send("testdata.....")
    def handle_del_conf_member(self, conference_event):

        print("[event listener cohort - " + self.cohort_id +
              "]--- Member Delete  Case---")
        phone_number = conference_event.getHeader("Caller-Caller-ID-Number",
                                                  -1)

        if phone_number:
            phone_number = phone_number[len(phone_number) - 10:]

            if phone_number == self.broadcaster_no:
                if phone_number in self.conference_connected_listeners:
                    print("[event listener cohort - " + self.cohort_id +
                          "]HOST CALL DROPPED")
                    self.conference_connected_listeners.remove(phone_number)
                    #print("HOST present in the list, after removing", str(self.conference_connected_listeners))
                    if self.dial_listeners_flag == 1:
                        print("size of connected callers list",
                              len(self.conference_connected_listeners))
                        controller.insert_broadcaster_show_call_logs(
                            "conference_host_call_drop", self.show_id,
                            self.conference_name, phone_number, self.cohort_id,
                            "none")
                        print("[event listener cohort - " + self.cohort_id +
                              "]Redialling the host")
                        #if esl.check_conf_alive :

                        dial_result = esl.add_listener_to_conference(
                            phone_number, self.show_id, config.locale,
                            self.conference_name, self.cohort_id, "unmute",
                            "conference_host_redial", self.conf_recording_path,
                            self.show_thread_dict[self.broadcaster_no])
                        if dial_result == "none":
                            print(
                                "redialling failed at the freeswitch side, possible cause, the conference might have destroyed by the time this phone"
                            )
                        else:
                            esl.play_audio_conference(self.conference_name,
                                                      config.host_call_drop)

                    else:
                        print(
                            "[event listener cohort - " + self.cohort_id +
                            "] - no listeners has been called yet so not redialling the host"
                        )

            elif phone_number in self.cohort_members:
                #time.sleep(2)
                if esl.check_conf_alive(self.conference_name):

                    #checking whether listener was earlier in the connected listeners list or not, if yes then now it needs to be removed
                    if phone_number in self.conference_connected_listeners:
                        print("[event listener cohort - " + self.cohort_id +
                              "]Conference Member of my cohort dropped")
                        self.conference_connected_listeners.remove(
                            phone_number)

                        name = connectSQL.get_use_name(phone_number)

                        #if name != 'none':
                        # send data to broadcaster to deactivate asha
                        #    data = {"objective" : "conf_member_status", "phoneno" : name , "show_id" : self.show_id , "conference_name" : self.conference_name, "task" : "offline"}
                        #else:
                        data = {
                            "objective": "conf_member_status",
                            "phoneno": phone_number,
                            "show_id": self.show_id,
                            "conference_name": self.conference_name,
                            "task": "offline"
                        }

                        json_data = json.dumps(data)
                        broadcaster_publisher.send(json_data,
                                                   self.broadcaster_no, "2")

                        print("[event listener cohort - " + self.cohort_id +
                              "]Redialling")
                        if esl.check_conf_alive(self.conference_name):
                            dial_result = esl.add_listener_to_conference(
                                phone_number, self.show_id, config.locale,
                                self.conference_name, self.cohort_id, "mute",
                                "conference_redial", self.conf_recording_path,
                                self.show_thread_dict[self.broadcaster_no])
                            controller.insert_listener_show_call_logs(
                                "conference_listener_call_drop", self.show_id,
                                self.conference_name, phone_number,
                                self.cohort_id)
                            if dial_result == "none":
                                print(
                                    'redialling failed at the freeswitch side, possible cause, the conference might have destroyed by the time this phone no was being redialled to add into that conference'
                                )
                        else:
                            print(
                                "[event listener cohort - " + self.cohort_id +
                                "]on checking again the conference status, found destroyed , so not redialling"
                            )

        else:
            print("[event listener cohort - " + self.cohort_id +
                  "]conf member delete event--no phone number captured")
    def handle_key_press(self, conference_event):
        digit_pressed = conference_event.getHeader("DTMF-Digit", -1)
        #uuid = conference_event.getHeader("Caller-Unique-ID", -1);
        phone_number = conference_event.getHeader("Caller-Caller-ID-Number",
                                                  -1)
        #        phone_number = phone_number[len(phone_number)-10:] #removing the locale

        #log key pressed and its timestamp to database - Garima

        global polling_member_list, start_polling, stop_polling, polling_start_time, polling_stop_time, count_choice, count_1, count_2, count_3, count_4

        if phone_number:
            phone_number = phone_number[len(phone_number) - 10:]
            if phone_number in self.cohort_members:
                #if connectSQL.get_cohortID_from_phoneno(phone_number) == self.cohort_id:

                #check if dtmf is for query or quiz/polling activity
                if start_polling == True:

                    print('....Polling started....')

                    if not phone_number in polling_member_list:
                        if digit_pressed == '1':
                            count_1 = count_1 + 1
                            print('count_1 after assignment is %s',
                                  str(count_1))
                            polling_member_list.append(phone_number)
                            #log into database - Garima

                            data = {
                                'objective': 'get_polling_result_response',
                                'show_id': self.show_id,
                                'phoneno': phone_number,
                                'poll_id': poll_id,
                                'response': digit_pressed
                            }

                            json_data = json.dumps(data)
                            print(
                                '[event_listener_thread]\t Listener press 1 event: '
                                + str(json_data))

                            #broadcaster_publisher.send(json_data)
                            broadcaster_no = controller.get_broadcaster(
                                self.show_id)
                            broadcaster_publisher.send(json_data,
                                                       broadcaster_no, "1")

                            controller.polling(self.show_id, phone_number,
                                               digit_pressed, poll_id,
                                               'valid key')

                        elif digit_pressed == '2':
                            count_2 = count_2 + 1
                            print('count_2 after assignment is %s',
                                  str(count_2))
                            polling_member_list.append(phone_number)
                            #log into database - Garima

                            data = {
                                'objective': 'get_polling_result_response',
                                'show_id': self.show_id,
                                'phoneno': phone_number,
                                'poll_id': poll_id,
                                'response': digit_pressed
                            }
                            json_data = json.dumps(data)
                            print(
                                '[event_listener_thread]\t Listener press 1 event: '
                                + str(json_data))

                            #broadcaster_publisher.send(json_data)
                            broadcaster_no = controller.get_broadcaster(
                                self.show_id)
                            broadcaster_publisher.send(json_data,
                                                       broadcaster_no, "1")

                            controller.polling(self.show_id, phone_number,
                                               digit_pressed, poll_id,
                                               'valid key')

                        elif digit_pressed == '3':

                            if options == '4' or options == '3':
                                count_3 = count_3 + 1
                                polling_member_list.append(phone_number)
                                #logging the event into database
                                controller.polling(self.show_id, phone_number,
                                                   digit_pressed, poll_id,
                                                   'valid key')

                                data = {
                                    'objective': 'get_polling_result_response',
                                    'show_id': self.show_id,
                                    'phoneno': phone_number,
                                    'poll_id': poll_id,
                                    'response': digit_pressed
                                }
                                json_data = json.dumps(data)
                                print(
                                    '[event_listener_thread]\t Listener press 1 event: '
                                    + str(json_data))

                                #broadcaster_publisher.send(json_data)
                                broadcaster_no = controller.get_broadcaster(
                                    self.show_id)
                                broadcaster_publisher.send(
                                    json_data, broadcaster_no, "1")

                            elif options == '2':
                                logger.info('invalid digit pressed')
                                #logging the event into database
                                controller.polling(self.show_id, phone_number,
                                                   digit_pressed, poll_id,
                                                   'invalid key')

                        elif digit_pressed == '4':

                            if options == '4':
                                count_4 = count_4 + 1
                                polling_member_list.append(phone_number)
                                #logging the event into database

                                controller.polling(self.show_id, phone_number,
                                                   digit_pressed, poll_id,
                                                   'valid key')

                                data = {
                                    'objective': 'get_polling_result_response',
                                    'show_id': self.show_id,
                                    'phoneno': phone_number,
                                    'poll_id': poll_id,
                                    'response': digit_pressed
                                }
                                json_data = json.dumps(data)
                                print(
                                    '[event_listener_thread]\t Listener press 1 event: '
                                    + str(json_data))

                                #broadcaster_publisher.send(json_data)
                                broadcaster_no = controller.get_broadcaster(
                                    self.show_id)
                                broadcaster_publisher.send(
                                    json_data, broadcaster_no, "1")

                            elif options == '3' or options == '2':
                                logger.info('invalid digit pressed')
                                #logging the event into database
                                controller.polling(self.show_id, phone_number,
                                                   digit_pressed, poll_id,
                                                   'invalid key')

                        else:
                            logger.info('invalid digit pressed')
                            #logging the event into database
                            controller.polling(self.show_id, phone_number,
                                               digit_pressed, poll_id,
                                               'invalid key')

                    #invalid_entry_attemptee_list.append(phone_number)
                    #todo play sound to the user

        #sending polling responses to broadcaster - Garima

                    else:
                        print('person attempting again not allowed')
                        controller.polling(self.show_id, phone_number,
                                           digit_pressed, poll_id,
                                           'invalid attempt')

                else:
                    if digit_pressed == '1':
                        print("[event listener cohort - " + self.cohort_id +
                              "] \n---1 pressed!\n")
                        if not phone_number in self.dtmf_1_member_list:

                            #sending connected callers count to the broadcaster
                            data = {
                                'objective': 'press_1_event',
                                'show_id': self.show_id,
                                'conference_name': self.conference_name,
                                'phoneno': phone_number
                            }
                            json_data = json.dumps(data)
                            #                            print('[event_listener_thread]\t Listener press 1 event: ' + str(json_data))
                            broadcaster_publisher.send(json_data,
                                                       self.broadcaster_no,
                                                       "1")

                            #adding to the cache of listenere who did press 1 event
                            self.dtmf_1_member_list.append(phone_number)

                            #adding to the database
                            controller.insert_listeners_conference_dtmf_events(
                                "conference_listener_dtmf", self.show_id,
                                self.conference_name, self.cohort_id,
                                phone_number, digit_pressed, 'valid key')

                        else:
                            print('dtmf list is ',
                                  str(self.dtmf_1_member_list))
                            print("[event listener cohort - " +
                                  self.cohort_id +
                                  "] listener press 1 again in the same QA")
                            controller.insert_listeners_conference_dtmf_events(
                                "conference_listener_dtmf", self.show_id,
                                self.conference_name, self.cohort_id,
                                phone_number, digit_pressed, 'invalid attempt')

                    else:
                        print('invalid key')
                        controller.insert_listeners_conference_dtmf_events(
                            "conference_listener_dtmf", self.show_id,
                            self.conference_name, self.cohort_id, phone_number,
                            digit_pressed, 'invalid key')
Example #8
0
def callback_b_s(ch, method, properties, body):
    
    #print('packet eithout utf-8: ')
    
#    if isinstance(body, unicode):
#        print('unicode')    
#        print(str(body))
    try:
        incoming_json = json.loads(body.encode('utf-8'))
    except:
	print('error in encoding into utf-8')
	incoming_json = json.loads(body)

    print("msg received from broadcaster")    
    #print(incoming_json)
   # broadcaster_no = "xyz"
    # NETWORK COMMANDS

    msg = 'EMPTY'

    data = {'objective' : 'command_not_found'}
    # create a new show
    if incoming_json['objective'] == 'broadcaster_basic_info':
        if ctrl.update_broadcaster_database(incoming_json):
            msg = 'OK'
        else:
            msg = 'FAIL'
	json_data = json.dumps(data)
	broadcaster_publisher.send(json_data , broadcaster_no)

    elif incoming_json['objective'] == 'start_polling':
        broadcaster_no = ctrl.get_broadcaster(incoming_json['show_id'])
	event_listener_thread.start_polling = True
	event_listener_thread.options = incoming_json['no_options']
	event_listener_thread.pollid = incoming_json['poll_id']

	if ctrl.show_polling(incoming_json):
           msg = 'OK'
	else:
	   msg = 'FAIL'
        json_data = json.dumps(data)
	broadcaster_publisher.send(json_data , broadcaster_no,"1")

    elif incoming_json['objective'] == 'stop_polling':
 	broadcaster_no = incoming_json['broadcaster']
        event_listener_thread.stop_polling = True
        data = {'objective' : 'command_found'}
        json_data = json.dumps(data)
	broadcaster_publisher.send(json_data , broadcaster_no, "1")

    elif incoming_json['objective'] == 'flush_callers':

        broadcaster_no = incoming_json['broadcaster']
	ret_val = ctrl.flush_query(incoming_json)
        show_thread_dict[broadcaster_no].flush_dtmf_members_list()
        print('show thread data is ', show_thread_dict)
        msg = 'OK'
        data = {'objective' : 'flush_callers_ack', 'info': msg}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")


    elif incoming_json['objective'] == 'get_upcoming_show':
        cohort_id = incoming_json['cohort_id']

        show_id = connectSQL.get_upcoming_showID(cohort_id)
	if show_id != "none": 
            timeofairing = connectSQL.get_upcoming_show_time(cohort_id)
            topic =  connectSQL.get_upcoming_show_topic(cohort_id)
	    local_name = connectSQL.get_upcoming_show_localized_topic_name(cohort_id)
	    #local_name = unicode(local_name[0], encoding='utf-8')
            print('showid is '+show_id+'time '+timeofairing+' topic '+topic+'local name is'+local_name)

  	    data = {'objective' : 'upcoming_show_data', 'show_id' : show_id, 'time_of_airing' : timeofairing, 'topic' : topic, 'local_name' : local_name}

	else:
	    
  	    data = {'objective' : 'upcoming_show_data', 'show_id' : 'none', 'time_of_airing' : 'none', 'topic' : 'none', 'local_name' : 'none'}
  	

        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , incoming_json['broadcaster'], "2")

    elif incoming_json['objective'] == 'get_show_id_for_gallery':

        cohort_id = incoming_json['cohort_id']

        show_id = connectSQL.get_upcoming_showID(cohort_id)
        if show_id != "none":
            timeofairing = connectSQL.get_upcoming_show_time(cohort_id)

            topic =  connectSQL.get_upcoming_show_topic(cohort_id)
            print('showid is '+show_id+'time '+timeofairing+' topic '+topic)

	    content_id = connectSQL.get_contentID_for_show(show_id)
            print('content id is ', content_id)

            data = {'objective' : 'get_show_id_for_gallery_ack', 'show_id' : show_id, 'time_of_airing' : timeofairing, 'topic' : topic, 'content_id' : content_id}

        else:

            data = {'objective' : 'get_show_id_for_gallery_ack', 'show_id' : 'none', 'time_of_airing' : 'none', 'topic' : 'none'}
        print(str(data))

        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , incoming_json['broadcaster'], "2")


    elif incoming_json['objective'] == 'app_install_notify':
        broadcaster_no = incoming_json['broadcaster']

        cohort_id = ctrl.app_install(incoming_json)
        if cohort_id != "none":
	    size = ctrl.get_cohort_size(cohort_id)
	    if size != "none":
                data = {"objective" : "configuration_data", "cohort_id" : cohort_id, "cohort_size" : str(size)}
	    else:
		data = {"objective" : "configuration_data", "cohort_id" : cohort_id, "cohort_size" : "0"}
	else:
            data = {"objective" : "configuration_data", "cohort_id" : "-1", "cohort_size" : "-1"}

        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "2")
          

    elif incoming_json['objective'] == 'get_notifications':
	broadcaster_no = incoming_json['broadcaster']
        msg = ctrl.get_notification_data(incoming_json)
        if msg != "none":
	    data = {"objective" : "notify", "info" : msg}
	else:
	    data = {"objective" : "notify", "info" : "-1"}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "2")
        


    elif incoming_json['objective'] == 'play_show_media':
        broadcaster_no = incoming_json['broadcaster']
        if ctrl.play_content_audio(incoming_json):
            msg = 'OK'

        else:
            msg = 'FAIL'

        data = {"objective" : "play_show_media_ack", "info" : msg}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")
        
	#setting the media flag and order in the event listener thread of the conference
	show_thread_dict[broadcaster_no].set_playback_flag(incoming_json['type'], incoming_json['media_order'])
       

        #broadcaster_publisher.send(json_data , broadcaster_no)



    elif incoming_json['objective'] == 'pause_play_content':
        broadcaster_no = incoming_json['broadcaster']
        if ctrl.pause_play_audio(incoming_json):
            msg = 'OK'

        else:
            msg = 'FAIL'

            data = {"objective" : "pause_play_audio_ack", "info" : msg}
            json_data = json.dumps(data)
            broadcaster_publisher.send(json_data , broadcaster_no, "1")

        #broadcaster_publisher.send(json_data , broadcaster_no)

    elif incoming_json['objective'] == 'stop_content':
        broadcaster_no = incoming_json['broadcaster']
        if ctrl.stop_audio(incoming_json):
            msg = 'OK'
	else:
	    msg = 'FAIL'
	
	data = {"objective" : "stop_content_ack", "info" : msg}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")

        #broadcaster_publisher.send(json_data , broadcaster_no)


    # create a new show
    elif incoming_json['objective'] == 'create_show':
        if ctrl.create_show(incoming_json):
            msg = 'OK'
        else:
            msg = 'FAIL'        
        #broadcaster_publisher.send(json_data , broadcaster_no)


    # get show status if finished or not
    elif incoming_json['objective'] == 'get_show_status':        
        msg = ctrl.get_show_status(incoming_json['show_id'])
        # broadcaster_publisher.send(json_data , broadcaster_no)    
    # FREESWITCH COMMANDS

    # schedule the broadcast of the trailer and also add its entry in a new table for logging purpose
    elif incoming_json['objective'] == 'spread_word':        
        if ctrl.spread_word(incoming_json):
            msg = "OK"
        else:
            msg = "FAIL"

    # delete listener for a specific show and also add its entry in a new table for logging purpose
    elif incoming_json['objective'] == 'del_listener':
        if ctrl.del_listener(incoming_json):
            msg = "OK"
        else:
            msg = "FAIL"

        #broadcaster_publisher.send(json_data , broadcaster_no)
    # delete all listeners for a specific show and also add its entry in a new table for logging purpose
    elif incoming_json['objective'] == 'del_all_listener':
        if ctrl.del_all_listener(incoming_json):
            msg = "OK"
        else:
            msg = "FAIL"

    # check the status of trailer if it is uploaded or not
    elif incoming_json['objective'] == "check_trailer":
        if ctrl.check_trailer(incoming_json['show_id']):
            msg = "OK"
        else:
            msg = "FAIL"
            
    # broadcaster plays the trailer and sees if its correct or not
    elif incoming_json['objective'] == "play_trailer":
        if ctrl.play_trailer(incoming_json):
            msg = "OK"
        else:
            msg = "FAIL"

    # broadcaster deletes the trailer 
    elif incoming_json['objective'] == "delete_trailer":
        if ctrl.delete_trailer(incoming_json):
            msg = "OK"
        else:
            msg = "FAIL"

    # call the broadcaster
    elif incoming_json['objective'] == 'start_show':
	#broadcaster_no = ctrl.get_broadcaster(incoming_json['show_id'])
        broadcaster_no = incoming_json['broadcaster']
        cohort_id = incoming_json['cohort_id']
        print("start show request")

        now = datetime.datetime.now()
        now = now.strftime("%Y_%m_%d_%H_%M_%S")


	#creating directories to store the show recordings
	show_id = incoming_json['show_id']
        conf_name = show_id + '_' + now

        show_dir = fs_config.recording_dir + show_id 
        conf_dir = show_dir + "/" + conf_name
        recording_file_path = conf_dir + "/" + show_id
	
	
        if not os.path.exists(show_dir):
            os.makedirs(show_dir, 0755)
     
        if not os.path.exists(conf_dir):
            os.makedirs(conf_dir, 0755) 


        #if not os.path.exists(recording_file_path):
        #    os.makedirs(conf_dir, 0755)

           
	#calling the host person first
        if ctrl.call_conference_host(broadcaster_no,conf_name,recording_file_path):
	    print('CONF NAMEEEE is '+conf_name)
	    print('recording file path  is '+recording_file_path)

	    if broadcaster_no not in show_thread_dict.keys():
		print('CONF NAMEEEE is '+conf_name)            

                show_thread_dict[broadcaster_no] = event_listener_thread.EventListenerThread(incoming_json['show_id'], cohort_id, conf_name, broadcaster_no, show_thread_dict)
                show_thread_dict[broadcaster_no].start()
	        show_thread_dict[broadcaster_no].set_conf_recording_path(recording_file_path)
	        show_conf_recording_path_dict[broadcaster_no] = recording_file_path
                msg =  conf_name
	        mongo.insert_show_conference_timestamps(incoming_json)

        else:
            msg = "FAIL"          

        data = {'objective' : 'start_show_response', 'info' : msg}

        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")

    # call ashas
    elif incoming_json['objective'] == 'dial_listeners':
        broadcaster_no = incoming_json['broadcaster']
	cohort_id = incoming_json['cohort_id']
	print('broadcaster no is ', broadcaster_no)

        #checking is thread is alive to counter cases when the host killed the app and restarted at this stage
	if broadcaster_no in show_thread_dict.keys():
	    show_thread_dict[broadcaster_no].set_dial_listeners_flag()
	else:
	    print('thread has ended')


	get_cohort_members_name_phone_mapping = connectSQL.get_cohort_members_name_phone_mapping(cohort_id)
	json_array = {}
	for member in get_cohort_members_name_phone_mapping:
#	     json_array.append({member[0]:member[1]})
	    json_array[member[0]] = member[1]

        if ctrl.call_listener(incoming_json, show_conf_recording_path_dict[broadcaster_no]):

            msg = 'OK'
	    #show_thread_dict[broadcaster_no].set_dial_listeners_flag()
	    mongo.insert_show_conference_timestamps(incoming_json)
	    data = {'objective' : 'dial_listeners_response', 'cohort_members_phone_name_mapping' : json_array}
	
	else:
            msg = 'FAIL'
	    data = {'objective' : 'dial_listeners_response', 'info' : msg}

        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")


    #get playback content metadata
    elif incoming_json['objective'] == 'show_playback_metadata':
        broadcaster_no = incoming_json['broadcaster']
	data = ctrl.get_show_playback_metadata(incoming_json)
	#if data
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")


    # set asha mute/unmute 
    elif incoming_json['objective'] == 'mute':
        broadcaster_no = incoming_json['broadcaster']
        listener_phoneno = incoming_json['listener_phoneno']
	#to keep track of unmute mute multiple in same QA
        turn = incoming_json['turn'] 
	show_thread_dict[broadcaster_no].QA_recording_action(listener_phoneno, "stop", turn)
        
	if ctrl.mute_unmute(incoming_json):
            msg = 'OK'
        else:
            msg = 'FAIL'


        data = {'objective' : 'mute_unmute_ack', 'info' : msg, "listener_phoneno" : listener_phoneno}

        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")
	

    elif incoming_json['objective'] == 'unmute':
	broadcaster_no = incoming_json['broadcaster']
        listener_phoneno = incoming_json['listener_phoneno']
	turn = incoming_json['turn']
	print('turn is', str(turn))
        show_thread_dict[broadcaster_no].QA_recording_action(listener_phoneno, "start", turn)

        if ctrl.mute_unmute(incoming_json):
            msg = 'OK'
        else:
            msg = 'FAIL'

        data = {'objective' : 'mute_unmute_ack', 'info' : msg, "listener_phoneno" : listener_phoneno}

        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")


    elif incoming_json['objective'] == 'play_feedback':

        broadcaster_no = incoming_json['broadcaster']
        if ctrl.play_feedback_audio(incoming_json):
            msg = 'OK'

        else:
            msg = 'FAIL'

        data = {"objective" : "play_feedback_ack", "info" : msg}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")
        show_thread_dict[broadcaster_no].set_playback_flag("feedback")


    # get active participants
    elif incoming_json['objective'] == 'get_active_participants':
	broadcaster_no = ctrl.get_broadcaster(incoming_json['show_id'])
        participants = ctrl.get_active_participants(incoming_json)
        if participants:
            msg = participants
        else:
            msg = 'FAIL'


    elif incoming_json['objective'] == 'update_show_status':
	broadcaster_no = incoming_json['broadcaster']
	show_id = incoming_json['show_id']

        if ctrl.update_show_status(incoming_json):
            msg = 'OK'
        else:
            msg = 'FAIL'
        data = {"objective" : "update_show_status_ack", "info" : msg}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")
	portal.update_show_recordings_in_portal(show_id)
	


    # end the show  
    elif incoming_json['objective'] == 'end_show_call':
	broadcaster_no = incoming_json['broadcaster']
        show_id = incoming_json['show_id']
        conference_name = incoming_json['conference_name']
        cohort_id = incoming_json['cohort_id']

	#stopping the conference thread for this conference identified by the broadcaster number
	if broadcaster_no in show_thread_dict.keys():
            if ctrl.end_show_call(incoming_json):
                msg = 'OK'
	    else:
                msg = 'FAIL'
	    if show_thread_dict[broadcaster_no].is_alive():
                show_thread_dict[broadcaster_no].stop()
	    else:
	        print('Thread already crashed')
	else:
	    msg = 'OK'
	data = {"objective" : "end_show_call_ack", "info" : msg}
	json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "1")
	#porting statistics computation to portal to avoid crashing of the server
#	show_statistics.compute_show_stats(show_id,conference_name, cohort_id)

    elif incoming_json['objective'] == 'broadcaster_content_listen_event':

        broadcaster_no = incoming_json['broadcaster']
	packet_id = incoming_json['packet_id']
        if ctrl.log_broadcaster_content_listen_data(incoming_json):
            msg = 'OK'
        else:
            msg = 'FAIL'

        data = {"objective" : "broadcaster_content_listen_event_ack", "info" : msg, "packet_id" : packet_id}
        json_data = json.dumps(data)
        broadcaster_publisher.send(json_data , broadcaster_no, "2")