2017-10-06 23:24:00 +00:00
|
|
|
// @flow
|
|
|
|
import { NativeModules } from 'react-native';
|
2017-11-17 16:17:27 +00:00
|
|
|
import INTERNALS from '../../utils/internals';
|
|
|
|
import { isIOS } from '../../utils';
|
2017-11-23 17:29:40 +00:00
|
|
|
import ModuleBase from '../../utils/ModuleBase';
|
2018-02-14 13:00:19 +00:00
|
|
|
import type App from '../core/app';
|
2017-10-06 23:24:00 +00:00
|
|
|
|
|
|
|
const FirebaseCoreModule = NativeModules.RNFirebase;
|
|
|
|
|
2017-11-23 17:29:40 +00:00
|
|
|
type GoogleApiAvailabilityType = {
|
|
|
|
status: number,
|
|
|
|
isAvailable: boolean,
|
|
|
|
isUserResolvableError?: boolean,
|
|
|
|
hasResolution?: boolean,
|
2018-01-25 18:25:39 +00:00
|
|
|
error?: string,
|
|
|
|
};
|
2017-11-23 17:29:40 +00:00
|
|
|
|
2018-01-03 20:00:38 +00:00
|
|
|
export const MODULE_NAME = 'RNFirebaseUtils';
|
|
|
|
export const NAMESPACE = 'utils';
|
2017-10-06 23:24:00 +00:00
|
|
|
|
2018-01-03 20:00:38 +00:00
|
|
|
export default class RNFirebaseUtils extends ModuleBase {
|
2018-01-08 09:20:32 +00:00
|
|
|
constructor(app: App) {
|
|
|
|
super(app, {
|
|
|
|
moduleName: MODULE_NAME,
|
2018-01-09 17:31:00 +00:00
|
|
|
multiApp: false,
|
2017-11-21 23:37:05 +00:00
|
|
|
hasShards: false,
|
2018-01-08 09:20:32 +00:00
|
|
|
namespace: NAMESPACE,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-10-06 23:24:00 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
checkPlayServicesAvailability() {
|
2018-01-05 17:20:02 +00:00
|
|
|
if (isIOS) return;
|
2017-10-07 02:09:05 +00:00
|
|
|
|
2018-01-05 17:20:02 +00:00
|
|
|
const { status } = this.playServicesAvailability;
|
2017-10-07 02:09:05 +00:00
|
|
|
|
2017-10-06 23:24:00 +00:00
|
|
|
if (!this.playServicesAvailability.isAvailable) {
|
2018-01-25 18:25:39 +00:00
|
|
|
if (
|
|
|
|
INTERNALS.OPTIONS.promptOnMissingPlayServices &&
|
|
|
|
this.playServicesAvailability.isUserResolvableError
|
|
|
|
) {
|
2017-10-06 23:24:00 +00:00
|
|
|
this.promptForPlayServices();
|
|
|
|
} else {
|
2018-01-05 17:20:02 +00:00
|
|
|
const error = INTERNALS.STRINGS.ERROR_PLAY_SERVICES(status);
|
2017-10-06 23:24:00 +00:00
|
|
|
if (INTERNALS.OPTIONS.errorOnMissingPlayServices) {
|
2018-01-25 18:25:39 +00:00
|
|
|
if (status === 2)
|
|
|
|
console.warn(error); // only warn if it exists but may need an update
|
2017-10-07 02:09:05 +00:00
|
|
|
else throw new Error(error);
|
2017-10-06 23:24:00 +00:00
|
|
|
} else {
|
|
|
|
console.warn(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
promptForPlayServices() {
|
|
|
|
if (isIOS) return null;
|
|
|
|
return FirebaseCoreModule.promptForPlayServices();
|
|
|
|
}
|
|
|
|
|
|
|
|
resolutionForPlayServices() {
|
|
|
|
if (isIOS) return null;
|
|
|
|
return FirebaseCoreModule.resolutionForPlayServices();
|
|
|
|
}
|
|
|
|
|
|
|
|
makePlayServicesAvailable() {
|
|
|
|
if (isIOS) return null;
|
|
|
|
return FirebaseCoreModule.makePlayServicesAvailable();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the global logging level for all logs.
|
|
|
|
*
|
2018-01-05 17:20:02 +00:00
|
|
|
* @param logLevel
|
2017-10-06 23:24:00 +00:00
|
|
|
*/
|
2018-01-05 17:20:02 +00:00
|
|
|
set logLevel(logLevel: string) {
|
|
|
|
INTERNALS.OPTIONS.logLevel = logLevel;
|
2017-10-06 23:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns props from the android GoogleApiAvailability sdk
|
|
|
|
* @android
|
|
|
|
* @return {RNFirebase.GoogleApiAvailabilityType|{isAvailable: boolean, status: number}}
|
|
|
|
*/
|
|
|
|
get playServicesAvailability(): GoogleApiAvailabilityType {
|
2018-01-25 18:25:39 +00:00
|
|
|
return (
|
|
|
|
FirebaseCoreModule.playServicesAvailability || {
|
|
|
|
isAvailable: true,
|
|
|
|
status: 0,
|
|
|
|
}
|
|
|
|
);
|
2017-10-06 23:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-07 02:53:20 +00:00
|
|
|
* Enable/Disable throwing an error or warning on detecting a play services problem
|
2017-10-06 23:24:00 +00:00
|
|
|
* @android
|
|
|
|
* @param bool
|
|
|
|
*/
|
2017-11-23 17:29:40 +00:00
|
|
|
set errorOnMissingPlayServices(bool: boolean) {
|
2017-10-06 23:24:00 +00:00
|
|
|
INTERNALS.OPTIONS.errorOnMissingPlayServices = bool;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable/Disable automatic prompting of the play services update dialog
|
|
|
|
* @android
|
|
|
|
* @param bool
|
|
|
|
*/
|
2017-11-23 17:29:40 +00:00
|
|
|
set promptOnMissingPlayServices(bool: boolean) {
|
2017-10-06 23:24:00 +00:00
|
|
|
INTERNALS.OPTIONS.promptOnMissingPlayServices = bool;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-09 17:31:54 +00:00
|
|
|
export const statics = {};
|