Skip to content

[cloud_functions] Update cloud_functions to use platform interface #1854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ Audrius Karosevicius <[email protected]>
Lukasz Piliszczuk <[email protected]>
SoundReply Solutions GmbH <[email protected]>
Michel Feinstein <[email protected]>
Tobias Löfstrand <[email protected]>
Tobias Löfstrand <[email protected]>
Stephen Beitzel <[email protected]>
6 changes: 6 additions & 0 deletions packages/cloud_functions/cloud_functions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.4.1+7

* Update to use the platform interface to execute calls.
* Fix timeout for Android (which had been ignoring explicit timeouts due to unit mismatch).
* Update repository location based on platform interface refactoring.

## 0.4.1+6

* Fix analysis failures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public void onMethodCall(MethodCall call, final Result result) {
functions.useFunctionsEmulator(origin);
}
HttpsCallableReference httpsCallableReference = functions.getHttpsCallable(functionName);
Number timeoutMilliseconds = call.argument("timeoutMilliseconds");
if (timeoutMilliseconds != null) {
httpsCallableReference.setTimeout(timeoutMilliseconds.longValue(), TimeUnit.MILLISECONDS);
Number timeoutMicroseconds = call.argument("timeoutMicroseconds");
if (timeoutMicroseconds != null) {
httpsCallableReference.setTimeout(timeoutMicroseconds.longValue(), TimeUnit.MICROSECONDS);
}
httpsCallableReference
.call(parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
library cloud_functions;

import 'dart:async';

import 'package:cloud_functions_platform_interface/cloud_functions_platform_interface.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class CloudFunctions {
: _app = app ?? FirebaseApp.instance,
_region = region;

@visibleForTesting
static const MethodChannel channel = MethodChannel('cloud_functions');

static CloudFunctions _instance = CloudFunctions();

static CloudFunctions get instance => _instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ class HttpsCallable {
/// automatically includes a Firebase Instance ID token to identify the app
/// instance. If a user is logged in with Firebase Auth, an auth ID token for
/// the user is also automatically included.
Future<HttpsCallableResult> call([dynamic parameters]) async {
Future<HttpsCallableResult> call([dynamic parameters]) {
try {
final MethodChannel channel = CloudFunctions.channel;
final dynamic response = await channel
.invokeMethod<dynamic>('CloudFunctions#call', <String, dynamic>{
'app': _cloudFunctions._app.name,
'region': _cloudFunctions._region,
'origin': _cloudFunctions._origin,
'timeoutMicroseconds': timeout?.inMicroseconds,
'functionName': _functionName,
'parameters': parameters,
});
return HttpsCallableResult._(response);
return CloudFunctionsPlatform.instance
.callCloudFunction(
appName: _cloudFunctions._app.name,
region: _cloudFunctions._region,
origin: _cloudFunctions._origin,
timeout: timeout,
functionName: _functionName,
parameters: parameters,
)
.then((response) => HttpsCallableResult._(response));
} on PlatformException catch (e) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this catch remain, if an error does not fall into it?

if (e.code == 'functionsError') {
final String code = e.details['code'];
Expand Down
5 changes: 3 additions & 2 deletions packages/cloud_functions/cloud_functions/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: cloud_functions
description: Flutter plugin for Cloud Functions.
version: 0.4.1+6
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/cloud_functions
version: 0.4.1+7
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/cloud_functions/cloud_functions

flutter:
plugin:
Expand All @@ -17,6 +17,7 @@ dependencies:
flutter:
sdk: flutter
firebase_core: ^0.4.0
cloud_functions_platform_interface: ^1.0.0

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:cloud_functions/cloud_functions.dart';
import 'package:cloud_functions_platform_interface/cloud_functions_platform_interface.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -14,7 +15,7 @@ void main() {
final List<MethodCall> log = <MethodCall>[];

setUp(() async {
CloudFunctions.channel
MethodChannelCloudFunctions.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
log.add(methodCall);
switch (methodCall.method) {
Expand Down