Skip to content

Commit

Permalink
- add constructor for typescript
Browse files Browse the repository at this point in the history
- fix Android `mapToChannelMediaInfo` crash
- fix iOS `switchChannel` `sendMetadata` crash
  • Loading branch information
LichKing-2234 committed Jul 9, 2020
1 parent d1d40f5 commit 93621d3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 10 deletions.
4 changes: 2 additions & 2 deletions BeanCovertor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ fun mapToLiveTranscoding(map: Map<*, *>): LiveTranscoding {

fun mapToChannelMediaInfo(map: Map<*, *>): ChannelMediaInfo {
return ChannelMediaInfo(
map["channelName"] as String,
map["token"] as String,
map["channelName"] as? String,
map["token"] as? String,
(map["uid"] as Number).toInt()
)
}
Expand Down
35 changes: 28 additions & 7 deletions Callback.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,38 @@ import io.agora.rtc.Constants
import io.agora.rtc.RtcEngine
import kotlin.math.abs

abstract class Callback<T> {
fun code(code: Int?) {
val newCode = code ?: Constants.ERR_NOT_INITIALIZED
if (newCode == 0) {
abstract class Callback {
fun code(code: Int?, runnable: ((Int) -> Any?)? = null) {
if (code == null || code < 0) {
val newCode = abs(code ?: Constants.ERR_NOT_INITIALIZED)
failure(newCode.toString(), RtcEngine.getErrorDescription(newCode))
return
}

val res = if (runnable != null) runnable(code) else Unit
if (res is Unit) {
success(null)
} else {
success(res)
}
}

fun <T> resolve(source: T?, runnable: (T) -> Any?) {
if (source == null) {
val code = Constants.ERR_NOT_INITIALIZED
failure(code.toString(), RtcEngine.getErrorDescription(code))
return
}

val res = runnable(source)
if (res is Unit) {
success(null)
} else if (newCode < 0) {
failure(newCode.toString(), RtcEngine.getErrorDescription(abs(newCode)))
} else {
success(res)
}
}

abstract fun success(data: T?)
abstract fun success(data: Any?)

abstract fun failure(code: String, message: String)
}
14 changes: 14 additions & 0 deletions RtcChannel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ class RtcChannelManager {
return Constants.ERR_NOT_INITIALIZED
}

fun createDataStream(channelId: String, reliable: Boolean, ordered: Boolean): Int {
this[channelId]?.let {
return@createDataStream it.createDataStream(reliable, ordered)
}
return Constants.ERR_NOT_INITIALIZED
}

fun sendStreamMessage(channelId: String, streamId: Int, message: String): Int {
this[channelId]?.let {
return@sendStreamMessage it.sendStreamMessage(streamId, message.toByteArray())
}
return Constants.ERR_NOT_INITIALIZED
}

interface RtcAudioInterface<Callback> {
fun adjustUserPlaybackSignalVolume(channelId: String, uid: Int, @IntRange(from = 0, to = 100) volume: Int, callback: Callback?)

Expand Down
8 changes: 7 additions & 1 deletion RtcSurfaceView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ import java.lang.ref.WeakReference
class RtcSurfaceView(
context: Context
) : FrameLayout(context) {
private var surface: SurfaceView = RtcEngine.CreateRendererView(context)
private var surface: SurfaceView
private var canvas: VideoCanvas
private var channel: WeakReference<RtcChannel>? = null

init {
try {
surface = RtcEngine.CreateRendererView(context)
} catch (e: UnsatisfiedLinkError) {
surface = SurfaceView(context)
e.printStackTrace()
}
canvas = VideoCanvas(surface)
addView(surface)
}
Expand Down

0 comments on commit 93621d3

Please sign in to comment.