mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-30 09:49:26 +00:00
Correctly handle ClientGroupChatRoom subscriptions.
This commit is contained in:
parent
a194a9c77c
commit
f9363b1062
3 changed files with 51 additions and 18 deletions
|
|
@ -23,6 +23,7 @@
|
|||
#include "linphone/types.h"
|
||||
|
||||
#include "chat/chat-room/chat-room-id.h"
|
||||
#include "core/core-listener.h"
|
||||
#include "object/object-p.h"
|
||||
#include "remote-conference-event-handler.h"
|
||||
|
||||
|
|
@ -30,9 +31,15 @@
|
|||
|
||||
LINPHONE_BEGIN_NAMESPACE
|
||||
|
||||
class RemoteConferenceEventHandlerPrivate : public ObjectPrivate {
|
||||
class RemoteConferenceEventHandlerPrivate : public ObjectPrivate, public CoreListener {
|
||||
private:
|
||||
void simpleNotifyReceived (const std::string &xmlBody);
|
||||
void subscribe ();
|
||||
void unsubscribe ();
|
||||
|
||||
// CoreListener
|
||||
void onNetworkReachable (bool reachable) override;
|
||||
void onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const std::string &message) override;
|
||||
|
||||
ChatRoomId chatRoomId;
|
||||
|
||||
|
|
@ -40,6 +47,7 @@ private:
|
|||
LinphoneEvent *lev = nullptr;
|
||||
|
||||
unsigned int lastNotify = 0;
|
||||
bool subscriptionWanted = false;
|
||||
|
||||
L_DECLARE_PUBLIC(RemoteConferenceEventHandler);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -166,6 +166,43 @@ void RemoteConferenceEventHandlerPrivate::simpleNotifyReceived (const string &xm
|
|||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void RemoteConferenceEventHandlerPrivate::subscribe () {
|
||||
if (lev || !subscriptionWanted)
|
||||
return; // Already subscribed or application did not request subscription
|
||||
const string &peerAddress = chatRoomId.getPeerAddress().asString();
|
||||
LinphoneAddress *lAddr = linphone_address_new(peerAddress.c_str());
|
||||
lev = linphone_core_create_subscribe(conf->getCore()->getCCore(), lAddr, "conference", 600);
|
||||
lev->op->set_from(chatRoomId.getLocalAddress().asString().c_str());
|
||||
const string &lastNotifyStr = Utils::toString(lastNotify);
|
||||
linphone_event_add_custom_header(lev, "Last-Notify-Version", lastNotifyStr.c_str());
|
||||
linphone_address_unref(lAddr);
|
||||
linphone_event_set_internal(lev, TRUE);
|
||||
linphone_event_set_user_data(lev, this);
|
||||
lInfo() << "Subscribing to chat room: " << peerAddress << "with last notify: " << lastNotifyStr;
|
||||
linphone_event_send_subscribe(lev, nullptr);
|
||||
}
|
||||
|
||||
void RemoteConferenceEventHandlerPrivate::unsubscribe () {
|
||||
if (lev) {
|
||||
linphone_event_terminate(lev);
|
||||
lev = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void RemoteConferenceEventHandlerPrivate::onNetworkReachable (bool reachable) {
|
||||
if (!reachable)
|
||||
unsubscribe();
|
||||
}
|
||||
|
||||
void RemoteConferenceEventHandlerPrivate::onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const std::string &message) {
|
||||
if (state == LinphoneRegistrationOk)
|
||||
subscribe();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
RemoteConferenceEventHandler::RemoteConferenceEventHandler (RemoteConference *remoteConference) :
|
||||
Object(*new RemoteConferenceEventHandlerPrivate) {
|
||||
L_D();
|
||||
|
|
@ -182,25 +219,14 @@ RemoteConferenceEventHandler::~RemoteConferenceEventHandler () {
|
|||
void RemoteConferenceEventHandler::subscribe (const ChatRoomId &chatRoomId) {
|
||||
L_D();
|
||||
d->chatRoomId = chatRoomId;
|
||||
const string &peerAddress = d->chatRoomId.getPeerAddress().asString();
|
||||
LinphoneAddress *lAddr = linphone_address_new(peerAddress.c_str());
|
||||
d->lev = linphone_core_create_subscribe(d->conf->getCore()->getCCore(), lAddr, "conference", 600);
|
||||
d->lev->op->set_from(d->chatRoomId.getLocalAddress().asString().c_str());
|
||||
const string &lastNotify = Utils::toString(d->lastNotify);
|
||||
linphone_event_add_custom_header(d->lev, "Last-Notify-Version", lastNotify.c_str());
|
||||
linphone_address_unref(lAddr);
|
||||
linphone_event_set_internal(d->lev, TRUE);
|
||||
linphone_event_set_user_data(d->lev, this);
|
||||
lInfo() << "Subscribing to chat room: " << peerAddress << "with last notify: " << lastNotify;
|
||||
linphone_event_send_subscribe(d->lev, nullptr);
|
||||
d->subscriptionWanted = true;
|
||||
d->subscribe();
|
||||
}
|
||||
|
||||
void RemoteConferenceEventHandler::unsubscribe () {
|
||||
L_D();
|
||||
if (d->lev) {
|
||||
linphone_event_terminate(d->lev);
|
||||
d->lev = nullptr;
|
||||
}
|
||||
d->unsubscribe();
|
||||
d->subscriptionWanted = false;
|
||||
}
|
||||
|
||||
void RemoteConferenceEventHandler::notifyReceived (const string &xmlBody) {
|
||||
|
|
@ -246,5 +272,4 @@ void RemoteConferenceEventHandler::resetLastNotify () {
|
|||
setLastNotify(0);
|
||||
}
|
||||
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public:
|
|||
virtual ~CoreListener () = default;
|
||||
|
||||
virtual void onNetworkReachable (bool reachable) {}
|
||||
virtual void onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState cstate, const std::string &message) {}
|
||||
virtual void onRegistrationStateChanged (LinphoneProxyConfig *cfg, LinphoneRegistrationState state, const std::string &message) {}
|
||||
};
|
||||
|
||||
LINPHONE_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue