Skip to content

Commit b2989d3

Browse files
authored
Merge pull request #423 from simplito/fix/stream_api_internal_subscription_for_streamroomupdated
fix: streamApi internal subscription for streamRoomUpdated
2 parents 7b83535 + 985adf2 commit b2989d3

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

endpoint/stream/stream/src/StreamApiLowImpl.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,10 @@ void StreamApiLowImpl::processNotificationEvent(const core::NotificationEvent& n
101101
auto type {notification.type};
102102
LOG_DEBUG("StreamApiLowImpl::processNotificationEvent event type: "+ type);
103103
Poco::JSON::Object::Ptr data = notification.data.extract<Poco::JSON::Object::Ptr>();
104-
105104
auto subscriptionQuery = _subscriber.getSubscriptionQuery(notification.subscriptions);
106105
if(!subscriptionQuery.has_value()) {
107106
return;
108107
}
109-
110-
LOG_DEBUG("StreamApiLowImpl::processNotificationEvent Bridge Event: " + type + "\n" + privmx::utils::Utils::stringifyVar(notification.data, true));
111108
if (type == "streamRoomCreated") {
112109
auto raw = server::StreamRoomInfo::fromJSON(data);
113110
if(raw.type.value_or(std::string(STREAM_TYPE_FILTER_FLAG)) != STREAM_TYPE_FILTER_FLAG) {
@@ -124,13 +121,20 @@ void StreamApiLowImpl::processNotificationEvent(const core::NotificationEvent& n
124121
}
125122
auto eventData = decryptAndConvertStreamRoomDataToStreamRoom(raw);
126123
auto event = core::EventBuilder::buildEvent<StreamRoomUpdatedEvent, StreamRoom>("stream", eventData, notification);
127-
_eventMiddleware->emitApiEvent(event);
128-
//update keys
129124
auto streamRoomData = _streamRoomMap.get(eventData.streamRoomId);
125+
auto subscriptions = notification.subscriptions;
126+
//update keys
130127
if(streamRoomData.has_value()) {
131128
std::vector<stream::Key> keys = generateWebRTCKeysFromStreamRoomInfo(raw, streamRoomData.value()->encryptionKeyId);
132129
streamRoomData.value()->webRtc->updateKeys(eventData.streamRoomId, keys);
130+
for(const auto& internalSubscription : streamRoomData.value()->subscriptionsIds) {
131+
subscriptions.erase(remove(subscriptions.begin(), subscriptions.end(), internalSubscription), subscriptions.end());
132+
}
133+
}
134+
if(!_subscriber.getSubscriptionQuery(subscriptions).has_value()) {
135+
return;
133136
}
137+
_eventMiddleware->emitApiEvent(event);
134138
} else if (type == "streamRoomDeleted") {
135139
auto raw = server::StreamRoomDeletedEventData::fromJSON(data);
136140
if(raw.type.value_or(std::string(STREAM_TYPE_FILTER_FLAG)) != STREAM_TYPE_FILTER_FLAG) {
@@ -231,7 +235,8 @@ std::shared_ptr<privmx::endpoint::stream::StreamApiLowImpl::StreamRoomData> Stre
231235
webRtc->updateKeys(streamRoomId, keys);
232236
// setup event listener
233237
auto internalSubscriptionQuery {_subscriber.getInternalEventsSubscriptionQuery(streamRoomId)};
234-
std::vector<std::string> subscriptionsIds = _subscriber.subscribeFor({internalSubscriptionQuery}, true);
238+
auto updatedStreamRoom {_subscriber.buildQuery(EventType::STREAMROOM_UPDATE, EventSelectorType::STREAMROOM_ID, streamRoomId)};
239+
std::vector<std::string> subscriptionsIds = _subscriber.subscribeFor({internalSubscriptionQuery, updatedStreamRoom}, true);
235240
_eventMiddleware->notificationEventListenerAddSubscriptionIds(_notificationListenerId, subscriptionsIds);
236241
std::shared_ptr<StreamRoomData> streamRoomData = std::make_shared<StreamRoomData>(
237242
dataChannelMessageEncryptorV1,

0 commit comments

Comments
 (0)