Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
added audience level notification of room closure
Browse files Browse the repository at this point in the history
  • Loading branch information
khodzha committed Oct 26, 2020
1 parent 1e692c1 commit 67a3fb1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
5 changes: 3 additions & 2 deletions docs/src/api/room.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ If either
* the room was updated so that the closure datetime was moved from future into the past,
* the room was vacuumed

`room.close` event will be sent to room topic.
This event is not guaranteed to be unique, that is two `room.close` events could be sent by the service.
`room.close` event will be sent to room topic and tenant topics.
This event is not guaranteed to be unique for a room, that is two `room.close` events could be sent by the service.

**URI:** `rooms/:room_id/events`
**URI:** `audiences/:audience/events`

**Label:** `room.close`.

Expand Down
40 changes: 30 additions & 10 deletions src/app/endpoint/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,21 @@ impl RequestHandler for UpdateHandler {
let mut responses = vec![response, notification];

let append_closed_notification = || {
let closed_notification = helpers::build_notification(
responses.push(helpers::build_notification(
"room.close",
&format!("rooms/{}/events", room.id()),
room.clone(),
reqp,
context.start_timestamp(),
));

responses.push(helpers::build_notification(
"room.close",
&format!("audiences/{}/events", room.audience()),
room,
reqp,
context.start_timestamp(),
);
responses.push(closed_notification);
));
};

// Publish room closed notification
Expand Down Expand Up @@ -810,16 +817,29 @@ mod test {
.await
.expect("Room update failed");

assert_eq!(messages.len(), 3);
assert_eq!(messages.len(), 4);

let (closed_tenant_notification, _, _) = find_event_by_predicate::<JsonValue, _>(
messages.as_slice(),
|evp, _, topic| evp.label() == "room.close" && topic.contains("audiences"),
)
.expect("Failed to find room.close event");

assert_eq!(
closed_tenant_notification
.get("id")
.and_then(|v| v.as_str()),
Some(room.id().to_string()).as_deref()
);

let (closed_notification, _, _) =
find_event_by_predicate::<JsonValue, _>(messages.as_slice(), |evp, _| {
evp.label() == "room.close"
})
.expect("Failed to find room.close event");
let (closed_room_notification, _, _) = find_event_by_predicate::<JsonValue, _>(
messages.as_slice(),
|evp, _, topic| evp.label() == "room.close" && topic.contains("rooms"),
)
.expect("Failed to find room.close event");

assert_eq!(
closed_notification.get("id").and_then(|v| v.as_str()),
closed_room_notification.get("id").and_then(|v| v.as_str()),
Some(room.id().to_string()).as_deref()
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/endpoint/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ mod test {

assert_eq!(recording.status(), &RecordingStatus::InProgress);

find_event_by_predicate::<JsonValue, _>(&messages, |evp, p| {
find_event_by_predicate::<JsonValue, _>(&messages, |evp, p, _| {
evp.label() == "room.close"
&& p.get("id").and_then(|v| v.as_str())
== Some(rtc.room_id().to_string()).as_deref()
Expand Down
4 changes: 2 additions & 2 deletions src/test_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ pub(crate) fn find_event_by_predicate<P, F>(
) -> Option<(P, &OutgoingEventProperties, &str)>
where
P: DeserializeOwned,
F: Fn(&OutgoingEventProperties, P) -> bool,
F: Fn(&OutgoingEventProperties, P, &str) -> bool,
{
for message in messages {
if let OutgoingEnvelopeProperties::Event(evp) = message.properties() {
if f(evp, message.payload::<P>()) {
if f(evp, message.payload::<P>(), message.topic()) {
return Some((message.payload::<P>(), evp, message.topic()));
}
}
Expand Down

0 comments on commit 67a3fb1

Please sign in to comment.