Add "reaction" event to CallParticipantModel observer

The CallParticipantModel observer now also emits one-time events that
are not reflected in the model state.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2023-05-04 05:42:51 +02:00 committed by Marcel Hibbe
parent 0a54fd6127
commit 92d655080d
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
7 changed files with 43 additions and 2 deletions

View File

@ -2861,6 +2861,10 @@ public class CallActivity extends CallBaseActivity {
addParticipantDisplayItem(callParticipantModel, "screen");
}
}
@Override
public void onReaction(String reaction) {
}
}
private class InternalSignalingMessageSender implements SignalingMessageSender {

View File

@ -34,7 +34,16 @@ public class ParticipantDisplayItem {
private final CallParticipantModel callParticipantModel;
private final CallParticipantModel.Observer callParticipantModelObserver = this::updateFromModel;
private final CallParticipantModel.Observer callParticipantModelObserver = new CallParticipantModel.Observer() {
@Override
public void onChange() {
updateFromModel();
}
@Override
public void onReaction(String reaction) {
}
};
private String userId;
private PeerConnection.IceConnectionState iceConnectionState;

View File

@ -42,6 +42,7 @@ public class CallParticipant {
@Override
public void onReaction(String reaction) {
callParticipantModel.emitReaction(reaction);
}
@Override

View File

@ -42,11 +42,15 @@ import java.util.Objects;
* Getters called after receiving a notification are guaranteed to provide at least the value that triggered the
* notification, but it may return even a more up to date one (so getting the value again on the following
* notification may return the same value as before).
*
* Besides onChange(), which notifies about changes in the model values, CallParticipantModel.Observer provides
* additional methods to be notified about one-time events that are not reflected in the model values, like reactions.
*/
public class CallParticipantModel {
public interface Observer {
void onChange();
void onReaction(String reaction);
}
protected class Data<T> {
@ -68,7 +72,7 @@ public class CallParticipantModel {
}
}
private final CallParticipantModelNotifier callParticipantModelNotifier = new CallParticipantModelNotifier();
protected final CallParticipantModelNotifier callParticipantModelNotifier = new CallParticipantModelNotifier();
protected final String sessionId;

View File

@ -83,4 +83,16 @@ class CallParticipantModelNotifier {
}
}
}
public synchronized void notifyReaction(String reaction) {
for (CallParticipantModelObserverOn observerOn : new ArrayList<>(callParticipantModelObserversOn)) {
if (observerOn.handler == null || observerOn.handler.getLooper() == Looper.myLooper()) {
observerOn.observer.onReaction(reaction);
} else {
observerOn.handler.post(() -> {
observerOn.observer.onReaction(reaction);
});
}
}
}
}

View File

@ -72,4 +72,8 @@ public class MutableCallParticipantModel extends CallParticipantModel {
public void setScreenMediaStream(MediaStream screenMediaStream) {
this.screenMediaStream.setValue(screenMediaStream);
}
public void emitReaction(String reaction) {
this.callParticipantModelNotifier.notifyReaction(reaction);
}
}

View File

@ -55,4 +55,11 @@ class CallParticipantModelTest {
callParticipantModel!!.setRaisedHand(true, 4815162342L)
Mockito.verify(mockedCallParticipantModelObserver, Mockito.only())?.onChange()
}
@Test
fun testEmitReaction() {
callParticipantModel!!.addObserver(mockedCallParticipantModelObserver)
callParticipantModel!!.emitReaction("theReaction")
Mockito.verify(mockedCallParticipantModelObserver, Mockito.only())?.onReaction("theReaction")
}
}