diff --git a/Makefile b/Makefile index e916eb0..622a72c 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ pigeon: # Generates the typesafe bridge between host and flutter flutter pub run pigeon \ - --input lib/src/HostApisDefinition.dart \ - --dart_out lib/src/HostApis.dart \ - --objc_header_out ios/Classes/HostApis.h \ - --objc_source_out ios/Classes/HostApis.m \ - --java_out ./android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java \ + --input lib/src/PlatformBridgeApisDefinition.dart \ + --dart_out lib/src/PlatformBridgeApis.dart \ + --objc_header_out ios/Classes/PlatformBridgeApis.h \ + --objc_source_out ios/Classes/PlatformBridgeApis.m \ + --java_out ./android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java \ --java_package "com.gianlucaparadise.flutter_cast_framework" \ No newline at end of file diff --git a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java similarity index 94% rename from android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java rename to android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java index ec66206..3015125 100644 --- a/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java +++ b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/PlatformBridgeApis.java @@ -17,7 +17,7 @@ import java.util.HashMap; /** Generated class from Pigeon. */ @SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) -public class HostApis { +public class PlatformBridgeApis { /** Generated class from Pigeon that represents data sent in messages. */ public static class CastMessage { @@ -44,9 +44,9 @@ public class HostApis { return fromMapResult; } } - private static class CastApiCodec extends StandardMessageCodec { - public static final CastApiCodec INSTANCE = new CastApiCodec(); - private CastApiCodec() {} + private static class CastHostApiCodec extends StandardMessageCodec { + public static final CastHostApiCodec INSTANCE = new CastHostApiCodec(); + private CastHostApiCodec() {} @Override protected Object readValueOfType(byte type, ByteBuffer buffer) { switch (type) { @@ -71,20 +71,20 @@ public class HostApis { } /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ - public interface CastApi { + public interface CastHostApi { void sendMessage(CastMessage message); void showCastDialog(); - /** The codec used by CastApi. */ + /** The codec used by CastHostApi. */ static MessageCodec getCodec() { - return CastApiCodec.INSTANCE; + return CastHostApiCodec.INSTANCE; } - /** Sets up an instance of `CastApi` to handle messages through the `binaryMessenger`. */ - static void setup(BinaryMessenger binaryMessenger, CastApi api) { + /** Sets up an instance of `CastHostApi` to handle messages through the `binaryMessenger`. */ + static void setup(BinaryMessenger binaryMessenger, CastHostApi api) { { BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.sendMessage", getCodec()); + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.sendMessage", getCodec()); if (api != null) { channel.setMessageHandler((message, reply) -> { Map wrapped = new HashMap<>(); @@ -108,7 +108,7 @@ public class HostApis { } { BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.showCastDialog", getCodec()); + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastHostApi.showCastDialog", getCodec()); if (api != null) { channel.setMessageHandler((message, reply) -> { Map wrapped = new HashMap<>(); @@ -182,6 +182,13 @@ public class HostApis { callback.reply(null); }); } + public void onMessageReceived(CastMessage messageArg, Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onMessageReceived", getCodec()); + channel.send(new ArrayList(Arrays.asList(messageArg)), channelReply -> { + callback.reply(null); + }); + } public void onSessionStarting(Reply callback) { BasicMessageChannel channel = new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onSessionStarting", getCodec()); @@ -245,13 +252,6 @@ public class HostApis { callback.reply(null); }); } - public void onMessageReceived(CastMessage messageArg, Reply callback) { - BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onMessageReceived", getCodec()); - channel.send(new ArrayList(Arrays.asList(messageArg)), channelReply -> { - callback.reply(null); - }); - } } private static Map wrapError(Throwable exception) { Map errorMap = new HashMap<>(); diff --git a/ios/Classes/HostApis.h b/ios/Classes/PlatformBridgeApis.h similarity index 89% rename from ios/Classes/HostApis.h rename to ios/Classes/PlatformBridgeApis.h index ee25664..37e9b96 100644 --- a/ios/Classes/HostApis.h +++ b/ios/Classes/PlatformBridgeApis.h @@ -15,15 +15,15 @@ NS_ASSUME_NONNULL_BEGIN @property(nonatomic, copy, nullable) NSString * message; @end -/// The codec used by CastApi. -NSObject *CastApiGetCodec(void); +/// The codec used by CastHostApi. +NSObject *CastHostApiGetCodec(void); -@protocol CastApi +@protocol CastHostApi - (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error; - (void)showCastDialogWithError:(FlutterError *_Nullable *_Nonnull)error; @end -extern void CastApiSetup(id binaryMessenger, NSObject *_Nullable api); +extern void CastHostApiSetup(id binaryMessenger, NSObject *_Nullable api); /// The codec used by CastFlutterApi. NSObject *CastFlutterApiGetCodec(void); @@ -32,6 +32,7 @@ NSObject *CastFlutterApiGetCodec(void); - (instancetype)initWithBinaryMessenger:(id)binaryMessenger; - (void)getSessionMessageNamespacesWithCompletion:(void(^)(NSArray *, NSError *_Nullable))completion; - (void)onCastStateChangedCastState:(NSNumber *)castState completion:(void(^)(NSError *_Nullable))completion; +- (void)onMessageReceivedMessage:(CastMessage *)message completion:(void(^)(NSError *_Nullable))completion; - (void)onSessionStartingWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionStartedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionStartFailedWithCompletion:(void(^)(NSError *_Nullable))completion; @@ -41,6 +42,5 @@ NSObject *CastFlutterApiGetCodec(void); - (void)onSessionResumedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionResumeFailedWithCompletion:(void(^)(NSError *_Nullable))completion; - (void)onSessionSuspendedWithCompletion:(void(^)(NSError *_Nullable))completion; -- (void)onMessageReceivedMessage:(CastMessage *)message completion:(void(^)(NSError *_Nullable))completion; @end NS_ASSUME_NONNULL_END diff --git a/ios/Classes/HostApis.m b/ios/Classes/PlatformBridgeApis.m similarity index 89% rename from ios/Classes/HostApis.m rename to ios/Classes/PlatformBridgeApis.m index 12641d3..83009cf 100644 --- a/ios/Classes/HostApis.m +++ b/ios/Classes/PlatformBridgeApis.m @@ -1,6 +1,6 @@ // Autogenerated from Pigeon (v1.0.8), do not edit directly. // See also: https://pub.dev/packages/pigeon -#import "HostApis.h" +#import "PlatformBridgeApis.h" #import #if !__has_feature(objc_arc) @@ -45,9 +45,9 @@ static NSDictionary *wrapResult(id result, FlutterError *error) } @end -@interface CastApiCodecReader : FlutterStandardReader +@interface CastHostApiCodecReader : FlutterStandardReader @end -@implementation CastApiCodecReader +@implementation CastHostApiCodecReader - (nullable id)readValueOfType:(UInt8)type { switch (type) { @@ -61,9 +61,9 @@ static NSDictionary *wrapResult(id result, FlutterError *error) } @end -@interface CastApiCodecWriter : FlutterStandardWriter +@interface CastHostApiCodecWriter : FlutterStandardWriter @end -@implementation CastApiCodecWriter +@implementation CastHostApiCodecWriter - (void)writeValue:(id)value { if ([value isKindOfClass:[CastMessage class]]) { @@ -76,37 +76,37 @@ static NSDictionary *wrapResult(id result, FlutterError *error) } @end -@interface CastApiCodecReaderWriter : FlutterStandardReaderWriter +@interface CastHostApiCodecReaderWriter : FlutterStandardReaderWriter @end -@implementation CastApiCodecReaderWriter +@implementation CastHostApiCodecReaderWriter - (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { - return [[CastApiCodecWriter alloc] initWithData:data]; + return [[CastHostApiCodecWriter alloc] initWithData:data]; } - (FlutterStandardReader *)readerWithData:(NSData *)data { - return [[CastApiCodecReader alloc] initWithData:data]; + return [[CastHostApiCodecReader alloc] initWithData:data]; } @end -NSObject *CastApiGetCodec() { +NSObject *CastHostApiGetCodec() { static dispatch_once_t s_pred = 0; static FlutterStandardMessageCodec *s_sharedObject = nil; dispatch_once(&s_pred, ^{ - CastApiCodecReaderWriter *readerWriter = [[CastApiCodecReaderWriter alloc] init]; + CastHostApiCodecReaderWriter *readerWriter = [[CastHostApiCodecReaderWriter alloc] init]; s_sharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; }); return s_sharedObject; } -void CastApiSetup(id binaryMessenger, NSObject *api) { +void CastHostApiSetup(id binaryMessenger, NSObject *api) { { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.CastApi.sendMessage" + messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.sendMessage" binaryMessenger:binaryMessenger - codec:CastApiGetCodec()]; + codec:CastHostApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(sendMessageMessage:error:)], @"CastApi api (%@) doesn't respond to @selector(sendMessageMessage:error:)", api); + NSCAssert([api respondsToSelector:@selector(sendMessageMessage:error:)], @"CastHostApi api (%@) doesn't respond to @selector(sendMessageMessage:error:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { NSArray *args = message; CastMessage *arg_message = args[0]; @@ -122,11 +122,11 @@ void CastApiSetup(id binaryMessenger, NSObject { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.CastApi.showCastDialog" + messageChannelWithName:@"dev.flutter.pigeon.CastHostApi.showCastDialog" binaryMessenger:binaryMessenger - codec:CastApiGetCodec()]; + codec:CastHostApiGetCodec()]; if (api) { - NSCAssert([api respondsToSelector:@selector(showCastDialogWithError:)], @"CastApi api (%@) doesn't respond to @selector(showCastDialogWithError:)", api); + NSCAssert([api respondsToSelector:@selector(showCastDialogWithError:)], @"CastHostApi api (%@) doesn't respond to @selector(showCastDialogWithError:)", api); [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { FlutterError *error; [api showCastDialogWithError:&error]; @@ -225,6 +225,16 @@ NSObject *CastFlutterApiGetCodec() { completion(nil); }]; } +- (void)onMessageReceivedMessage:(CastMessage *)arg_message completion:(void(^)(NSError *_Nullable))completion { + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.CastFlutterApi.onMessageReceived" + binaryMessenger:self.binaryMessenger + codec:CastFlutterApiGetCodec()]; + [channel sendMessage:@[arg_message] reply:^(id reply) { + completion(nil); + }]; +} - (void)onSessionStartingWithCompletion:(void(^)(NSError *_Nullable))completion { FlutterBasicMessageChannel *channel = [FlutterBasicMessageChannel @@ -315,14 +325,4 @@ NSObject *CastFlutterApiGetCodec() { completion(nil); }]; } -- (void)onMessageReceivedMessage:(CastMessage *)arg_message completion:(void(^)(NSError *_Nullable))completion { - FlutterBasicMessageChannel *channel = - [FlutterBasicMessageChannel - messageChannelWithName:@"dev.flutter.pigeon.CastFlutterApi.onMessageReceived" - binaryMessenger:self.binaryMessenger - codec:CastFlutterApiGetCodec()]; - [channel sendMessage:@[arg_message] reply:^(id reply) { - completion(nil); - }]; -} @end diff --git a/lib/src/HostApis.dart b/lib/src/PlatformBridgeApis.dart similarity index 94% rename from lib/src/HostApis.dart rename to lib/src/PlatformBridgeApis.dart index 88a6918..d4d6fe9 100644 --- a/lib/src/HostApis.dart +++ b/lib/src/PlatformBridgeApis.dart @@ -27,8 +27,8 @@ class CastMessage { } } -class _CastApiCodec extends StandardMessageCodec { - const _CastApiCodec(); +class _CastHostApiCodec extends StandardMessageCodec { + const _CastHostApiCodec(); @override void writeValue(WriteBuffer buffer, Object? value) { if (value is CastMessage) { @@ -52,19 +52,19 @@ class _CastApiCodec extends StandardMessageCodec { } } -class CastApi { - /// Constructor for [CastApi]. The [binaryMessenger] named argument is +class CastHostApi { + /// Constructor for [CastHostApi]. The [binaryMessenger] named argument is /// available for dependency injection. If it is left null, the default /// BinaryMessenger will be used which routes to the host platform. - CastApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; + CastHostApi({BinaryMessenger? binaryMessenger}) : _binaryMessenger = binaryMessenger; final BinaryMessenger? _binaryMessenger; - static const MessageCodec codec = _CastApiCodec(); + static const MessageCodec codec = _CastHostApiCodec(); Future sendMessage(CastMessage arg_message) async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.CastApi.sendMessage', codec, binaryMessenger: _binaryMessenger); + 'dev.flutter.pigeon.CastHostApi.sendMessage', codec, binaryMessenger: _binaryMessenger); final Map? replyMap = await channel.send([arg_message]) as Map?; if (replyMap == null) { @@ -87,7 +87,7 @@ class CastApi { Future showCastDialog() async { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.CastApi.showCastDialog', codec, binaryMessenger: _binaryMessenger); + 'dev.flutter.pigeon.CastHostApi.showCastDialog', codec, binaryMessenger: _binaryMessenger); final Map? replyMap = await channel.send(null) as Map?; if (replyMap == null) { @@ -138,6 +138,7 @@ abstract class CastFlutterApi { List getSessionMessageNamespaces(); void onCastStateChanged(int castState); + void onMessageReceived(CastMessage message); void onSessionStarting(); void onSessionStarted(); void onSessionStartFailed(); @@ -147,7 +148,6 @@ abstract class CastFlutterApi { void onSessionResumed(); void onSessionResumeFailed(); void onSessionSuspended(); - void onMessageReceived(CastMessage message); static void setup(CastFlutterApi? api) { { const BasicMessageChannel channel = BasicMessageChannel( @@ -178,6 +178,22 @@ abstract class CastFlutterApi { }); } } + { + const BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastFlutterApi.onMessageReceived', codec); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null.'); + final List args = (message as List?)!; + final CastMessage? arg_message = args[0] as CastMessage?; + assert(arg_message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null, expected non-null CastMessage.'); + api.onMessageReceived(arg_message!); + return; + }); + } + } { const BasicMessageChannel channel = BasicMessageChannel( 'dev.flutter.pigeon.CastFlutterApi.onSessionStarting', codec); @@ -295,21 +311,5 @@ abstract class CastFlutterApi { }); } } - { - const BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.CastFlutterApi.onMessageReceived', codec); - if (api == null) { - channel.setMessageHandler(null); - } else { - channel.setMessageHandler((Object? message) async { - assert(message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null.'); - final List args = (message as List?)!; - final CastMessage? arg_message = args[0] as CastMessage?; - assert(arg_message != null, 'Argument for dev.flutter.pigeon.CastFlutterApi.onMessageReceived was null, expected non-null CastMessage.'); - api.onMessageReceived(arg_message!); - return; - }); - } - } } } diff --git a/lib/src/HostApisDefinition.dart b/lib/src/PlatformBridgeApisDefinition.dart similarity index 95% rename from lib/src/HostApisDefinition.dart rename to lib/src/PlatformBridgeApisDefinition.dart index d0b4a51..d623bf2 100644 --- a/lib/src/HostApisDefinition.dart +++ b/lib/src/PlatformBridgeApisDefinition.dart @@ -6,7 +6,7 @@ class CastMessage { } @HostApi() -abstract class CastApi { +abstract class CastHostApi { void sendMessage(CastMessage message); void showCastDialog(); }