Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / signal / call / SignalCallInbound.kt
SignalCallInbound.kt103 lines · 3.0 KiBRaw
| 1 | package com.vayunmathur.communicate.data.signal.call |
| 2 | |
| 3 | import com.vayunmathur.library.log.Log |
| 4 | import kotlinx.coroutines.launch |
| 5 | import org.signal.ringrtc.CallId |
| 6 | import org.signal.ringrtc.CallManager |
| 7 | |
| 8 | /** |
| 9 | * Inbound call signaling for [SignalCallManager] (split for file length). |
| 10 | * Extension functions on [SignalCallManager]; behavior identical, call sites unchanged. |
| 11 | */ |
| 12 | |
| 13 | fun SignalCallManager.receivedOffer( |
| 14 | callId: Long, |
| 15 | senderAci: String, |
| 16 | senderDeviceId: Int, |
| 17 | localDeviceId: Int, |
| 18 | opaque: ByteArray, |
| 19 | messageAgeSec: Long, |
| 20 | video: Boolean, |
| 21 | ) { |
| 22 | val manager = callManager ?: return |
| 23 | scope.launch { |
| 24 | val keys = signaling.identityKeys(senderAci) ?: run { |
| 25 | Log.status(SignalCallManager.TAG, "no identity keys for $senderAci, cannot accept the offer") |
| 26 | return@launch |
| 27 | } |
| 28 | val mediaType = if (video) CallManager.CallMediaType.VIDEO_CALL else CallManager.CallMediaType.AUDIO_CALL |
| 29 | callMediaTypes[callId] = mediaType |
| 30 | try { |
| 31 | manager.receivedOffer( |
| 32 | CallId(callId), |
| 33 | SignalRemote(senderAci), |
| 34 | senderDeviceId, |
| 35 | opaque, |
| 36 | messageAgeSec, |
| 37 | mediaType, |
| 38 | localDeviceId, |
| 39 | keys.remote, |
| 40 | keys.local, |
| 41 | ) |
| 42 | } catch (expected: Throwable) { |
| 43 | Log.status(SignalCallManager.TAG, "receivedOffer failed", expected) |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | fun SignalCallManager.receivedAnswer(callId: Long, senderAci: String, senderDeviceId: Int, opaque: ByteArray) { |
| 49 | val manager = callManager ?: return |
| 50 | scope.launch { |
| 51 | val keys = signaling.identityKeys(senderAci) ?: return@launch |
| 52 | try { |
| 53 | manager.receivedAnswer( |
| 54 | CallId(callId), |
| 55 | SignalRemote(senderAci), |
| 56 | senderDeviceId, |
| 57 | opaque, |
| 58 | keys.remote, |
| 59 | keys.local, |
| 60 | ) |
| 61 | } catch (expected: Throwable) { |
| 62 | Log.status(SignalCallManager.TAG, "receivedAnswer failed", expected) |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | fun SignalCallManager.receivedIceCandidates( |
| 68 | callId: Long, |
| 69 | senderAci: String, |
| 70 | senderDeviceId: Int, |
| 71 | candidates: List<ByteArray>, |
| 72 | ) { |
| 73 | withManager("receivedIceCandidates") { |
| 74 | it.receivedIceCandidates( |
| 75 | CallId(callId), |
| 76 | SignalRemote(senderAci), |
| 77 | senderDeviceId, |
| 78 | candidates) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | fun SignalCallManager.receivedHangup( |
| 83 | callId: Long, |
| 84 | senderAci: String, |
| 85 | senderDeviceId: Int, |
| 86 | type: CallManager.HangupType, |
| 87 | deviceId: Int, |
| 88 | ) { |
| 89 | withManager("receivedHangup") { |
| 90 | it.receivedHangup( |
| 91 | CallId(callId), |
| 92 | SignalRemote(senderAci), |
| 93 | senderDeviceId, |
| 94 | type, |
| 95 | deviceId) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | fun SignalCallManager.receivedBusy(callId: Long, senderAci: String, senderDeviceId: Int) { |
| 100 | withManager("receivedBusy") { |
| 101 | it.receivedBusy(CallId(callId), SignalRemote(senderAci), senderDeviceId) |
| 102 | } |
| 103 | } |