Closed yooneskh closed 3 years ago
I tested the android demo and found out something interesting. I added some logs in the code as below.
Log.e("test", "on router :: " + routerRtpCapabilities);
mMediasoupDevice.load(routerRtpCapabilities);
String rtpCapabilities = mMediasoupDevice.getRtpCapabilities();
Log.e("test", "on load :: " + rtpCapabilities);
What i saw was that the first log always happens, but the second log only happened in the first and second time i opened the app. after that i did not see the second log, but my video and audio is actually loaded in the app and i can see it streaming!
Such a thing does not happen in my own app in kotlin. i cannot get past device.load in any way
I tried putting the load in another thread (with HandlerThread) and nothing changed.
private lateinit var handlerThread: HandlerThread
private lateinit var workHandler: Handler
override fun onCreate() {
handlerThread = HandlerThread("worker")
handlerThread.start()
defer(1000) {
workHandler = Handler(handlerThread.looper)
beginConnection()
}
}
private fun beginConnection() = runWithPermissions( Manifest.permission.INTERNET, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE) {
workHandler.post { beginLoading() }
}
lateinit var device: Device
private fun beginLoading() {
YSocket.needsAuthentication = false
YSocket.connect()
debug("connecting")
YSocket.onDisconnected { debug("disconnected!!!") }
YSocket.onConnected {
debug("connected")
workHandler.post {
device = Device()
YSocket.emit("getRouterRtpCapabilities")
YSocket.on("routerRtpCapabilities", Emitter.Listener { data ->
debug("on router rtp")
device.load(data[0] as String)
val rtpCapabilities = device.rtpCapabilities
debug("on device loaded :: $rtpCapabilities")
createSendTransport()
// createReceiveTransport()
//
// enableMic()
// enableCam()
})
}
}
}
private fun createSendTransport() {
}
I can see this in the logs
2020-07-21 14:24:54.226 15524-15660/ir.yooneskh.markazeteb I/mediasoupclient-jni: [TRACE] device_jni::JNI_Device_NewDevice()
But nothing else from JNI or mediasoup. Log level is set to debug.
Logger.setLogLevel(Logger.LogLevel.LOG_DEBUG)
Logger.setDefaultHandler()
MediasoupClient.initialize(this)
I just found out that if i give {}
as the result of routerRtpCapabilities
to the device.load
, the function does not block and gives me the result (although empty codecs and headers, which is expected). So the problem is rooted in the codecs i have defined for my router in the server but i cannot decide what codecs to give for it to work. i copied the codecs in the mediasoup-demo
server but it didn't work. any ideas?
Just out of interest does the below work?
mediaCodecs: [
{
kind: "audio",
mimeType: "audio/opus",
clockRate: 48000,
channels: 2
},
{
kind" video",
mimeType": video/VP8",
clockRate: 90000
}
]
@ethand91 No this was the original codecs i used. I worked for web but not in android.
Ok so this was a false alarm, sorry everyone. a note to all future readers.
If you are developing android application in Kotlin
and use Socket.IO
, note that Emitter.Listener
does not give you strings!
My problem was this part of the code.
YSocket.on("routerRtpCapabilities", Emitter.Listener { data ->
device.load(data[0] as String)
})
data is not an array of strings apparently, each array item is a kind of ByteArray
. data[0]
will be printed correctly because .toString()
will be called on it implicitly.
So the correct way of handling it is this.
YSocket.on("routerRtpCapabilities", Emitter.Listener { data ->
device.load(data[0].toString())
})
The only thing that bugs me is that why it failed silently? why was there no errors? incorrect casting usually gives big fat errors. Is it because if JNI?
I am trying to do a simple loopback sample in android. I have already done this in the web client and the server works correctly there. I have pasted the relevant codes below.
This gets printed
But somehow the code gets stuck at device.load and the next debug does not get printed. there is no error or anything.
This might be relevant too.
With More Detail