Create enum as per the spec and use default values when applicable

This commit is contained in:
Benoit Marty 2020-05-28 12:19:58 +02:00 committed by Valere
parent 3d03bf6f91
commit dcae051e85
6 changed files with 49 additions and 27 deletions

View file

@ -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.
*/

View file

@ -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)

View file

@ -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
}
}

View file

@ -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.
*/

View file

@ -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
}

View file

@ -61,12 +61,8 @@ internal class DefaultCallService @Inject constructor(
override fun sendOfferSdp(callId: String, roomId: String, sdp: SessionDescription, callback: MatrixCallback<String>) {
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<String>) {
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<IceCandidate>) {
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<CallAnswerContent>()?.let {