From b355bf21e6685a7f88b67d682a8ec761ba4ee4fc Mon Sep 17 00:00:00 2001 From: David Villasmil Date: Wed, 28 Jun 2023 18:39:22 +0200 Subject: [PATCH] [mod_conference] Add flag to destroy the conference only when all mandatory members disconnect. And set endconf to end the conference when any member with the flag disconnects (#2079) * feature/mod_conference_mandatory_member_flag: Add flag to destroy the conference only when all mandatory members disconnect. And set endconf to end the conference when any member with the flag disconnects --- src/mod/applications/mod_conference/conference_cdr.c | 3 +++ .../applications/mod_conference/conference_member.c | 12 +++++++++++- .../applications/mod_conference/conference_utils.c | 2 ++ src/mod/applications/mod_conference/mod_conference.c | 4 ++++ src/mod/applications/mod_conference/mod_conference.h | 1 + 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/mod/applications/mod_conference/conference_cdr.c b/src/mod/applications/mod_conference/conference_cdr.c index b6eb630540..f7ed7ddf27 100644 --- a/src/mod/applications/mod_conference/conference_cdr.c +++ b/src/mod/applications/mod_conference/conference_cdr.c @@ -662,6 +662,9 @@ void conference_cdr_render(conference_obj_t *conference) x_tag = switch_xml_add_child_d(x_flags, "end_conference", flag_off++); switch_xml_set_txt_d(x_tag, conference_cdr_test_mflag(np, MFLAG_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "mandatory_member_end_conference", flag_off++); + switch_xml_set_txt_d(x_tag, conference_cdr_test_mflag(np, MFLAG_MANDATORY_MEMBER_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "was_kicked", flag_off++); switch_xml_set_txt_d(x_tag, conference_cdr_test_mflag(np, MFLAG_KICKED) ? "true" : "false"); diff --git a/src/mod/applications/mod_conference/conference_member.c b/src/mod/applications/mod_conference/conference_member.c index 6112a2890c..c258e59783 100644 --- a/src/mod/applications/mod_conference/conference_member.c +++ b/src/mod/applications/mod_conference/conference_member.c @@ -766,7 +766,12 @@ switch_status_t conference_member_add(conference_obj_t *conference, conference_m conference->count++; } + if (conference_utils_member_test_flag(member, MFLAG_ENDCONF)) { + conference->endconference_time = 0; + } + + if (conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF)) { if (conference->end_count++) { conference->endconference_time = 0; } @@ -1314,9 +1319,14 @@ switch_status_t conference_member_del(conference_obj_t *conference, conference_m conference_video_check_flush(member, SWITCH_FALSE); + /* End conference when any member with "endconf" flag disconnects */ if (conference_utils_member_test_flag(member, MFLAG_ENDCONF)) { + conference_utils_set_flag_locked(conference, CFLAG_DESTRUCT); + } + + /* End conference only if all mandatory members have disconnected */ + if (conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF)) { if (!--conference->end_count) { - //conference_utils_set_flag_locked(conference, CFLAG_DESTRUCT); conference->endconference_time = switch_epoch_time_now(NULL); } } diff --git a/src/mod/applications/mod_conference/conference_utils.c b/src/mod/applications/mod_conference/conference_utils.c index c8dd0fd4e9..a441594ddc 100644 --- a/src/mod/applications/mod_conference/conference_utils.c +++ b/src/mod/applications/mod_conference/conference_utils.c @@ -132,6 +132,8 @@ void conference_utils_set_mflags(const char *flags, member_flag_t *f) f[MFLAG_NOMOH] = 1; } else if (!strcasecmp(argv[i], "endconf")) { f[MFLAG_ENDCONF] = 1; + } else if (!strcasecmp(argv[i], "mandatory_member_endconf")) { + f[MFLAG_MANDATORY_MEMBER_ENDCONF] = 1; } else if (!strcasecmp(argv[i], "mintwo")) { f[MFLAG_MINTWO] = 1; } else if (!strcasecmp(argv[i], "talk-data-events")) { diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index 619cd8c4a6..bf03d2a5bc 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -1347,6 +1347,9 @@ void conference_xlist(conference_obj_t *conference, switch_xml_t x_conference, i x_tag = switch_xml_add_child_d(x_flags, "end_conference", count++); switch_xml_set_txt_d(x_tag, conference_utils_member_test_flag(member, MFLAG_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "mandatory_member_end_conference", count++); + switch_xml_set_txt_d(x_tag, conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF) ? "true" : "false"); + x_tag = switch_xml_add_child_d(x_flags, "is_ghost", count++); switch_xml_set_txt_d(x_tag, conference_utils_member_test_flag(member, MFLAG_GHOST) ? "true" : "false"); @@ -1456,6 +1459,7 @@ void conference_jlist(conference_obj_t *conference, cJSON *json_conferences) ADDBOOL(json_conference_member_flags, "has_floor", member->id == member->conference->floor_holder); ADDBOOL(json_conference_member_flags, "is_moderator", conference_utils_member_test_flag(member, MFLAG_MOD)); ADDBOOL(json_conference_member_flags, "end_conference", conference_utils_member_test_flag(member, MFLAG_ENDCONF)); + ADDBOOL(json_conference_member_flags, "mandatory_member_end_conference", conference_utils_member_test_flag(member, MFLAG_MANDATORY_MEMBER_ENDCONF)); ADDBOOL(json_conference_member_flags, "pass_digits", conference_utils_member_test_flag(member, MFLAG_DIST_DTMF)); } switch_mutex_unlock(conference->member_mutex); diff --git a/src/mod/applications/mod_conference/mod_conference.h b/src/mod/applications/mod_conference/mod_conference.h index 3c28634264..21baaadc82 100644 --- a/src/mod/applications/mod_conference/mod_conference.h +++ b/src/mod/applications/mod_conference/mod_conference.h @@ -178,6 +178,7 @@ typedef enum { MFLAG_NO_MINIMIZE_ENCODING, MFLAG_FLUSH_BUFFER, MFLAG_ENDCONF, + MFLAG_MANDATORY_MEMBER_ENDCONF, MFLAG_HAS_AUDIO, MFLAG_TALKING, MFLAG_RESTART,