-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(cloud_functions): add support for cloud functions stream #17214
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
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
5bbf13d
chore: add platform interface and method channel implementation for C…
SelaseKay 24acdda
chore: add `httpsCallableStreamFromUrl` and `httpsStreamCallableWithUri`
SelaseKay fa00dd9
chore: resolve comments
SelaseKay fa750ed
chore: add Android implementation for Cloud Functions stream
SelaseKay 3e8ac29
chore: resolve formatting issues
SelaseKay c248cd6
chore: correct variable name
SelaseKay 1ac4533
chore: add support for Cloud Functions Stream(Android)
SelaseKay d8e0fce
Merge branch 'main' into feat/cloud_functions_stream_support
SelaseKay 95236c8
chore: create dedicated StreamHandler class
SelaseKay 785e019
Merge branch 'main' into feat/cloud_functions_stream_support
SelaseKay 6161988
chore: add streamhandler implementation for ios
SelaseKay debdc46
Merge branch 'main' into feat/cloud_functions_stream_support
SelaseKay 4d0c10e
chore: add iOS implementation for Cloud Functions stream
SelaseKay 1190fde
chore: add license header to stream handler files
SelaseKay 6bbde2f
chore: web Cloud Functions stream wip
SelaseKay 66be89b
chore: push all
SelaseKay 4804ab9
chore: update functions based on API Doc modification
SelaseKay 4f83c36
chore: clean up code
SelaseKay 213e283
chore: add web package
SelaseKay de10bcc
Merge branch 'main' into feat/cloud_functions_stream_support
SelaseKay 794d441
chore: add streaming example
SelaseKay 560e3eb
Merge branch 'feat/cloud_functions_stream_support' of github.com:fire…
SelaseKay 6ad0820
chore: fix ci issues
SelaseKay a9819db
chore: fix ci
SelaseKay 295c6c6
chore: fix cloud function test
SelaseKay 7a5ad4e
chore: add missing doc
SelaseKay 45fea6f
chore: fixes and clean up
SelaseKay 047354a
chore: add e2e for Cloud Functions Stream
SelaseKay 045150d
chore: fix formatting issue
SelaseKay 69ef58f
chore: add more tests and fix timeout for Android
SelaseKay 693aa89
chore: add test for map and list
SelaseKay aa77160
chore: fix test
SelaseKay 06c1c9c
chore: update year to 2025 in files
SelaseKay 1404359
chore(web): add support for abort signal
SelaseKay 43c223c
chore: resolve comments and add test for Abort
SelaseKay df743ee
chore: fix test
SelaseKay c5136d6
chore: fix test
SelaseKay 3964f3b
chore: update copyright year
SelaseKay f3af9e8
chore: print error to console
SelaseKay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2,923 changes: 971 additions & 1,952 deletions
2,923
.github/workflows/scripts/functions/package-lock.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...d/src/main/java/io/flutter/plugins/firebase/functions/FirebaseFunctionsStreamHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2025 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.firebase.functions; | ||
|
||
import android.net.Uri; | ||
import com.google.firebase.functions.FirebaseFunctions; | ||
import com.google.firebase.functions.HttpsCallableOptions; | ||
import com.google.firebase.functions.HttpsCallableReference; | ||
import com.google.firebase.functions.StreamResponse; | ||
import io.flutter.plugin.common.EventChannel; | ||
import io.flutter.plugin.common.EventChannel.StreamHandler; | ||
import java.net.URL; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
import org.reactivestreams.Publisher; | ||
|
||
public class FirebaseFunctionsStreamHandler implements StreamHandler { | ||
|
||
private final FirebaseFunctions firebaseFunctions; | ||
|
||
private StreamResponseSubscriber subscriber; | ||
|
||
public FirebaseFunctionsStreamHandler(FirebaseFunctions functions) { | ||
this.firebaseFunctions = functions; | ||
} | ||
|
||
@Override | ||
public void onListen(Object arguments, EventChannel.EventSink events) { | ||
@SuppressWarnings("unchecked") | ||
Map<String, Object> argumentsMap = (Map<String, Object>) arguments; | ||
httpsStreamCall(argumentsMap, events); | ||
} | ||
|
||
@Override | ||
public void onCancel(Object arguments) { | ||
subscriber.cancel(); | ||
} | ||
|
||
private void httpsStreamCall(Map<String, Object> arguments, EventChannel.EventSink events) { | ||
try { | ||
|
||
String functionName = (String) arguments.get("functionName"); | ||
String functionUri = (String) arguments.get("functionUri"); | ||
String origin = (String) arguments.get("origin"); | ||
Integer timeout = (Integer) arguments.get("timeout"); | ||
Object parameters = arguments.get("parameters"); | ||
boolean limitedUseAppCheckToken = | ||
(boolean) Objects.requireNonNull(arguments.get("limitedUseAppCheckToken")); | ||
|
||
if (origin != null) { | ||
Uri originUri = Uri.parse(origin); | ||
firebaseFunctions.useEmulator(originUri.getHost(), originUri.getPort()); | ||
} | ||
|
||
HttpsCallableReference httpsCallableReference; | ||
HttpsCallableOptions options = | ||
new HttpsCallableOptions.Builder() | ||
.setLimitedUseAppCheckTokens(limitedUseAppCheckToken) | ||
.build(); | ||
|
||
Publisher<StreamResponse> publisher; | ||
if (functionName != null) { | ||
httpsCallableReference = firebaseFunctions.getHttpsCallable(functionName, options); | ||
publisher = httpsCallableReference.stream(parameters); | ||
} else if (functionUri != null) { | ||
httpsCallableReference = | ||
firebaseFunctions.getHttpsCallableFromUrl(new URL(functionUri), options); | ||
publisher = httpsCallableReference.stream(); | ||
} else { | ||
throw new IllegalArgumentException("Either functionName or functionUri must be set"); | ||
} | ||
|
||
if (timeout != null) { | ||
httpsCallableReference.setTimeout(timeout.longValue(), TimeUnit.MILLISECONDS); | ||
} | ||
subscriber = new StreamResponseSubscriber(events); | ||
publisher.subscribe(subscriber); | ||
} catch (Exception e) { | ||
events.error("firebase_functions", e.getMessage(), null); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we would need an external library to handle this? We managed to do all the other implementations without it AFAIK/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The other ones provided a way to add listeners directly (eg. addOnConfigUpdatedListener) whereas this one doesn't. It returns a
Publisher
so this is the only way around it AFAIK.Reference: https://firebase.google.com/docs/reference/kotlin/com/google/firebase/functions/HttpsCallableReference#summary