Skip to content

Commit

Permalink
添加Rtc扩展方法
Browse files Browse the repository at this point in the history
  • Loading branch information
shenbengit committed Nov 3, 2023
1 parent c0ecccd commit 2e080df
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.shencoder.webrtcextension.ext


/**
*
* @author Shenben
* @date 2023/11/3 10:28
* @description
* @since
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.shencoder.webrtcextension.ext

import org.webrtc.SdpObserver
import org.webrtc.SessionDescription
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine


/**
*
* @author Shenben
* @date 2023/11/3 10:32
* @description
* @since
*/

suspend inline fun createSessionDescription(crossinline call: (SdpObserver) -> Unit): Result<SessionDescription> =
suspendCoroutine {
val observer = object : SdpObserver {
override fun onCreateSuccess(sdp: SessionDescription?) {
if (sdp != null) {
it.resume(Result.success(sdp))
} else {
it.resume(Result.failure(RuntimeException("SessionDescription is null!")))
}
}

override fun onCreateFailure(error: String?) =
it.resume(Result.failure(RuntimeException(error)))

override fun onSetSuccess() = Unit
override fun onSetFailure(error: String?) = Unit
}

call(observer)
}

suspend inline fun suspendSdpObserver(crossinline call: (SdpObserver) -> Unit): Result<Unit> =
suspendCoroutine {
val observer = object : SdpObserver {

override fun onCreateFailure(error: String?) = Unit
override fun onCreateSuccess(sdp: SessionDescription?) = Unit

override fun onSetSuccess() = it.resume(Result.success(Unit))
override fun onSetFailure(error: String?) =
it.resume(Result.failure(RuntimeException(error)))
}
call(observer)
}

0 comments on commit 2e080df

Please sign in to comment.