local-conference-event-handler.cpp 5.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
/*
 * local-conference-event-handler.cpp
 * Copyright (C) 2017  Belledonne Communications SARL
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "local-conference-event-handler.h"
#include "conference-info.hxx"
#include "private.h"

using namespace std;
using namespace conference_info;
using namespace LinphonePrivate;

class Conference::LocalConferenceEventHandlerPrivate : public ObjectPrivate {
public:
	void notifyFullState(string notify, LinphoneEvent *lev);
	void notifyAllExcept(string notify, LinphoneAddress *addr);

	LocalConference *conf;
	LinphoneCore *lc;
};

void Conference::LocalConferenceEventHandlerPrivate::notifyFullState(string notify, LinphoneEvent *lev) {
	LinphoneContent* content = linphone_core_create_content(lev->lc);
	linphone_content_set_buffer(content,notify.c_str(),strlen(notify.c_str()));
	linphone_event_notify(lev, content);
	linphone_content_unref(content);
	// linphone_event_unref(lev); ??
}

void Conference::LocalConferenceEventHandlerPrivate::notifyAllExcept(string notify, LinphoneAddress *addr) {
	for(auto participant : conf->getParticipants()) {
		if(!linphone_address_equal(participant.getAddress(), addr)) {
			LinphoneEvent *lev = linphone_core_create_notify(lc, participant.getAddress(), "Conference");
			LinphoneContent* content = linphone_core_create_content(lev->lc);
			linphone_content_set_buffer(content,notify.c_str(),strlen(notify.c_str()));
			linphone_event_notify(lev, content);
			linphone_content_unref(content);
			linphone_event_unref(lev);
		}
	}
}

// -------- Conference::LocalConferenceEventHandler public methods ---------
Benjamin REIS's avatar
Benjamin REIS committed
58
Conference::LocalConferenceEventHandler::LocalConferenceEventHandler(LinphoneCore *core, LocalConference *localConf) : Object(*new LocalConferenceEventHandlerPrivate) {
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
	L_D(LocalConferenceEventHandler);
	xercesc::XMLPlatformUtils::Initialize();
	d->conf = localConf;
	d->lc = core; // conf->getCore() ?
}

Conference::LocalConferenceEventHandler::~LocalConferenceEventHandler() {
	xercesc::XMLPlatformUtils::Terminate();
}

string Conference::LocalConferenceEventHandler::subscribeReceived(LinphoneEvent *lev) {
	L_D(LocalConferenceEventHandler);
	char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
	Conference_type confInfo = Conference_type(entity);
	Users_type users;
	confInfo.setUsers(users);
	stringstream notify;
	xml_schema::NamespaceInfomap map;

	map[""].name = "urn:ietf:params:xml:ns:conference-info";
	for(auto participant : d->conf->getParticipants()) {
		User_type user = User_type();
		User_roles_type roles;
		user.setRoles(roles);
		user.setEntity(linphone_address_as_string_uri_only(participant.getAddress()));
		user.getRoles()->getEntry().push_back(participant.isAdmin() ? "admin" : "participant");
		user.setState("full");
		confInfo.getUsers()->getUser().push_back(user);
	}

	serializeConference_info(notify, confInfo, map);
	//d->notifyFullState(notify.str(), lev);
	return notify.str();
}

string Conference::LocalConferenceEventHandler::notifyParticipantAdded(LinphoneAddress *addr) {
	L_D(LocalConferenceEventHandler);
	char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
	Conference_type confInfo = Conference_type(entity);
	Users_type users;
	confInfo.setUsers(users);
	stringstream notify;
	xml_schema::NamespaceInfomap map;

	User_type user = User_type();
	User_roles_type roles;
	user.setRoles(roles);
	user.setEntity(linphone_address_as_string_uri_only(addr));
	user.getRoles()->getEntry().push_back("participant");
	user.setState("full");
	confInfo.getUsers()->getUser().push_back(user);

	serializeConference_info(notify, confInfo, map);
	//d->notifyAllExcept(notify.str(), addr);
	return notify.str();
}

string Conference::LocalConferenceEventHandler::notifyParticipantRemoved(LinphoneAddress *addr) {
	L_D(LocalConferenceEventHandler);
	char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
	Conference_type confInfo = Conference_type(entity);
	Users_type users;
	confInfo.setUsers(users);
	stringstream notify;
	xml_schema::NamespaceInfomap map;

	User_type user = User_type();
	user.setEntity(linphone_address_as_string_uri_only(addr));
	user.setState("deleted");
	confInfo.getUsers()->getUser().push_back(user);

	serializeConference_info(notify, confInfo, map);
	//d->notifyAllExcept(notify.str(), addr);
	return notify.str();
}

string Conference::LocalConferenceEventHandler::notifyParticipantSetAdmin(LinphoneAddress *addr, bool isAdmin) {
	L_D(LocalConferenceEventHandler);
	char *entity = linphone_address_as_string_uri_only(d->conf->getAddress());
	Conference_type confInfo = Conference_type(entity);
	Users_type users;
	confInfo.setUsers(users);
	stringstream notify;
	xml_schema::NamespaceInfomap map;

	User_type user = User_type();
	User_roles_type roles;
	user.setRoles(roles);
	user.setEntity(linphone_address_as_string_uri_only(addr));
	user.getRoles()->getEntry().push_back(isAdmin ? "admin" : "participant");
	user.setState("partial");
	confInfo.getUsers()->getUser().push_back(user);

	serializeConference_info(notify, confInfo, map);
	//d->notifyAllExcept(notify.str(), addr);
	return notify.str();
}