Skip to content

Commit

Permalink
Refactoring and fixes in android bridge (roc-streaming#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv committed Oct 5, 2024
1 parent 03e0278 commit 4be3eb0
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 284 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Autogenerated from Pigeon (v21.1.0), do not edit directly.
// Autogenerated from Pigeon (v22.3.0), do not edit directly.
// See also: https://pub.dev/packages/pigeon
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")

Expand Down Expand Up @@ -42,7 +42,7 @@ class FlutterError (
override val message: String? = null,
val details: Any? = null
) : Throwable()
private object ConnectorPigeonCodec : StandardMessageCodec() {
private open class AndroidConnectorPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return super.readValueOfType(type, buffer)
}
Expand All @@ -56,7 +56,7 @@ private object ConnectorPigeonCodec : StandardMessageCodec() {
*
* Generated interface from Pigeon that represents a handler of messages from Flutter.
*/
interface Backend {
interface AndroidConnector {
fun startReceiver()
fun stopReceiver()
fun isReceiverAlive(): Boolean
Expand All @@ -65,16 +65,16 @@ interface Backend {
fun isSenderAlive(): Boolean

companion object {
/** The codec used by Backend. */
/** The codec used by AndroidConnector. */
val codec: MessageCodec<Any?> by lazy {
ConnectorPigeonCodec
AndroidConnectorPigeonCodec()
}
/** Sets up an instance of `Backend` to handle messages through the `binaryMessenger`. */
/** Sets up an instance of `AndroidConnector` to handle messages through the `binaryMessenger`. */
@JvmOverloads
fun setUp(binaryMessenger: BinaryMessenger, api: Backend?, messageChannelSuffix: String = "") {
fun setUp(binaryMessenger: BinaryMessenger, api: AndroidConnector?, messageChannelSuffix: String = "") {
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid_package.Backend.startReceiver$separatedMessageChannelSuffix", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid.AndroidConnector.startReceiver$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
val wrapped: List<Any?> = try {
Expand All @@ -90,7 +90,7 @@ interface Backend {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid_package.Backend.stopReceiver$separatedMessageChannelSuffix", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid.AndroidConnector.stopReceiver$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
val wrapped: List<Any?> = try {
Expand All @@ -106,7 +106,7 @@ interface Backend {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid_package.Backend.isReceiverAlive$separatedMessageChannelSuffix", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid.AndroidConnector.isReceiverAlive$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
val wrapped: List<Any?> = try {
Expand All @@ -121,7 +121,7 @@ interface Backend {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid_package.Backend.startSender$separatedMessageChannelSuffix", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid.AndroidConnector.startSender$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
Expand All @@ -139,7 +139,7 @@ interface Backend {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid_package.Backend.stopSender$separatedMessageChannelSuffix", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid.AndroidConnector.stopSender$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
val wrapped: List<Any?> = try {
Expand All @@ -155,7 +155,7 @@ interface Backend {
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid_package.Backend.isSenderAlive$separatedMessageChannelSuffix", codec)
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.roc_droid.AndroidConnector.isSenderAlive$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { _, reply ->
val wrapped: List<Any?> = try {
Expand All @@ -171,6 +171,4 @@ interface Backend {
}
}
}

fun getHostLanguage(): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.rocstreaming.connector

import AndroidConnector
import android.util.Log
import org.rocstreaming.service.SenderReceiverService

private const val LOG_TAG = "[rocdroid.Connector]"

class AndroidConnectorImpl : AndroidConnector {
//private var senderReceiverService: SenderReceiverService = SenderReceiverService()

override fun startReceiver() {
Log.d(LOG_TAG, "Start Receiver")
//senderReceiverService.startReceiver()
}

override fun stopReceiver() {
Log.d(LOG_TAG, "Stop Receiver")
//senderReceiverService.stopReceiver()
}

override fun isReceiverAlive(): Boolean {
//return senderReceiverService.isReceiverAlive()
return true
}

override fun startSender(ip: String) {
Log.d(LOG_TAG, "Start Sender")
//senderReceiverService.startSender(ip, null)
}

override fun stopSender() {
Log.d(LOG_TAG, "Stop Sender")
//senderReceiverService.stopSender()
}

override fun isSenderAlive(): Boolean {
//return senderReceiverService.isSenderAlive()
return true
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ package org.rocstreaming.rocdroid
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.plugins.FlutterPlugin
import org.rocstreaming.connector.AndroidConnectorImpl

class MainActivity: FlutterActivity(){
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
}}

AndroidConnector.setUp(flutterEngine.dartExecutor.binaryMessenger,
AndroidConnectorImpl())
}
}
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ org.gradle.jvmargs=-Xmx4G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
minSdkVersion=26
compileSdkVersion=33
2 changes: 1 addition & 1 deletion dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def task_gen_model_watch():
def task_gen_agent():
"""run flutter pigeon Agent code generation"""
return {
'actions': ['dart run pigeon --input lib/src/agent/ibackend.dart'],
'actions': ['dart run pigeon --input lib/src/agent/android_connector.dart'],
'title': title_with_actions,
}

Expand Down
27 changes: 14 additions & 13 deletions lib/src/agent/android_backend.dart
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import 'backend.g.dart';
import 'android_connector.g.dart';
import 'backend.dart';

/// ???.
class AndroidBackend implements Backend {
final Backend _backend = Backend();
final AndroidConnector _connector = AndroidConnector();

@override
Future<bool> isReceiverAlive() async {
return await _backend.isReceiverAlive();
Future<void> startReceiver() async {
await _connector.startReceiver();
}

@override
Future<bool> isSenderAlive() async {
return await _backend.isSenderAlive();
Future<void> stopReceiver() async {
await _connector.stopReceiver();
}

@override
Future<void> startReceiver() async {
await _backend.startReceiver();
Future<bool> isReceiverAlive() async {
return await _connector.isReceiverAlive();
}

@override
Future<void> startSender(String ip) async {
await _backend.startSender(ip);
await _connector.startSender(ip);
}

@override
Future<void> stopReceiver() async {
await _backend.stopReceiver();
Future<void> stopSender() async {
await _connector.stopSender();
}

@override
Future<void> stopSender() async {
await _backend.stopSender();
Future<bool> isSenderAlive() async {
return await _connector.isSenderAlive();
}
}
32 changes: 32 additions & 0 deletions lib/src/agent/android_connector.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:pigeon/pigeon.dart';

@ConfigurePigeon(PigeonOptions(
dartOut: 'lib/src/agent/android_connector.g.dart',
dartOptions: DartOptions(),
kotlinOut:
'android/app/src/main/kotlin/org/rocstreaming/connector/AndroidConnector.g.kt',
kotlinOptions: KotlinOptions(),
dartPackageName: 'roc_droid',
))

/// ???.
@HostApi()
abstract class AndroidConnector {
void startReceiver();

void stopReceiver();

bool isReceiverAlive();

void startSender(String ip);

void stopSender();

bool isSenderAlive();
}

// /// ???.
// @FlutterApi()
// abstract class FlutterHandler {
// void textChanged(String text);
// }
Loading

0 comments on commit 4be3eb0

Please sign in to comment.