Pigeon: Integrated sendMessage API in Kotlin
This commit is contained in:
parent
82c16ccd8c
commit
258cf8d607
3 changed files with 18 additions and 7 deletions
|
|
@ -54,6 +54,9 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
|
||||||
|
|
||||||
mMessageCastingChannel = MessageCastingChannel(methodChannel)
|
mMessageCastingChannel = MessageCastingChannel(methodChannel)
|
||||||
|
|
||||||
|
castApi = MyApi()
|
||||||
|
HostApis.CastApi.setup(messenger, castApi)
|
||||||
|
|
||||||
CastContext.getSharedInstance(applicationContext).addCastStateListener { i ->
|
CastContext.getSharedInstance(applicationContext).addCastStateListener { i ->
|
||||||
Log.d(TAG, "Cast state changed: $i")
|
Log.d(TAG, "Cast state changed: $i")
|
||||||
methodChannel.invokeMethod(MethodNames.onCastStateChanged, i)
|
methodChannel.invokeMethod(MethodNames.onCastStateChanged, i)
|
||||||
|
|
@ -98,6 +101,7 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
|
||||||
private val mSessionManagerListener = CastSessionManagerListener()
|
private val mSessionManagerListener = CastSessionManagerListener()
|
||||||
|
|
||||||
private var channel: MethodChannel? = null
|
private var channel: MethodChannel? = null
|
||||||
|
private var castApi : HostApis.CastApi? = null
|
||||||
private var applicationContext: Context? = null
|
private var applicationContext: Context? = null
|
||||||
private var activity: Activity? = null
|
private var activity: Activity? = null
|
||||||
|
|
||||||
|
|
@ -163,11 +167,17 @@ class FlutterCastFrameworkPlugin : FlutterPlugin, MethodCallHandler, ActivityAwa
|
||||||
|
|
||||||
CastDialogOpener.showCastDialog(context, activity)
|
CastDialogOpener.showCastDialog(context, activity)
|
||||||
}
|
}
|
||||||
MethodNames.sendMessage -> this.mMessageCastingChannel?.sendMessage(mCastSession, arguments)
|
|
||||||
else -> result.notImplemented()
|
else -> result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private inner class MyApi : HostApis.CastApi {
|
||||||
|
override fun sendMessage(message: HostApis.CastMessage?) {
|
||||||
|
mMessageCastingChannel?.sendMessage(mCastSession, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private inner class NamespaceResult(val oldSession: CastSession?, val newSession: CastSession?) : Result {
|
private inner class NamespaceResult(val oldSession: CastSession?, val newSession: CastSession?) : Result {
|
||||||
override fun notImplemented() {
|
override fun notImplemented() {
|
||||||
Log.d(TAG, "Updating mCastSession - notImplemented")
|
Log.d(TAG, "Updating mCastSession - notImplemented")
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,4 @@ object MethodNames {
|
||||||
|
|
||||||
const val getSessionMessageNamespaces = "CastSession.getSessionMessageNamespaces"
|
const val getSessionMessageNamespaces = "CastSession.getSessionMessageNamespaces"
|
||||||
const val onMessageReceived = "CastSession.onMessageReceived"
|
const val onMessageReceived = "CastSession.onMessageReceived"
|
||||||
const val sendMessage = "CastSession.sendMessage"
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.gianlucaparadise.flutter_cast_framework.cast
|
package com.gianlucaparadise.flutter_cast_framework.cast
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.gianlucaparadise.flutter_cast_framework.HostApis
|
||||||
import com.gianlucaparadise.flutter_cast_framework.MethodNames
|
import com.gianlucaparadise.flutter_cast_framework.MethodNames
|
||||||
import com.google.android.gms.cast.Cast
|
import com.google.android.gms.cast.Cast
|
||||||
import com.google.android.gms.cast.CastDevice
|
import com.google.android.gms.cast.CastDevice
|
||||||
|
|
@ -22,11 +23,12 @@ class MessageCastingChannel(private val channel: MethodChannel) : Cast.MessageRe
|
||||||
channel.invokeMethod(MethodNames.onMessageReceived, argsMap)
|
channel.invokeMethod(MethodNames.onMessageReceived, argsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sendMessage(castSession: CastSession?, arguments: Any) {
|
fun sendMessage(castSession: CastSession?, castMessage: HostApis.CastMessage?) {
|
||||||
Log.d(TAG, "Send Message arguments: $arguments:")
|
Log.d(TAG, "Send Message arguments: $castMessage:")
|
||||||
val argsMap = arguments as HashMap<String, String?>
|
if (castMessage == null) return
|
||||||
val namespace = argsMap["namespace"]
|
|
||||||
val message = argsMap["message"]
|
val namespace = castMessage.namespace
|
||||||
|
val message = castMessage.message
|
||||||
|
|
||||||
sendMessage(castSession, namespace, message)
|
sendMessage(castSession, namespace, message)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue