-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
https_callable_web.dart
61 lines (48 loc) 路 1.93 KB
/
https_callable_web.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// ignore_for_file: require_trailing_commas
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:js_util' as util;
import 'package:cloud_functions_platform_interface/cloud_functions_platform_interface.dart';
import 'interop/functions.dart' as functions_interop;
import 'utils.dart';
/// A web specific implementation of [HttpsCallable].
class HttpsCallableWeb extends HttpsCallablePlatform {
/// Constructor.
HttpsCallableWeb(FirebaseFunctionsPlatform functions, this._webFunctions,
String? origin, String? name, HttpsCallableOptions options, Uri? uri)
: super(functions, origin, name, options, uri);
final functions_interop.Functions _webFunctions;
@override
Future<dynamic> call([dynamic parameters]) async {
if (origin != null) {
final uri = Uri.parse(origin!);
_webFunctions.useFunctionsEmulator(uri.host, uri.port);
}
functions_interop.HttpsCallableOptions callableOptions =
functions_interop.HttpsCallableOptions(
timeout: options.timeout.inMilliseconds,
limitedUseAppCheckTokens: options.limitedUseAppCheckToken,
);
late functions_interop.HttpsCallable callable;
if (name != null) {
callable = _webFunctions.httpsCallable(name!, callableOptions);
} else if (uri != null) {
callable = _webFunctions.httpsCallableUri(uri!, callableOptions);
} else {
throw ArgumentError('Either name or uri must be provided');
}
functions_interop.HttpsCallableResult response;
var input = parameters;
if ((input is Map) || (input is Iterable)) {
input = util.jsify(parameters);
}
try {
response = await callable.call(input);
} catch (e, s) {
throw convertFirebaseFunctionsException(e, s);
}
return response.data;
}
}