Skip to content

Commit

Permalink
fix data channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Quarken committed Jun 28, 2024
1 parent c53d3ef commit 2815490
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ data class SDP(
val sdp: String
)

private fun StringTypeFromSdp(sdp: SessionDescription) = when (sdp.type) {
SessionDescription.Type.OFFER -> "offer"
SessionDescription.Type.PRANSWER -> "pranswer"
SessionDescription.Type.ANSWER -> "answer"
SessionDescription.Type.ROLLBACK -> "rollback"
null -> throw IllegalArgumentException("StringTypeFromSdp called with null as argument")
}

private fun SignalMessageTypeFromSdp(sdp: SessionDescription) = when (sdp.type) {
SessionDescription.Type.OFFER -> SignalMessageType.OFFER
SessionDescription.Type.PRANSWER -> SignalMessageType.ANSWER
SessionDescription.Type.ANSWER -> SignalMessageType.ANSWER
SessionDescription.Type.ROLLBACK -> SignalMessageType.OFFER
null -> throw IllegalArgumentException("StringTypeFromSdp called with null as argument")
}

internal class EdgeWebrtcConnectionImpl(
conn: Connection
) : EdgeWebrtcConnection, PeerConnection.Observer, RendererCommon.RendererEvents {
Expand Down Expand Up @@ -184,13 +200,8 @@ internal class EdgeWebrtcConnectionImpl(

private suspend fun sendDescription(sdp: SessionDescription) {
EdgeLogger.info("Sending description to peer: ${sdp.description}")
val data = jsonMapper.writeValueAsString(SDP("answer", sdp.description))
val type = when (sdp.type) {
SessionDescription.Type.OFFER -> SignalMessageType.OFFER
SessionDescription.Type.ANSWER -> SignalMessageType.ANSWER
else -> SignalMessageType.OFFER
}
val msg = SignalMessage(type = type, data = data, metadata = createMetadata())
val data = jsonMapper.writeValueAsString(SDP(StringTypeFromSdp(sdp), sdp.description))
val msg = SignalMessage(type = SignalMessageTypeFromSdp(sdp), data = data, metadata = createMetadata())
val sendPromise = signaling.send(msg)
try {
sendPromise.await()
Expand Down
4 changes: 3 additions & 1 deletion webrtc/src/main/java/com/nabto/edge/client/webrtc/webrtc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.util.AttributeSet
import com.nabto.edge.client.Connection
import com.nabto.edge.client.webrtc.impl.EdgeWebrtcManagerInternal
import io.getstream.webrtc.android.ui.VideoTextureViewRenderer
import java.util.concurrent.CompletableFuture

// @TODO: Make our own TextureViewRenderer implementation?
// @TODO: Make a Jetpack Composable View?
Expand Down Expand Up @@ -235,7 +236,7 @@ interface EdgeWebrtcConnection {

/**
* Create a new data channel
* WARNING: Experimental
* WARNING: Data channels are experimental and may not work as expected.
*
* @param label A string that describes the data channel.
*/
Expand Down Expand Up @@ -285,6 +286,7 @@ interface EdgeWebrtcManager {
fun createRTCConnection(conn: Connection): EdgeWebrtcConnection

companion object {
@JvmStatic
fun getInstance(): EdgeWebrtcManager = EdgeWebrtcManagerInternal.instance
}
}

0 comments on commit 2815490

Please sign in to comment.