Pigeon: Renamed HostApis
This commit is contained in:
parent
1cf4e493d6
commit
1dd9ab2370
6 changed files with 82 additions and 82 deletions
10
Makefile
10
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"
|
||||
|
|
@ -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<Object> 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<Object> 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<String, Object> wrapped = new HashMap<>();
|
||||
|
|
@ -108,7 +108,7 @@ public class HostApis {
|
|||
}
|
||||
{
|
||||
BasicMessageChannel<Object> 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<String, Object> wrapped = new HashMap<>();
|
||||
|
|
@ -182,6 +182,13 @@ public class HostApis {
|
|||
callback.reply(null);
|
||||
});
|
||||
}
|
||||
public void onMessageReceived(CastMessage messageArg, Reply<Void> callback) {
|
||||
BasicMessageChannel<Object> channel =
|
||||
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onMessageReceived", getCodec());
|
||||
channel.send(new ArrayList<Object>(Arrays.asList(messageArg)), channelReply -> {
|
||||
callback.reply(null);
|
||||
});
|
||||
}
|
||||
public void onSessionStarting(Reply<Void> callback) {
|
||||
BasicMessageChannel<Object> 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<Void> callback) {
|
||||
BasicMessageChannel<Object> channel =
|
||||
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastFlutterApi.onMessageReceived", getCodec());
|
||||
channel.send(new ArrayList<Object>(Arrays.asList(messageArg)), channelReply -> {
|
||||
callback.reply(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
private static Map<String, Object> wrapError(Throwable exception) {
|
||||
Map<String, Object> errorMap = new HashMap<>();
|
||||
|
|
@ -15,15 +15,15 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property(nonatomic, copy, nullable) NSString * message;
|
||||
@end
|
||||
|
||||
/// The codec used by CastApi.
|
||||
NSObject<FlutterMessageCodec> *CastApiGetCodec(void);
|
||||
/// The codec used by CastHostApi.
|
||||
NSObject<FlutterMessageCodec> *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<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *_Nullable api);
|
||||
extern void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *_Nullable api);
|
||||
|
||||
/// The codec used by CastFlutterApi.
|
||||
NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec(void);
|
||||
|
|
@ -32,6 +32,7 @@ NSObject<FlutterMessageCodec> *CastFlutterApiGetCodec(void);
|
|||
- (instancetype)initWithBinaryMessenger:(id<FlutterBinaryMessenger>)binaryMessenger;
|
||||
- (void)getSessionMessageNamespacesWithCompletion:(void(^)(NSArray<NSString *> *, 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<FlutterMessageCodec> *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
|
||||
|
|
@ -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 <Flutter/Flutter.h>
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
|
|
@ -45,9 +45,9 @@ static NSDictionary<NSString *, id> *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<NSString *, id> *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<NSString *, id> *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<FlutterMessageCodec> *CastApiGetCodec() {
|
||||
NSObject<FlutterMessageCodec> *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<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi> *api) {
|
||||
void CastHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger, NSObject<CastHostApi> *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<FlutterBinaryMessenger> binaryMessenger, NSObject<CastApi>
|
|||
{
|
||||
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<FlutterMessageCodec> *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<FlutterMessageCodec> *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
|
||||
|
|
@ -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<Object?> codec = _CastApiCodec();
|
||||
static const MessageCodec<Object?> codec = _CastHostApiCodec();
|
||||
|
||||
Future<void> sendMessage(CastMessage arg_message) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.CastApi.sendMessage', codec, binaryMessenger: _binaryMessenger);
|
||||
'dev.flutter.pigeon.CastHostApi.sendMessage', codec, binaryMessenger: _binaryMessenger);
|
||||
final Map<Object?, Object?>? replyMap =
|
||||
await channel.send(<Object>[arg_message]) as Map<Object?, Object?>?;
|
||||
if (replyMap == null) {
|
||||
|
|
@ -87,7 +87,7 @@ class CastApi {
|
|||
|
||||
Future<void> showCastDialog() async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.CastApi.showCastDialog', codec, binaryMessenger: _binaryMessenger);
|
||||
'dev.flutter.pigeon.CastHostApi.showCastDialog', codec, binaryMessenger: _binaryMessenger);
|
||||
final Map<Object?, Object?>? replyMap =
|
||||
await channel.send(null) as Map<Object?, Object?>?;
|
||||
if (replyMap == null) {
|
||||
|
|
@ -138,6 +138,7 @@ abstract class CastFlutterApi {
|
|||
|
||||
List<String?> 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<Object?> channel = BasicMessageChannel<Object?>(
|
||||
|
|
@ -178,6 +178,22 @@ abstract class CastFlutterApi {
|
|||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'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<Object?> args = (message as List<Object?>?)!;
|
||||
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<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.CastFlutterApi.onSessionStarting', codec);
|
||||
|
|
@ -295,21 +311,5 @@ abstract class CastFlutterApi {
|
|||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
const BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'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<Object?> args = (message as List<Object?>?)!;
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ class CastMessage {
|
|||
}
|
||||
|
||||
@HostApi()
|
||||
abstract class CastApi {
|
||||
abstract class CastHostApi {
|
||||
void sendMessage(CastMessage message);
|
||||
void showCastDialog();
|
||||
}
|
||||
Loading…
Reference in a new issue