diff --git a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java index 82998c4..2302e02 100644 --- a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java +++ b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java @@ -73,6 +73,7 @@ public class HostApis { /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ public interface CastApi { void sendMessage(CastMessage message); + void showCastDialog(); /** The codec used by CastApi. */ static MessageCodec getCodec() { @@ -105,6 +106,25 @@ public class HostApis { channel.setMessageHandler(null); } } + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.showCastDialog", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + api.showCastDialog(); + wrapped.put("result", null); + } + catch (Error | RuntimeException exception) { + wrapped.put("error", wrapError(exception)); + } + reply.reply(wrapped); + }); + } else { + channel.setMessageHandler(null); + } + } } } private static Map wrapError(Throwable exception) { diff --git a/ios/Classes/HostApis.h b/ios/Classes/HostApis.h index 79f3c21..11ccbc1 100644 --- a/ios/Classes/HostApis.h +++ b/ios/Classes/HostApis.h @@ -20,6 +20,7 @@ NSObject *CastApiGetCodec(void); @protocol CastApi - (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error; +- (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error; @end extern void CastApiSetup(id binaryMessenger, NSObject *_Nullable api); diff --git a/ios/Classes/HostApis.m b/ios/Classes/HostApis.m index bd7fca8..b02db2f 100644 --- a/ios/Classes/HostApis.m +++ b/ios/Classes/HostApis.m @@ -119,4 +119,22 @@ void CastApiSetup(id binaryMessenger, NSObject [channel setMessageHandler:nil]; } } + { + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.CastApi.showCastDialog" + binaryMessenger:binaryMessenger + codec:CastApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(showCastDialogWithError:)], @"CastApi api (%@) doesn't respond to @selector(showCastDialogWithError:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + FlutterError *error; + [api showCastDialogWithError:&error]; + callback(wrapResult(nil, error)); + }]; + } + else { + [channel setMessageHandler:nil]; + } + } } diff --git a/lib/src/HostApis.dart b/lib/src/HostApis.dart index f03dbd4..ff687c2 100644 --- a/lib/src/HostApis.dart +++ b/lib/src/HostApis.dart @@ -84,4 +84,27 @@ class CastApi { return; } } + + Future showCastDialog() async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastApi.showCastDialog', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send(null) as Map?; + if (replyMap == null) { + throw PlatformException( + code: 'channel-error', + message: 'Unable to establish connection on channel.', + details: null, + ); + } else if (replyMap['error'] != null) { + final Map error = (replyMap['error'] as Map?)!; + throw PlatformException( + code: (error['code'] as String?)!, + message: error['message'] as String?, + details: error['details'], + ); + } else { + return; + } + } } diff --git a/lib/src/HostApisDefinition.dart b/lib/src/HostApisDefinition.dart index 4249c84..5917d89 100644 --- a/lib/src/HostApisDefinition.dart +++ b/lib/src/HostApisDefinition.dart @@ -8,4 +8,5 @@ class CastMessage { @HostApi() abstract class CastApi { void sendMessage(CastMessage message); + void showCastDialog(); } \ No newline at end of file