-
Notifications
You must be signed in to change notification settings - Fork 739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/fga/fix some voip issues #2830
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
61373b8
Timeline: start refactoring the Interceptor mechanism
ganfra 109a9e8
Timeline: fix crash on mutable iterator
ganfra 96b02d3
VoIP: PSTN support was done too early
ganfra 5e3e5d2
Clean code
ganfra 3170d44
VoIP: extract the PSTNProtocoltChecker to the SDK
ganfra 79acf1c
Fix copyright
ganfra 776ebce
Merge branch 'develop' into feature/fga/fix_some_voip_issues
ganfra 754dec9
Remove useless log
ganfra 373586c
Cleanup
bmarty a34c072
Rename interface
bmarty c787de7
Cleaup
bmarty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...-sdk-android/src/main/java/org/matrix/android/sdk/api/session/call/PSTNProtocolChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.api.session.call | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import org.matrix.android.sdk.api.extensions.tryOrNull | ||
import org.matrix.android.sdk.api.session.room.model.thirdparty.ThirdPartyProtocol | ||
import org.matrix.android.sdk.internal.session.SessionScope | ||
import org.matrix.android.sdk.internal.session.thirdparty.GetThirdPartyProtocolsTask | ||
import org.matrix.android.sdk.internal.task.TaskExecutor | ||
import timber.log.Timber | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
import javax.inject.Inject | ||
|
||
private const val PSTN_VECTOR_KEY = "im.vector.protocol.pstn" | ||
private const val PSTN_MATRIX_KEY = "m.protocol.pstn" | ||
|
||
/** | ||
* This class is responsible for checking if the HS support the PSTN protocol. | ||
* As long as the request succeed, it'll check only once by session. | ||
*/ | ||
@SessionScope | ||
class PSTNProtocolChecker @Inject internal constructor(private val taskExecutor: TaskExecutor, | ||
private val getThirdPartyProtocolsTask: GetThirdPartyProtocolsTask) { | ||
|
||
interface Listener { | ||
fun onPSTNSupportUpdated() | ||
} | ||
|
||
private var alreadyChecked = AtomicBoolean(false) | ||
|
||
private val pstnSupportListeners = mutableListOf<Listener>() | ||
|
||
fun addListener(listener: Listener) { | ||
pstnSupportListeners.add(listener) | ||
} | ||
|
||
fun removeListener(listener: Listener) { | ||
pstnSupportListeners.remove(listener) | ||
} | ||
|
||
var supportedPSTNProtocol: String? = null | ||
private set | ||
|
||
fun checkForPSTNSupportIfNeeded() { | ||
if (alreadyChecked.get()) return | ||
taskExecutor.executorScope.checkForPSTNSupport() | ||
} | ||
|
||
private fun CoroutineScope.checkForPSTNSupport() = launch { | ||
try { | ||
supportedPSTNProtocol = getSupportedPSTN(3) | ||
alreadyChecked.set(true) | ||
if (supportedPSTNProtocol != null) { | ||
pstnSupportListeners.forEach { | ||
tryOrNull { it.onPSTNSupportUpdated() } | ||
} | ||
} | ||
} catch (failure: Throwable) { | ||
Timber.v("Fail to get supported PSTN, will check again next time.") | ||
} | ||
} | ||
|
||
private suspend fun getSupportedPSTN(maxTries: Int): String? { | ||
val thirdPartyProtocols: Map<String, ThirdPartyProtocol> = try { | ||
getThirdPartyProtocolsTask.execute(Unit) | ||
} catch (failure: Throwable) { | ||
if (maxTries == 1) { | ||
throw failure | ||
} else { | ||
// Wait for 10s before trying again | ||
delay(10_000L) | ||
return getSupportedPSTN(maxTries - 1) | ||
} | ||
} | ||
return when { | ||
thirdPartyProtocols.containsKey(PSTN_VECTOR_KEY) -> PSTN_VECTOR_KEY | ||
thirdPartyProtocols.containsKey(PSTN_MATRIX_KEY) -> PSTN_MATRIX_KEY | ||
else -> null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
vector/src/main/java/im/vector/app/core/epoxy/TimelineEmptyItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2019 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.core.epoxy | ||
|
||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import im.vector.app.R | ||
import im.vector.app.features.home.room.detail.timeline.item.ItemWithEvents | ||
|
||
@EpoxyModelClass(layout = R.layout.item_timeline_empty) | ||
abstract class TimelineEmptyItem : VectorEpoxyModel<TimelineEmptyItem.Holder>(), ItemWithEvents { | ||
|
||
@EpoxyAttribute lateinit var eventId: String | ||
|
||
override fun getEventIds(): List<String> { | ||
return listOf(eventId) | ||
} | ||
|
||
class Holder : VectorEpoxyHolder() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
vector/src/main/java/im/vector/app/features/call/webrtc/PSTNProtocol.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no
interface
to hide implementation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I can, but I try to remove interfaces when it's not really necessary as we already have a lots... Fields are private and constructor is internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'd seen the internal constructor. OK, thanks!