-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c0ecccd
commit 2e080df
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
extension-lib/src/main/java/com/shencoder/webrtcextension/ext/PeerConnectionExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
50 changes: 50 additions & 0 deletions
50
extension-lib/src/main/java/com/shencoder/webrtcextension/ext/SdpExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |