Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions whip/src/main/java/com/pedro/whip/WhipClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,18 @@ class WhipClient(private val connectChecker: ConnectChecker) {
Log.i(TAG, "found ${localCandidates.size} candidates")
val offerResponse = commandsManager.writeOffer()
Log.i(TAG, offerResponse.body)

if (offerResponse.statusCode !in 200..299) {
if (offerResponse.statusCode == 401 || offerResponse.statusCode == 403) {
onMainThread { connectChecker.onAuthError() }
} else {
onMainThread {
connectChecker.onConnectionFailed("Write offer failed: ${offerResponse.statusCode}")
}
}
return@launch
} else if (commandsManager.authEnabled()) {
onMainThread { connectChecker.onAuthSuccess() }
}

val localFrag = commandsManager.localSdpInfo?.uFrag ?: return@launch
val remoteFrag = commandsManager.remoteSdpInfo?.uFrag ?: return@launch
Expand Down Expand Up @@ -388,7 +399,9 @@ class WhipClient(private val connectChecker: ConnectChecker) {
dtlsConnection?.close()
dtlsConnection = null
val error = runCatching {
//TODO write delete command
withTimeoutOrNull(100.milliseconds) {
commandsManager.writeDelete()
}
Log.i(TAG, "write delete success")
}.exceptionOrNull()
if (error != null) {
Expand Down Expand Up @@ -493,5 +506,4 @@ class WhipClient(private val connectChecker: ConnectChecker) {
whipSender.resetBytesSend()
}


}
2 changes: 1 addition & 1 deletion whip/src/main/java/com/pedro/whip/utils/Requests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Requests {
val responseHeaders = mutableMapOf<String, String>()
socket.headerFields.forEach {
try {
responseHeaders.put(it.key, it.value.joinToString(", "))
responseHeaders[it.key] = it.value.joinToString(", ")
} catch (_: Exception){}
}
val bodyResult = String(bytes)
Expand Down
18 changes: 18 additions & 0 deletions whip/src/main/java/com/pedro/whip/webrtc/CommandsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ class CommandsManager {
return answer
}

fun writeDelete(): RequestResponse {
val uri = "${if (tlsEnabled) "https" else "http"}://$host:$port/$path"
val headers = mutableMapOf<String, String>().apply {
if (!token.isNullOrEmpty()) put("Authorization", "Bearer $token")
}
return Requests.makeRequest(
uri,
"DELETE",
headers,
null,
timeout,
tlsEnabled,
certificates
)
}

private suspend fun getStunCandidates(
socketType: SocketType,
stunHost: String,
Expand Down Expand Up @@ -335,4 +351,6 @@ class CommandsManager {
fun generateTransactionId(): ByteArray {
return secureRandom.nextBytes(12)
}

fun authEnabled(): Boolean = token != null
}
Loading