From dcae051e8522d82fa09aeeaa3dcdda8f83aa1c02 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 28 May 2020 12:19:58 +0200 Subject: [PATCH] Create enum as per the spec and use default values when applicable --- .../room/model/call/CallAnswerContent.kt | 4 +-- .../room/model/call/CallCandidatesContent.kt | 2 +- .../room/model/call/CallHangupContent.kt | 14 +++++++--- .../room/model/call/CallInviteContent.kt | 8 +++--- .../api/session/room/model/call/SdpType.kt | 27 +++++++++++++++++++ .../session/call/DefaultCallService.kt | 21 +++------------ 6 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/SdpType.kt diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallAnswerContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallAnswerContent.kt index f9f9cf15b2..7fb575d12c 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallAnswerContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallAnswerContent.kt @@ -35,7 +35,7 @@ data class CallAnswerContent( /** * Required. The version of the VoIP specification this messages adheres to. This specification is version 0. */ - @Json(name = "version") val version: Int + @Json(name = "version") val version: Int = 0 ) { @JsonClass(generateAdapter = true) @@ -43,7 +43,7 @@ data class CallAnswerContent( /** * Required. The type of session description. Must be 'answer'. */ - @Json(name = "type") val type: String, + @Json(name = "type") val type: SdpType = SdpType.ANSWER, /** * Required. The SDP text of the session description. */ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallCandidatesContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallCandidatesContent.kt index 1375776919..6132d1a57a 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallCandidatesContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallCandidatesContent.kt @@ -36,7 +36,7 @@ data class CallCandidatesContent( /** * Required. The version of the VoIP specification this messages adheres to. This specification is version 0. */ - @Json(name = "version") val version: Int + @Json(name = "version") val version: Int = 0 ) { @JsonClass(generateAdapter = true) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallHangupContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallHangupContent.kt index c17efd2559..1e50bc247e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallHangupContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallHangupContent.kt @@ -32,11 +32,19 @@ data class CallHangupContent( /** * Required. The version of the VoIP specification this message adheres to. This specification is version 0. */ - @Json(name = "version") val version: Int, + @Json(name = "version") val version: Int = 0, /** * Optional error reason for the hangup. This should not be provided when the user naturally ends or rejects the call. * When there was an error in the call negotiation, this should be `ice_failed` for when ICE negotiation fails * or `invite_timeout` for when the other party did not answer in time. One of: ["ice_failed", "invite_timeout"] */ - @Json(name = "reason") val reason: String? -) + @Json(name = "reason") val reason: Reason? = null +) { + enum class Reason { + @Json(name = "ice_failed") + ICE_FAILED, + + @Json(name = "invite_timeout") + INVITE_TIMEOUT + } +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallInviteContent.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallInviteContent.kt index cd0df70c96..1fad181fab 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallInviteContent.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/CallInviteContent.kt @@ -31,24 +31,24 @@ data class CallInviteContent( /** * Required. The session description object */ - @Json(name = "version") val version: Int?, + @Json(name = "offer") val offer: Offer?, /** * Required. The version of the VoIP specification this message adheres to. This specification is version 0. */ - @Json(name = "lifetime") val lifetime: Int?, + @Json(name = "version") val version: Int? = 0, /** * Required. The time in milliseconds that the invite is valid for. * Once the invite age exceeds this value, clients should discard it. * They should also no longer show the call as awaiting an answer in the UI. */ - @Json(name = "offer") val offer: Offer? + @Json(name = "lifetime") val lifetime: Int? ) { @JsonClass(generateAdapter = true) data class Offer( /** * Required. The type of session description. Must be 'offer'. */ - @Json(name = "type") val type: String?, + @Json(name = "type") val type: SdpType? = SdpType.OFFER, /** * Required. The SDP text of the session description. */ diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/SdpType.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/SdpType.kt new file mode 100644 index 0000000000..17c6d9a89f --- /dev/null +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/room/model/call/SdpType.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 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.matrix.android.api.session.room.model.call + +import com.squareup.moshi.Json + +enum class SdpType { + @Json(name = "offer") + OFFER, + + @Json(name = "answer") + ANSWER +} diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/DefaultCallService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/DefaultCallService.kt index 7b0731d8a8..2f26dce2cb 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/DefaultCallService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/call/DefaultCallService.kt @@ -61,12 +61,8 @@ internal class DefaultCallService @Inject constructor( override fun sendOfferSdp(callId: String, roomId: String, sdp: SessionDescription, callback: MatrixCallback) { val eventContent = CallInviteContent( callId = callId, - version = 0, lifetime = CALL_TIMEOUT_MS, - offer = CallInviteContent.Offer( - type = sdp.type.canonicalForm(), - sdp = sdp.description - ) + offer = CallInviteContent.Offer(sdp = sdp.description) ) createEventAndLocalEcho(type = EventType.CALL_INVITE, roomId = roomId, content = eventContent.toContent()).let { event -> @@ -83,11 +79,7 @@ internal class DefaultCallService @Inject constructor( override fun sendAnswerSdp(callId: String, roomId: String, sdp: SessionDescription, callback: MatrixCallback) { val eventContent = CallAnswerContent( callId = callId, - version = 0, - answer = CallAnswerContent.Answer( - type = sdp.type.canonicalForm(), - sdp = sdp.description - ) + answer = CallAnswerContent.Answer(sdp = sdp.description) ) createEventAndLocalEcho(type = EventType.CALL_INVITE, roomId = roomId, content = eventContent.toContent()).let { event -> @@ -104,7 +96,6 @@ internal class DefaultCallService @Inject constructor( override fun sendLocalIceCandidates(callId: String, roomId: String, candidates: List) { val eventContent = CallCandidatesContent( callId = callId, - version = 0, candidates = candidates.map { CallCandidatesContent.Candidate( sdpMid = it.sdpMid, @@ -128,11 +119,7 @@ internal class DefaultCallService @Inject constructor( } override fun sendHangup(callId: String, roomId: String) { - val eventContent = CallHangupContent( - callId = callId, - version = 0, - reason = null - ) + val eventContent = CallHangupContent(callId = callId) createEventAndLocalEcho(type = EventType.CALL_HANGUP, roomId = roomId, content = eventContent.toContent()).let { event -> roomEventSender.sendEvent(event) } @@ -146,7 +133,7 @@ internal class DefaultCallService @Inject constructor( callListeners.remove(listener) } - fun onCallEvent(event: Event) { + internal fun onCallEvent(event: Event) { when (event.getClearType()) { EventType.CALL_ANSWER -> { event.getClearContent().toModel()?.let {