| 139 | } |
| 140 | |
| 141 | export class Functions implements IFunctions { |
| 142 | _native: com.google.firebase.functions.FirebaseFunctions; |
| 143 | _app: FirebaseApp; |
| 144 | |
| 145 | constructor(app?: FirebaseApp) { |
| 146 | if (app?.native) { |
| 147 | this._native = defaultRegionOrCustomDomain ? com.google.firebase.functions.FirebaseFunctions.getInstance(app.native, defaultRegionOrCustomDomain) : com.google.firebase.functions.FirebaseFunctions.getInstance(app.native); |
| 148 | } else { |
| 149 | if (defaultFunctions) { |
| 150 | return defaultFunctions; |
| 151 | } |
| 152 | defaultFunctions = this; |
| 153 | // If defaultRegionOrCustomDomain is set, get FirebaseFunctions instance using that parameter |
| 154 | // @see https://firebase.google.com/docs/functions/locations_client-side_location_selection_for_callable_functions |
| 155 | this._native = defaultRegionOrCustomDomain ? com.google.firebase.functions.FirebaseFunctions.getInstance(defaultRegionOrCustomDomain) : com.google.firebase.functions.FirebaseFunctions.getInstance(); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | httpsCallable(name: string, options?: HttpsCallableOptions): HttpsCallable { |
| 160 | const callable = this.native.getHttpsCallable(name); |
| 161 | if (typeof options?.timeout === 'number') { |
| 162 | callable.setTimeout(options.timeout, java.util.concurrent.TimeUnit.SECONDS); |
| 163 | } |
| 164 | return (data: any) => { |
| 165 | return new Promise((resolve, reject) => { |
| 166 | org.nativescript.firebase.functions.FirebaseFunctions.call( |
| 167 | callable, |
| 168 | data ? serialize(data, true) : null, |
| 169 | new org.nativescript.firebase.functions.FirebaseFunctions.Callback<com.google.firebase.functions.HttpsCallableResult>({ |
| 170 | onSuccess(result: com.google.firebase.functions.HttpsCallableResult): void { |
| 171 | resolve(deserialize(result?.getData?.())); |
| 172 | }, |
| 173 | onError(error): void { |
| 174 | reject(toHttpsError(error)); |
| 175 | }, |
| 176 | }) |
| 177 | ); |
| 178 | }); |
| 179 | }; |
| 180 | } |
| 181 | |
| 182 | useEmulator(host: string, port: number) { |
| 183 | this.native.useEmulator(host === 'localhost' || host === '127.0.0.1' ? '10.0.2.2' : host, port); |
| 184 | } |
| 185 | |
| 186 | get native() { |
| 187 | return this._native; |
| 188 | } |
| 189 | |
| 190 | get ios() { |
| 191 | return this.native; |
| 192 | } |
| 193 | |
| 194 | useFunctionsEmulatorOrigin(origin: string) { |
| 195 | this.native.useFunctionsEmulator(origin); |
| 196 | } |
| 197 | |
| 198 | get app(): FirebaseApp { |
nothing calls this directly
no outgoing calls
no test coverage detected