Skip to content

Commit

Permalink
Send state also through signaling messages
Browse files Browse the repository at this point in the history
The speaking state is still sent only through data channels, as it is
not currently handled by other clients when sent through signaling
messages.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Dec 19, 2024
1 parent bd5e96c commit 6bfe01b
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package com.nextcloud.talk.call;

import com.nextcloud.talk.models.json.signaling.DataChannelMessage;
import com.nextcloud.talk.models.json.signaling.NCMessagePayload;
import com.nextcloud.talk.models.json.signaling.NCSignalingMessage;

import java.util.Objects;

Expand Down Expand Up @@ -42,6 +44,7 @@ public void onChange() {
audioEnabled = localCallParticipantModel.isAudioEnabled();

messageSender.sendToAll(getDataChannelMessageForAudioState());
messageSender.sendToAll(getSignalingMessageForAudioState());
}

if (!Objects.equals(speaking, localCallParticipantModel.isSpeaking())) {
Expand All @@ -54,6 +57,7 @@ public void onChange() {
videoEnabled = localCallParticipantModel.isVideoEnabled();

messageSender.sendToAll(getDataChannelMessageForVideoState());
messageSender.sendToAll(getSignalingMessageForVideoState());
}
}
}
Expand Down Expand Up @@ -106,4 +110,61 @@ protected DataChannelMessage getDataChannelMessageForVideoState() {

return new DataChannelMessage(type);
}

/**
* Returns a signaling message with the common fields set (type and room type).
*
* @param type the type of the signaling message
* @return the signaling message
*/
private NCSignalingMessage createBaseSignalingMessage(String type) {
NCSignalingMessage ncSignalingMessage = new NCSignalingMessage();
// "roomType" is not really relevant without a peer or when referring to the whole participant, but it is
// nevertheless expected in the message. As most of the signaling messages currently sent to all participants
// are related to audio/video state "video" is used as the room type.
ncSignalingMessage.setRoomType("video");
ncSignalingMessage.setType(type);

return ncSignalingMessage;
}

/**
* Returns a signaling message to notify current audio state.
*
* @return the signaling message
*/
protected NCSignalingMessage getSignalingMessageForAudioState() {
String type = "mute";
if (localCallParticipantModel.isAudioEnabled() != null && localCallParticipantModel.isAudioEnabled()) {
type = "unmute";
}

NCSignalingMessage ncSignalingMessage = createBaseSignalingMessage(type);

NCMessagePayload ncMessagePayload = new NCMessagePayload();
ncMessagePayload.setType("audio");
ncSignalingMessage.setPayload(ncMessagePayload);

return ncSignalingMessage;
}

/**
* Returns a signaling message to notify current video state.
*
* @return the signaling message
*/
protected NCSignalingMessage getSignalingMessageForVideoState() {
String type = "mute";
if (localCallParticipantModel.isVideoEnabled() != null && localCallParticipantModel.isVideoEnabled()) {
type = "unmute";
}

NCSignalingMessage ncSignalingMessage = createBaseSignalingMessage(type);

NCMessagePayload ncMessagePayload = new NCMessagePayload();
ncMessagePayload.setType("video");
ncSignalingMessage.setPayload(ncMessagePayload);

return ncSignalingMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,8 @@ private void sendState(String sessionId) {
messageSender.send(getDataChannelMessageForAudioState(), sessionId);
messageSender.send(getDataChannelMessageForSpeakingState(), sessionId);
messageSender.send(getDataChannelMessageForVideoState(), sessionId);

messageSender.send(getSignalingMessageForAudioState(), sessionId);
messageSender.send(getSignalingMessageForVideoState(), sessionId);
}
}
Loading

0 comments on commit 6bfe01b

Please sign in to comment.