Compare commits

...

3 commits

Author SHA1 Message Date
adbenitez
de9a2df1b4 update DeclineCallReceiver.java 2025-09-22 18:43:20 +02:00
adbenitez
a3c7e3db3d use RPC for call API 2025-09-22 18:33:59 +02:00
adbenitez
249fc829be fix constant numbering in ConversationAdapter.java 2025-09-22 17:44:27 +02:00
7 changed files with 58 additions and 40 deletions

View file

@ -773,30 +773,6 @@ JNIEXPORT void Java_com_b44t_messenger_DcContext_setWebxdcIntegration(JNIEnv *en
}
JNIEXPORT jint Java_com_b44t_messenger_DcContext_placeOutgoingCall(JNIEnv *env, jobject obj, jint chat_id, jstring info)
{
CHAR_REF(info);
jint msg_id = dc_place_outgoing_call(get_dc_context(env, obj), chat_id, infoPtr);
CHAR_UNREF(info);
return msg_id;
}
JNIEXPORT jint Java_com_b44t_messenger_DcContext_acceptIncomingCall(JNIEnv *env, jobject obj, jint msg_id, jstring info)
{
CHAR_REF(info);
jboolean ret = dc_accept_incoming_call(get_dc_context(env, obj), msg_id, infoPtr) != 0;
CHAR_UNREF(info);
return ret;
}
JNIEXPORT jint Java_com_b44t_messenger_DcContext_endCall(JNIEnv *env, jobject obj, jint msg_id)
{
return dc_end_call(get_dc_context(env, obj), msg_id) != 0;
}
JNIEXPORT jint Java_com_b44t_messenger_DcContext_addDeviceMsg(JNIEnv *env, jobject obj, jstring label, jobject msg)
{
CHAR_REF(label);

@ -1 +1 @@
Subproject commit 5d9b887624f8c1641e40e009727b977de1c62bee
Subproject commit 738dc5ce197f589131479801db2fbd0fb0964599

View file

@ -208,9 +208,6 @@ public class DcContext {
public native String getWebxdcStatusUpdates(int msg_id, int last_known_serial);
public native void setWebxdcIntegration (String file);
public native int initWebxdcIntegration(int chat_id);
public native int placeOutgoingCall (int chat_id, String place_call_info);
public native boolean acceptIncomingCall (int msg_id, String accept_call_info);
public native boolean endCall (int msg_id);
public native int addDeviceMsg (String label, DcMsg msg);
public native boolean wasDeviceMsgEverAdded(String label);
public DcLot checkQr (String qr) { return new DcLot(checkQrCPtr(qr)); }

View file

@ -172,6 +172,22 @@ public class Rpc {
getResult("set_accounts_order", order);
}
public String iceServers(int accountId) throws RpcException {
return gson.fromJson(getResult("ice_servers", accountId), String.class);
}
public int placeOutgoingCall(int accountId, int chatId, String payload) throws RpcException {
return gson.fromJson(getResult("place_outgoing_call", accountId, chatId, payload), Integer.class);
}
public void acceptIncomingCall(int accountId, int msgId, String payload) throws RpcException {
getResult("accept_incoming_call", accountId, msgId, payload);
}
public void endCall(int accountId, int msgId) throws RpcException {
getResult("end_call", accountId, msgId);
}
private static class Request {
private final String jsonrpc = "2.0";
public final String method;

View file

@ -77,8 +77,8 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
private static final int MESSAGE_TYPE_THUMBNAIL_INCOMING = 6;
private static final int MESSAGE_TYPE_DOCUMENT_OUTGOING = 7;
private static final int MESSAGE_TYPE_DOCUMENT_INCOMING = 8;
private static final int MESSAGE_TYPE_STICKER_INCOMING = 10;
private static final int MESSAGE_TYPE_STICKER_OUTGOING = 11;
private static final int MESSAGE_TYPE_STICKER_INCOMING = 9;
private static final int MESSAGE_TYPE_STICKER_OUTGOING = 10;
private final Set<DcMsg> batchSelected = Collections.synchronizedSet(new HashSet<DcMsg>());

View file

@ -3,13 +3,16 @@ package org.thoughtcrime.securesms.notifications;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.rpc.RpcException;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.util.Util;
public class DeclineCallReceiver extends BroadcastReceiver {
private static final String TAG = DeclineCallReceiver.class.getSimpleName();
public static final String DECLINE_ACTION = "org.thoughtcrime.securesms.notifications.DECLINE_CALL";
public static final String ACCOUNT_ID_EXTRA = "account_id";
public static final String CALL_ID_EXTRA = "call_id";
@ -28,8 +31,11 @@ public class DeclineCallReceiver extends BroadcastReceiver {
Util.runOnAnyBackgroundThread(() -> {
DcHelper.getNotificationCenter(context).removeCallNotification(accountId, callId);
DcContext dcContext = DcHelper.getAccounts(context).getAccount(accountId);
dcContext.endCall(callId);
try {
DcHelper.getRpc(context).endCall(accountId, callId);
} catch (RpcException e) {
Log.e(TAG, "Error", e);
}
});
}
}

View file

@ -18,6 +18,8 @@ import androidx.annotation.NonNull;
import com.b44t.messenger.DcChat;
import com.b44t.messenger.DcContext;
import com.b44t.messenger.DcEvent;
import com.b44t.messenger.rpc.Rpc;
import com.b44t.messenger.rpc.RpcException;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.WebViewActivity;
@ -42,6 +44,8 @@ public class VideochatActivity extends WebViewActivity implements DcEventCenter.
public static final String EXTRA_HASH = "hash";
private DcContext dcContext;
private Rpc rpc;
private int accId;
private int chatId;
private int callId;
private boolean ended = false;
@ -54,10 +58,11 @@ public class VideochatActivity extends WebViewActivity implements DcEventCenter.
Bundle bundle = getIntent().getExtras();
assert bundle != null;
String hash = bundle.getString(EXTRA_HASH, "");
accId = bundle.getInt(EXTRA_ACCOUNT_ID, -1);
chatId = bundle.getInt(EXTRA_CHAT_ID, 0);
callId = bundle.getInt(EXTRA_CALL_ID, 0);
int accId = bundle.getInt(EXTRA_ACCOUNT_ID, -1);
this.dcContext = DcHelper.getAccounts(this).getAccount(accId);
rpc = DcHelper.getRpc(this);
dcContext = DcHelper.getAccounts(this).getAccount(accId);
DcHelper.getNotificationCenter(this).removeCallNotification(accId, callId);
@ -102,7 +107,13 @@ public class VideochatActivity extends WebViewActivity implements DcEventCenter.
@Override
protected void onDestroy() {
DcHelper.getEventCenter(this).removeObservers(this);
if (callId != 0 && !ended) dcContext.endCall(callId);
if (callId != 0 && !ended) {
try {
rpc.endCall(accId, callId);
} catch (RpcException e) {
Log.e(TAG, "Error", e);
}
}
super.onDestroy();
}
@ -145,18 +156,30 @@ public class VideochatActivity extends WebViewActivity implements DcEventCenter.
class InternalJSApi {
@JavascriptInterface
public String getIceServers() {
// TODO: hardcode server for now, should come core
return "[{\"urls\": \"turn:c20.testrun.org\",\"username\": \"ohV8aec1\", \"credential\": \"zo3theiY\"}]";
try {
return rpc.iceServers(accId);
} catch (RpcException e) {
Log.e(TAG, "Error", e);
return null;
}
}
@JavascriptInterface
public void startCall(String payload) {
callId = dcContext.placeOutgoingCall(chatId, payload);
try {
callId = rpc.placeOutgoingCall(accId, chatId, payload);
} catch (RpcException e) {
Log.e(TAG, "Error", e);
}
}
@JavascriptInterface
public void acceptCall(String payload) {
dcContext.acceptIncomingCall(callId, payload);
try {
rpc.acceptIncomingCall(accId, callId, payload);
} catch (RpcException e) {
Log.e(TAG, "Error", e);
}
}
@JavascriptInterface