add receiving of "typing" signaling messages

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-05-16 13:55:07 +02:00
parent 32bd18ff32
commit 8997c3b5c7
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 100 additions and 0 deletions

View File

@ -311,6 +311,24 @@ class ChatActivity :
}
}
private val conversationMessageListener = object : SignalingMessageReceiver.ConversationMessageListener {
override fun onStartTyping(session: String?) {
val name = webSocketInstance?.getDisplayNameForSession(session)
runOnUiThread {
Toast.makeText(this@ChatActivity, name + " started typing", Toast.LENGTH_SHORT).show()
}
}
override fun onStopTyping(session: String?) {
val name = webSocketInstance?.getDisplayNameForSession(session)
runOnUiThread {
Toast.makeText(this@ChatActivity, name + " stopped typing", Toast.LENGTH_SHORT).show()
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
@ -398,6 +416,7 @@ class ChatActivity :
setupWebsocket()
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
webSocketInstance?.getSignalingMessageReceiver()?.addListener(conversationMessageListener)
if (conversationUser?.userId != "?" &&
CapabilitiesUtilNew.hasSpreedFeatureCapability(conversationUser, "mention-flag")
@ -1980,6 +1999,7 @@ class ChatActivity :
eventBus.unregister(this)
webSocketInstance?.getSignalingMessageReceiver()?.removeListener(localParticipantMessageListener)
webSocketInstance?.getSignalingMessageReceiver()?.removeListener(conversationMessageListener)
findViewById<View>(R.id.toolbar)?.setOnClickListener(null)

View File

@ -0,0 +1,54 @@
/*
* Nextcloud Talk application
*
* @author Marcel Hibbe
* Copyright (C) 2023 Marcel Hibbe <dev@mhibbe.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.signaling;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Set;
class ConversationMessageNotifier {
private final Set<SignalingMessageReceiver.ConversationMessageListener> conversationMessageListeners = new LinkedHashSet<>();
public synchronized void addListener(SignalingMessageReceiver.ConversationMessageListener listener) {
if (listener == null) {
throw new IllegalArgumentException("conversationMessageListener can not be null");
}
conversationMessageListeners.add(listener);
}
public synchronized void removeListener(SignalingMessageReceiver.ConversationMessageListener listener) {
conversationMessageListeners.remove(listener);
}
public synchronized void notifyStartTyping(String sessionId) {
for (SignalingMessageReceiver.ConversationMessageListener listener : new ArrayList<>(conversationMessageListeners)) {
listener.onStartTyping(sessionId);
}
}
public void notifyStopTyping(String sessionId) {
for (SignalingMessageReceiver.ConversationMessageListener listener : new ArrayList<>(conversationMessageListeners)) {
listener.onStopTyping(sessionId);
}
}
}

View File

@ -153,6 +153,14 @@ public abstract class SignalingMessageReceiver {
void onUnshareScreen();
}
/**
* Listener for conversation messages.
*/
public interface ConversationMessageListener {
void onStartTyping(String session);
void onStopTyping(String session);
}
/**
* Listener for WebRTC offers.
*
@ -185,6 +193,8 @@ public abstract class SignalingMessageReceiver {
private final CallParticipantMessageNotifier callParticipantMessageNotifier = new CallParticipantMessageNotifier();
private final ConversationMessageNotifier conversationMessageNotifier = new ConversationMessageNotifier();
private final OfferMessageNotifier offerMessageNotifier = new OfferMessageNotifier();
private final WebRtcMessageNotifier webRtcMessageNotifier = new WebRtcMessageNotifier();
@ -236,6 +246,14 @@ public abstract class SignalingMessageReceiver {
callParticipantMessageNotifier.removeListener(listener);
}
public void addListener(ConversationMessageListener listener) {
conversationMessageNotifier.addListener(listener);
}
public void removeListener(ConversationMessageListener listener) {
conversationMessageNotifier.removeListener(listener);
}
/**
* Adds a listener for all offer messages.
*
@ -563,6 +581,14 @@ public abstract class SignalingMessageReceiver {
return;
}
if ("startedTyping".equals(type)) {
conversationMessageNotifier.notifyStartTyping(sessionId);
}
if ("stoppedTyping".equals(type)) {
conversationMessageNotifier.notifyStopTyping(sessionId);
}
if ("reaction".equals(type)) {
// Message schema (external signaling server):
// {