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 new file mode 100644 index 0000000..82998c4 --- /dev/null +++ b/android/src/main/java/com/gianlucaparadise/flutter_cast_framework/HostApis.java @@ -0,0 +1,117 @@ +// Autogenerated from Pigeon (v1.0.8), do not edit directly. +// See also: https://pub.dev/packages/pigeon + +package com.gianlucaparadise.flutter_cast_framework; + +import io.flutter.plugin.common.BasicMessageChannel; +import io.flutter.plugin.common.BinaryMessenger; +import io.flutter.plugin.common.MessageCodec; +import io.flutter.plugin.common.StandardMessageCodec; +import java.io.ByteArrayOutputStream; +import java.nio.ByteBuffer; +import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.HashMap; + +/** Generated class from Pigeon. */ +@SuppressWarnings({"unused", "unchecked", "CodeBlock2Expr", "RedundantSuppression"}) +public class HostApis { + + /** Generated class from Pigeon that represents data sent in messages. */ + public static class CastMessage { + private String namespace; + public String getNamespace() { return namespace; } + public void setNamespace(String setterArg) { this.namespace = setterArg; } + + private String message; + public String getMessage() { return message; } + public void setMessage(String setterArg) { this.message = setterArg; } + + Map toMap() { + Map toMapResult = new HashMap<>(); + toMapResult.put("namespace", namespace); + toMapResult.put("message", message); + return toMapResult; + } + static CastMessage fromMap(Map map) { + CastMessage fromMapResult = new CastMessage(); + Object namespace = map.get("namespace"); + fromMapResult.namespace = (String)namespace; + Object message = map.get("message"); + fromMapResult.message = (String)message; + return fromMapResult; + } + } + private static class CastApiCodec extends StandardMessageCodec { + public static final CastApiCodec INSTANCE = new CastApiCodec(); + private CastApiCodec() {} + @Override + protected Object readValueOfType(byte type, ByteBuffer buffer) { + switch (type) { + case (byte)128: + return CastMessage.fromMap((Map) readValue(buffer)); + + default: + return super.readValueOfType(type, buffer); + + } + } + @Override + protected void writeValue(ByteArrayOutputStream stream, Object value) { + if (value instanceof CastMessage) { + stream.write(128); + writeValue(stream, ((CastMessage) value).toMap()); + } else +{ + super.writeValue(stream, value); + } + } + } + + /** Generated interface from Pigeon that represents a handler of messages from Flutter.*/ + public interface CastApi { + void sendMessage(CastMessage message); + + /** The codec used by CastApi. */ + static MessageCodec getCodec() { + return CastApiCodec.INSTANCE; + } + + /** Sets up an instance of `CastApi` to handle messages through the `binaryMessenger`. */ + static void setup(BinaryMessenger binaryMessenger, CastApi api) { + { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.CastApi.sendMessage", getCodec()); + if (api != null) { + channel.setMessageHandler((message, reply) -> { + Map wrapped = new HashMap<>(); + try { + ArrayList args = (ArrayList)message; + CastMessage messageArg = (CastMessage)args.get(0); + if (messageArg == null) { + throw new NullPointerException("messageArg unexpectedly null."); + } + api.sendMessage(messageArg); + 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) { + Map errorMap = new HashMap<>(); + errorMap.put("message", exception.toString()); + errorMap.put("code", exception.getClass().getSimpleName()); + errorMap.put("details", null); + return errorMap; + } +} diff --git a/ios/Classes/HostApis.h b/ios/Classes/HostApis.h new file mode 100644 index 0000000..79f3c21 --- /dev/null +++ b/ios/Classes/HostApis.h @@ -0,0 +1,27 @@ +// Autogenerated from Pigeon (v1.0.8), do not edit directly. +// See also: https://pub.dev/packages/pigeon +#import +@protocol FlutterBinaryMessenger; +@protocol FlutterMessageCodec; +@class FlutterError; +@class FlutterStandardTypedData; + +NS_ASSUME_NONNULL_BEGIN + +@class CastMessage; + +@interface CastMessage : NSObject +@property(nonatomic, copy, nullable) NSString * namespace; +@property(nonatomic, copy, nullable) NSString * message; +@end + +/// The codec used by CastApi. +NSObject *CastApiGetCodec(void); + +@protocol CastApi +- (void)sendMessageMessage:(CastMessage *)message error:(FlutterError *_Nullable *_Nonnull)error; +@end + +extern void CastApiSetup(id binaryMessenger, NSObject *_Nullable api); + +NS_ASSUME_NONNULL_END diff --git a/ios/Classes/HostApis.m b/ios/Classes/HostApis.m new file mode 100644 index 0000000..bd7fca8 --- /dev/null +++ b/ios/Classes/HostApis.m @@ -0,0 +1,122 @@ +// Autogenerated from Pigeon (v1.0.8), do not edit directly. +// See also: https://pub.dev/packages/pigeon +#import "HostApis.h" +#import + +#if !__has_feature(objc_arc) +#error File requires ARC to be enabled. +#endif + +static NSDictionary *wrapResult(id result, FlutterError *error) { + NSDictionary *errorDict = (NSDictionary *)[NSNull null]; + if (error) { + errorDict = @{ + @"code": (error.code ? error.code : [NSNull null]), + @"message": (error.message ? error.message : [NSNull null]), + @"details": (error.details ? error.details : [NSNull null]), + }; + } + return @{ + @"result": (result ? result : [NSNull null]), + @"error": errorDict, + }; +} + +@interface CastMessage () ++ (CastMessage *)fromMap:(NSDictionary *)dict; +- (NSDictionary *)toMap; +@end + +@implementation CastMessage ++ (CastMessage *)fromMap:(NSDictionary *)dict { + CastMessage *result = [[CastMessage alloc] init]; + result.namespace = dict[@"namespace"]; + if ((NSNull *)result.namespace == [NSNull null]) { + result.namespace = nil; + } + result.message = dict[@"message"]; + if ((NSNull *)result.message == [NSNull null]) { + result.message = nil; + } + return result; +} +- (NSDictionary *)toMap { + return [NSDictionary dictionaryWithObjectsAndKeys:(self.namespace ? self.namespace : [NSNull null]), @"namespace", (self.message ? self.message : [NSNull null]), @"message", nil]; +} +@end + +@interface CastApiCodecReader : FlutterStandardReader +@end +@implementation CastApiCodecReader +- (nullable id)readValueOfType:(UInt8)type +{ + switch (type) { + case 128: + return [CastMessage fromMap:[self readValue]]; + + default: + return [super readValueOfType:type]; + + } +} +@end + +@interface CastApiCodecWriter : FlutterStandardWriter +@end +@implementation CastApiCodecWriter +- (void)writeValue:(id)value +{ + if ([value isKindOfClass:[CastMessage class]]) { + [self writeByte:128]; + [self writeValue:[value toMap]]; + } else +{ + [super writeValue:value]; + } +} +@end + +@interface CastApiCodecReaderWriter : FlutterStandardReaderWriter +@end +@implementation CastApiCodecReaderWriter +- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data { + return [[CastApiCodecWriter alloc] initWithData:data]; +} +- (FlutterStandardReader *)readerWithData:(NSData *)data { + return [[CastApiCodecReader alloc] initWithData:data]; +} +@end + +NSObject *CastApiGetCodec() { + static dispatch_once_t s_pred = 0; + static FlutterStandardMessageCodec *s_sharedObject = nil; + dispatch_once(&s_pred, ^{ + CastApiCodecReaderWriter *readerWriter = [[CastApiCodecReaderWriter alloc] init]; + s_sharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter]; + }); + return s_sharedObject; +} + + +void CastApiSetup(id binaryMessenger, NSObject *api) { + { + FlutterBasicMessageChannel *channel = + [FlutterBasicMessageChannel + messageChannelWithName:@"dev.flutter.pigeon.CastApi.sendMessage" + binaryMessenger:binaryMessenger + codec:CastApiGetCodec()]; + if (api) { + NSCAssert([api respondsToSelector:@selector(sendMessageMessage:error:)], @"CastApi api (%@) doesn't respond to @selector(sendMessageMessage:error:)", api); + [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) { + NSArray *args = message; + CastMessage *arg_message = args[0]; + FlutterError *error; + [api sendMessageMessage:arg_message error:&error]; + callback(wrapResult(nil, error)); + }]; + } + else { + [channel setMessageHandler:nil]; + } + } +} diff --git a/lib/src/HostApis.dart b/lib/src/HostApis.dart new file mode 100644 index 0000000..f03dbd4 --- /dev/null +++ b/lib/src/HostApis.dart @@ -0,0 +1,87 @@ +// Autogenerated from Pigeon (v1.0.8), do not edit directly. +// See also: https://pub.dev/packages/pigeon +// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name +// @dart = 2.12 +import 'dart:async'; +import 'dart:typed_data' show Uint8List, Int32List, Int64List, Float64List; + +import 'package:flutter/foundation.dart' show WriteBuffer, ReadBuffer; +import 'package:flutter/services.dart'; + +class CastMessage { + String? namespace; + String? message; + + Object encode() { + final Map pigeonMap = {}; + pigeonMap['namespace'] = namespace; + pigeonMap['message'] = message; + return pigeonMap; + } + + static CastMessage decode(Object message) { + final Map pigeonMap = message as Map; + return CastMessage() + ..namespace = pigeonMap['namespace'] as String? + ..message = pigeonMap['message'] as String?; + } +} + +class _CastApiCodec extends StandardMessageCodec { + const _CastApiCodec(); + @override + void writeValue(WriteBuffer buffer, Object? value) { + if (value is CastMessage) { + buffer.putUint8(128); + writeValue(buffer, value.encode()); + } else +{ + super.writeValue(buffer, value); + } + } + @override + Object? readValueOfType(int type, ReadBuffer buffer) { + switch (type) { + case 128: + return CastMessage.decode(readValue(buffer)!); + + default: + return super.readValueOfType(type, buffer); + + } + } +} + +class CastApi { + /// Constructor for [CastApi]. 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; + + final BinaryMessenger? _binaryMessenger; + + static const MessageCodec codec = _CastApiCodec(); + + Future sendMessage(CastMessage arg_message) async { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.CastApi.sendMessage', codec, binaryMessenger: _binaryMessenger); + final Map? replyMap = + await channel.send([arg_message]) 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 new file mode 100644 index 0000000..4249c84 --- /dev/null +++ b/lib/src/HostApisDefinition.dart @@ -0,0 +1,11 @@ +import 'package:pigeon/pigeon.dart'; + +class CastMessage { + String? namespace; + String? message; +} + +@HostApi() +abstract class CastApi { + void sendMessage(CastMessage message); +} \ No newline at end of file