Skip to content

Commit 8443f4e

Browse files
authored
Merge eec98b2 into b9be9f1
2 parents b9be9f1 + eec98b2 commit 8443f4e

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

firebase-functions/api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ package com.google.firebase.functions {
8686
method public void setTimeout(long timeout, java.util.concurrent.TimeUnit units);
8787
method public org.reactivestreams.Publisher<com.google.firebase.functions.StreamResponse> stream();
8888
method public org.reactivestreams.Publisher<com.google.firebase.functions.StreamResponse> stream(Object? data = null);
89+
method public kotlinx.coroutines.flow.Flow<com.google.firebase.functions.StreamResponse> streamAsFlow();
90+
method public kotlinx.coroutines.flow.Flow<com.google.firebase.functions.StreamResponse> streamAsFlow(Object? data = null);
8991
method public com.google.firebase.functions.HttpsCallableReference withTimeout(long timeout, java.util.concurrent.TimeUnit units);
9092
property public final long timeout;
9193
}

firebase-functions/firebase-functions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ dependencies {
113113
implementation(libs.playservices.base)
114114
implementation(libs.playservices.basement)
115115
implementation(libs.reactive.streams)
116+
implementation(libs.kotlinx.coroutines.reactive)
116117

117118
api(libs.playservices.tasks)
118119

@@ -133,7 +134,6 @@ dependencies {
133134
androidTestImplementation(libs.truth)
134135
androidTestImplementation(libs.androidx.test.runner)
135136
androidTestImplementation(libs.androidx.test.junit)
136-
androidTestImplementation(libs.kotlinx.coroutines.reactive)
137137
androidTestImplementation(libs.mockito.core)
138138
androidTestImplementation(libs.mockito.dexmaker)
139139
kapt("com.google.dagger:dagger-android-processor:2.43.2")

firebase-functions/src/androidTest/java/com/google/firebase/functions/StreamTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import com.google.firebase.Firebase
2323
import com.google.firebase.initialize
2424
import java.util.concurrent.TimeUnit
2525
import kotlinx.coroutines.delay
26-
import kotlinx.coroutines.reactive.asFlow
2726
import kotlinx.coroutines.runBlocking
2827
import kotlinx.coroutines.withTimeout
2928
import org.junit.Before
@@ -100,7 +99,7 @@ class StreamTests {
10099
val messages = mutableListOf<StreamResponse.Message>()
101100
var result: StreamResponse.Result? = null
102101

103-
val flow = function.stream(input).asFlow()
102+
val flow = function.streamAsFlow(input)
104103
try {
105104
withTimeout(1000) {
106105
flow.collect { response ->

firebase-functions/src/main/java/com/google/firebase/functions/HttpsCallableReference.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import androidx.annotation.VisibleForTesting
1717
import com.google.android.gms.tasks.Task
1818
import java.net.URL
1919
import java.util.concurrent.TimeUnit
20+
import kotlinx.coroutines.flow.Flow
21+
import kotlinx.coroutines.reactive.asFlow
2022
import org.reactivestreams.Publisher
2123

2224
/** A reference to a particular Callable HTTPS trigger in Cloud Functions. */
@@ -173,6 +175,49 @@ public class HttpsCallableReference {
173175
}
174176
}
175177

178+
/**
179+
* Streams data to the specified HTTPS endpoint.
180+
*
181+
* The data passed into the trigger can be any of the following types:
182+
*
183+
* * Any primitive type, including null, int, long, float, and boolean.
184+
* * [String]
185+
* * [List<?>][java.util.List], where the contained objects are also one of these types.
186+
* * [Map<String, ?>][java.util.Map], where the values are also one of these types.
187+
* * [org.json.JSONArray]
188+
* * [org.json.JSONObject]
189+
* * [org.json.JSONObject.NULL]
190+
*
191+
* If the returned streamResponse fails, the exception will be one of the following types:
192+
*
193+
* * [java.io.IOException]
194+
* - if the HTTPS request failed to connect.
195+
* * [FirebaseFunctionsException]
196+
* - if the request connected, but the function returned an error.
197+
*
198+
* The request to the Cloud Functions backend made by this method automatically includes a
199+
* Firebase Instance ID token to identify the app instance. If a user is logged in with Firebase
200+
* Auth, an auth token for the user will also be automatically included.
201+
*
202+
* Firebase Instance ID sends data to the Firebase backend periodically to collect information
203+
* regarding the app instance. To stop this, see
204+
* [com.google.firebase.iid.FirebaseInstanceId.deleteInstanceId]. It will resume with a new
205+
* Instance ID the next time you call this method.
206+
*
207+
* @param data Parameters to pass to the endpoint. Defaults to `null` if not provided.
208+
* @return [Flow] that will emit intermediate data, and the final result, as it is generated by
209+
* the function.
210+
* @see org.json.JSONArray
211+
*
212+
* @see org.json.JSONObject
213+
*
214+
* @see java.io.IOException
215+
*
216+
* @see FirebaseFunctionsException
217+
*/
218+
@JvmOverloads
219+
public fun streamAsFlow(data: Any? = null): Flow<StreamResponse> = stream(data).asFlow()
220+
176221
/**
177222
* Changes the timeout for calls from this instance of Functions. The default is 60 seconds.
178223
*

0 commit comments

Comments
 (0)