mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-24 22:17:25 +00:00
feat: update to utilise call ID
This commit is contained in:
@@ -154,8 +154,8 @@ dependencies {
|
||||
testImplementation 'org.robolectric:shadows-multidex:4.4'
|
||||
}
|
||||
|
||||
def canonicalVersionCode = 229
|
||||
def canonicalVersionName = "1.11.11"
|
||||
def canonicalVersionCode = 230
|
||||
def canonicalVersionName = "1.12.0"
|
||||
|
||||
def postFixSize = 10
|
||||
def abiPostFix = ['armeabi-v7a' : 1,
|
||||
|
@@ -23,6 +23,7 @@ import org.session.libsignal.utilities.Log
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.permissions.Permissions
|
||||
import org.webrtc.*
|
||||
import java.util.*
|
||||
|
||||
|
||||
class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection.Observer,
|
||||
@@ -40,6 +41,7 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
|
||||
const val EXTRA_SDP = "WebRtcTestsActivity_EXTRA_SDP"
|
||||
const val EXTRA_ADDRESS = "WebRtcTestsActivity_EXTRA_ADDRESS"
|
||||
const val EXTRA_CALL_ID = "WebRtcTestsActivity_EXTRA_CALL_ID"
|
||||
const val EXTRA_RELAY_USED = "WebRtcTestsActivity_EXTRA_RELAY_USED"
|
||||
const val EXTRA_SDP_MLINE_INDEXES = "WebRtcTestsActivity_EXTRA_SDP_MLINE_INDEXES"
|
||||
const val EXTRA_SDP_MIDS = "WebRtcTestsActivity_EXTRA_SDP_MIDS"
|
||||
@@ -89,20 +91,19 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
}
|
||||
|
||||
private lateinit var callAddress: Address
|
||||
private lateinit var callId: UUID
|
||||
private var relayUsed: Boolean = true
|
||||
|
||||
private val peerConnection by lazy {
|
||||
// TODO: in a lokinet world, ice servers shouldn't be needed as .loki addresses should suffice to p2p
|
||||
val server = PeerConnection.IceServer.builder("stun:stun.l.google.com:19302").createIceServer()
|
||||
val server1 = PeerConnection.IceServer.builder("stun:stun1.l.google.com:19302").createIceServer()
|
||||
val server2 = PeerConnection.IceServer.builder("stun:stun2.l.google.com:19302").createIceServer()
|
||||
val server3 = PeerConnection.IceServer.builder("stun:stun3.l.google.com:19302").createIceServer()
|
||||
val server4 = PeerConnection.IceServer.builder("stun:stun4.l.google.com:19302").createIceServer()
|
||||
val iceServers = mutableListOf(server,server1,server2,server3,server4)
|
||||
val server = PeerConnection.IceServer.builder("turn:freyr.getsession.org:5349").setUsername("session").setPassword("session").createIceServer()
|
||||
val iceServers = mutableListOf(server)
|
||||
if (relayUsed) {
|
||||
// add relay server
|
||||
}
|
||||
val rtcConfig = PeerConnection.RTCConfiguration(iceServers)
|
||||
val rtcConfig = PeerConnection.RTCConfiguration(iceServers).apply {
|
||||
this.iceTransportsType = PeerConnection.IceTransportsType.RELAY
|
||||
}
|
||||
rtcConfig.keyType = PeerConnection.KeyType.ECDSA
|
||||
connectionFactory.createPeerConnection(rtcConfig, this)!!
|
||||
}
|
||||
@@ -156,6 +157,7 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
}
|
||||
|
||||
// create either call or answer
|
||||
callId = intent.getStringExtra(EXTRA_CALL_ID).let(UUID::fromString)
|
||||
if (intent.action == ACTION_ANSWER) {
|
||||
callAddress = intent.getParcelableExtra(EXTRA_ADDRESS) ?: run { finish(); return }
|
||||
val offerSdp = intent.getStringArrayExtra(EXTRA_SDP)!![0]
|
||||
@@ -169,7 +171,7 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
lifecycleScope.launchWhenCreated {
|
||||
while (this.isActive) {
|
||||
val answer = synchronized(WebRtcUtils.callCache) {
|
||||
WebRtcUtils.callCache[callAddress]?.firstOrNull { it.type == SignalServiceProtos.CallMessage.Type.ANSWER }
|
||||
WebRtcUtils.callCache[callId]?.firstOrNull { it.type == SignalServiceProtos.CallMessage.Type.ANSWER }
|
||||
}
|
||||
if (answer != null) {
|
||||
peerConnection.setRemoteDescription(
|
||||
@@ -193,7 +195,7 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
delay(2_000L)
|
||||
peerConnection.getStats(this@WebRtcTestsActivity)
|
||||
synchronized(WebRtcUtils.callCache) {
|
||||
val set = WebRtcUtils.callCache[callAddress] ?: mutableSetOf()
|
||||
val set = WebRtcUtils.callCache[callId] ?: mutableSetOf()
|
||||
set.filter { it.hashCode() !in acceptedCallMessageHashes
|
||||
&& it.type == SignalServiceProtos.CallMessage.Type.ICE_CANDIDATES }.forEach { callMessage ->
|
||||
callMessage.iceCandidates().forEach { candidate ->
|
||||
@@ -228,9 +230,10 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
|
||||
private fun endCall() {
|
||||
if (isFinishing) return
|
||||
val uuid = callId
|
||||
|
||||
MessageSender.sendNonDurably(
|
||||
CallMessage.endCall(),
|
||||
CallMessage.endCall(uuid),
|
||||
callAddress
|
||||
)
|
||||
peerConnection.close()
|
||||
@@ -319,7 +322,8 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
CallMessage(SignalServiceProtos.CallMessage.Type.ICE_CANDIDATES,
|
||||
candidates.map { it.sdp },
|
||||
candidates.map { it.sdpMLineIndex },
|
||||
candidates.map { it.sdpMid }
|
||||
candidates.map { it.sdpMid },
|
||||
callId
|
||||
),
|
||||
callAddress
|
||||
)
|
||||
@@ -362,18 +366,28 @@ class WebRtcTestsActivity: PassphraseRequiredActionBarActivity(), PeerConnection
|
||||
SessionDescription.Type.OFFER -> {
|
||||
peerConnection.setLocalDescription(this, sdp)
|
||||
MessageSender.sendNonDurably(
|
||||
CallMessage(SignalServiceProtos.CallMessage.Type.OFFER, listOf(sdp.description), listOf(), listOf()),
|
||||
CallMessage(SignalServiceProtos.CallMessage.Type.OFFER,
|
||||
listOf(sdp.description),
|
||||
listOf(),
|
||||
listOf(),
|
||||
callId
|
||||
),
|
||||
callAddress
|
||||
)
|
||||
}
|
||||
SessionDescription.Type.ANSWER -> {
|
||||
peerConnection.setLocalDescription(this, sdp)
|
||||
MessageSender.sendNonDurably(
|
||||
CallMessage(SignalServiceProtos.CallMessage.Type.ANSWER, listOf(sdp.description), listOf(), listOf()),
|
||||
CallMessage(SignalServiceProtos.CallMessage.Type.ANSWER,
|
||||
listOf(sdp.description),
|
||||
listOf(),
|
||||
listOf(),
|
||||
callId
|
||||
),
|
||||
callAddress
|
||||
)
|
||||
}
|
||||
SessionDescription.Type.PRANSWER -> TODO("do the PR answer create success handling") // MessageSender.send()
|
||||
null, SessionDescription.Type.PRANSWER -> TODO("do the PR answer create success handling") // MessageSender.send()
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -46,6 +46,7 @@ import org.thoughtcrime.securesms.groups.EditClosedGroupActivity.Companion.group
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil
|
||||
import org.thoughtcrime.securesms.util.getColorWithID
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
object ConversationMenuHelper {
|
||||
|
||||
@@ -187,6 +188,7 @@ object ConversationMenuHelper {
|
||||
.setMessage("Use relay?")
|
||||
.setPositiveButton("Use Relay") { d, w ->
|
||||
val intent = Intent(context, WebRtcTestsActivity::class.java)
|
||||
intent.putExtra(WebRtcTestsActivity.EXTRA_CALL_ID, UUID.randomUUID().toString())
|
||||
intent.putExtra(WebRtcTestsActivity.EXTRA_ADDRESS, thread.address)
|
||||
intent.putExtra(WebRtcTestsActivity.EXTRA_RELAY_USED, false)
|
||||
val activity = context as AppCompatActivity
|
||||
|
@@ -12,13 +12,16 @@ import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.loader.app.LoaderManager
|
||||
import androidx.loader.content.Loader
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.android.synthetic.main.activity_home.*
|
||||
import kotlinx.android.synthetic.main.seed_reminder_stub.*
|
||||
@@ -33,13 +36,16 @@ import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
import org.session.libsession.messaging.jobs.JobQueue
|
||||
import org.session.libsession.messaging.sending_receiving.MessageSender
|
||||
import org.session.libsession.messaging.utilities.WebRtcUtils
|
||||
import org.session.libsession.utilities.*
|
||||
import org.session.libsession.utilities.Util
|
||||
import org.session.libsignal.protos.SignalServiceProtos
|
||||
import org.session.libsignal.utilities.ThreadUtils
|
||||
import org.session.libsignal.utilities.toHexString
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.MuteDialog
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.calls.WebRtcTestsActivity
|
||||
import org.thoughtcrime.securesms.conversation.v2.ConversationActivityV2
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.NotificationUtils
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
@@ -58,6 +64,7 @@ import org.thoughtcrime.securesms.onboarding.SeedActivity
|
||||
import org.thoughtcrime.securesms.onboarding.SeedReminderViewDelegate
|
||||
import org.thoughtcrime.securesms.preferences.SettingsActivity
|
||||
import org.thoughtcrime.securesms.util.*
|
||||
import org.thoughtcrime.securesms.webrtc.CallBottomSheet
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
@@ -141,6 +148,50 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis
|
||||
}
|
||||
this.broadcastReceiver = broadcastReceiver
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, IntentFilter("blockedContactsChanged"))
|
||||
lifecycleScope.launchWhenCreated {
|
||||
// web rtc channel handling
|
||||
for (message in WebRtcUtils.SIGNAL_QUEUE) {
|
||||
// TODO: check errors here in the
|
||||
val sender = Address.fromSerialized(message.sender!!)
|
||||
val callId = message.callId!!
|
||||
synchronized(WebRtcUtils.callCache) {
|
||||
val set = WebRtcUtils.callCache[callId] ?: mutableSetOf()
|
||||
set += message
|
||||
WebRtcUtils.callCache[callId] = set
|
||||
}
|
||||
when (message.type) {
|
||||
SignalServiceProtos.CallMessage.Type.OFFER -> {
|
||||
// show bottom sheet
|
||||
if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) {
|
||||
CallBottomSheet().apply {
|
||||
arguments = bundleOf(
|
||||
CallBottomSheet.ARGUMENT_ADDRESS to sender,
|
||||
CallBottomSheet.ARGUMENT_SDP to message.sdps.toTypedArray(),
|
||||
CallBottomSheet.ARGUMENT_TYPE to message.type!!.number,
|
||||
CallBottomSheet.ARGUMENT_CALL_ID to callId.toString()
|
||||
)
|
||||
show(this@HomeActivity.supportFragmentManager,"call-sheet")
|
||||
}
|
||||
}
|
||||
}
|
||||
SignalServiceProtos.CallMessage.Type.END_CALL -> {
|
||||
// dismiss the call sheet
|
||||
supportFragmentManager.findFragmentByTag("call-sheet")?.let { callSheet ->
|
||||
if (callSheet is BottomSheetDialogFragment) {
|
||||
callSheet.dismiss()
|
||||
}
|
||||
}
|
||||
// clear the callCache for this sender
|
||||
synchronized(WebRtcUtils.callCache) {
|
||||
WebRtcUtils.callCache[callId] = mutableSetOf()
|
||||
}
|
||||
sendBroadcast(Intent(WebRtcTestsActivity.ACTION_END))
|
||||
}
|
||||
else -> { /* do nothing */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lifecycleScope.launchWhenStarted {
|
||||
launch(Dispatchers.IO) {
|
||||
// Double check that the long poller is up
|
||||
|
@@ -17,6 +17,7 @@ import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.calls.WebRtcTestsActivity
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import java.util.*
|
||||
|
||||
class CallBottomSheet: BottomSheetDialogFragment() {
|
||||
|
||||
@@ -24,6 +25,7 @@ class CallBottomSheet: BottomSheetDialogFragment() {
|
||||
const val ARGUMENT_ADDRESS = "CallBottomSheet_ADDRESS"
|
||||
const val ARGUMENT_SDP = "CallBottomSheet_SDP"
|
||||
const val ARGUMENT_TYPE = "CallBottomSheet_TYPE"
|
||||
const val ARGUMENT_CALL_ID = "CallBottomSheet_CALL_ID"
|
||||
}
|
||||
|
||||
private lateinit var address: Address
|
||||
@@ -41,6 +43,8 @@ class CallBottomSheet: BottomSheetDialogFragment() {
|
||||
|
||||
address = arguments?.getParcelable(ARGUMENT_ADDRESS) ?: return dismiss()
|
||||
val sdp = arguments?.getStringArray(ARGUMENT_SDP) ?: return dismiss()
|
||||
val callId = arguments?.getString(ARGUMENT_CALL_ID) ?: return dismiss()
|
||||
val callUUID = UUID.fromString(callId)
|
||||
val recipient = Recipient.from(requireContext(), address, false)
|
||||
profilePictureView.publicKey = address.serialize()
|
||||
profilePictureView.glide = GlideApp.with(this)
|
||||
@@ -53,7 +57,8 @@ class CallBottomSheet: BottomSheetDialogFragment() {
|
||||
val intent = Intent(requireContext(), WebRtcTestsActivity::class.java)
|
||||
val bundle = bundleOf(
|
||||
WebRtcTestsActivity.EXTRA_ADDRESS to address,
|
||||
WebRtcTestsActivity.EXTRA_RELAY_USED to relaySwitch.isChecked
|
||||
WebRtcTestsActivity.EXTRA_RELAY_USED to relaySwitch.isChecked,
|
||||
WebRtcTestsActivity.EXTRA_CALL_ID to callId
|
||||
)
|
||||
intent.action = WebRtcTestsActivity.ACTION_ANSWER
|
||||
bundle.putStringArray(WebRtcTestsActivity.EXTRA_SDP, sdp)
|
||||
@@ -64,7 +69,7 @@ class CallBottomSheet: BottomSheetDialogFragment() {
|
||||
}
|
||||
|
||||
declineButton.setOnClickListener {
|
||||
MessageSender.sendNonDurably(CallMessage.endCall(), address)
|
||||
MessageSender.sendNonDurably(CallMessage.endCall(callUUID), address)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user