Throttle BobTransfer re-attempts + Fix DTMF causes trak to become disposed (Cheogram)

This commit is contained in:
Arne 2023-05-23 20:02:19 +02:00
parent cdc3fb0ba8
commit af05c6552a
2 changed files with 17 additions and 9 deletions

View file

@ -4,6 +4,8 @@ import android.net.Uri;
import android.util.Base64;
import android.util.Log;
import java.util.Map;
import java.util.HashMap;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
@ -29,7 +31,6 @@ import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.Jid;
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
import io.ipfs.multihash.Multihash;
public class BobTransfer implements Transferable {
protected int status = Transferable.STATUS_OFFER;
@ -37,6 +38,7 @@ public class BobTransfer implements Transferable {
protected Account account;
protected Jid to;
protected XmppConnectionService xmppConnectionService;
protected static Map<URI, Long> attempts = new HashMap<>();
public static Cid cid(Uri uri) {
if (uri == null || uri.getScheme() == null || !uri.getScheme().equals("cid")) return null;
@ -85,7 +87,8 @@ public class BobTransfer implements Transferable {
return true;
}
if (xmppConnectionService.hasInternetConnection()) {
if (xmppConnectionService.hasInternetConnection() && attempts.getOrDefault(uri, 0L) + 10000L < System.currentTimeMillis()) {
attempts.put(uri, System.currentTimeMillis());
changeStatus(Transferable.STATUS_DOWNLOADING);
IqPacket request = new IqPacket(IqPacket.TYPE.GET);
@ -114,14 +117,19 @@ public class BobTransfer implements Transferable {
}
final OutputStream outputStream = AbstractConnectionManager.createOutputStream(new DownloadableFile(file.getAbsolutePath()), false, false);
outputStream.write(bytes);
outputStream.flush();
outputStream.close();
finish(file);
if (outputStream != null && bytes != null) {
outputStream.write(bytes);
outputStream.flush();
outputStream.close();
finish(file);
} else {
Log.w(Config.LOGTAG, "Could not write BobTransfer, null outputStream");
finish(null);
}
} catch (final IOException | XmppConnectionService.BlockedMediaException e) {
Log.w(Config.LOGTAG, "Could not write BobTransfer: " + e);
finish(null);
xmppConnectionService.showErrorToastInUi(R.string.download_failed_could_not_write_file);
}
}
});

View file

@ -736,10 +736,10 @@ public class WebRTCWrapper {
}
public boolean applyDtmfTone(String tone) {
if (toneManager == null || peerConnection == null || peerConnection.getSenders().isEmpty()) {
if (toneManager == null || peerConnection == null || localAudioTrack == null) {
return false;
}
peerConnection.getSenders().get(0).dtmf().insertDtmf(tone, TONE_DURATION, 100);
localAudioTrack.rtpSender.dtmf().insertDtmf(tone, TONE_DURATION, 100);
toneManager.startTone(TONE_CODES.get(tone), TONE_DURATION);
return true;
}