Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
onMessage(listener) {
if (!isFunction(listener)) {
throw new Error("firebase.messaging().onMessage(*) 'listener' expected a function.");
}
// TODO(salakar) rework internals as without this native module will never be ready (therefore never subscribes)
this.native;
const subscription = this.emitter.addListener('messaging_message_received', listener);
return () => subscription.remove();
}
function wrapSnapshotEventListener(task, listenerFn, unsubscribe) {
if (!isFunction(listenerFn)) {
return null;
}
return event => {
if (unsubscribe) {
setTimeout(() => unsubscribe(), 0);
} // 1 frame = 16ms, pushing to next frame
if (isFunction(listenerFn)) {
const snapshot = Object.assign({}, event);
snapshot.task = task;
snapshot.ref = task._ref;
if (snapshot.metadata) {
if (!snapshot.metadata.generation) {
snapshot.metadata.generation = '';
}
if (!snapshot.metadata.bucket) {
set(value, onComplete) {
if (isUndefined(value)) {
throw new Error("firebase.database().ref().set(*) 'value' must be defined.");
}
if (!isUndefined(onComplete) && !isFunction(onComplete)) {
throw new Error(
"firebase.database().ref().set(_, *) 'onComplete' must be a function if provided.",
);
}
return promiseWithOptionalCallback(this._database.native.set(this.path, { value }), onComplete);
}
let _complete;
let _completeSubscription;
const unsubscribe = () => {
if (_nextSubscription) {
_nextSubscription.remove();
}
if (_errorSubscription) {
_errorSubscription.remove();
}
if (_completeSubscription) {
_completeSubscription.remove();
}
};
if (isFunction(nextOrObserver)) {
_error = wrapErrorEventListener(error, unsubscribe);
_next = wrapSnapshotEventListener(task, nextOrObserver);
_complete = wrapSnapshotEventListener(task, complete, unsubscribe);
} else if (isObject(nextOrObserver)) {
_error = wrapErrorEventListener(nextOrObserver.error, unsubscribe);
_next = wrapSnapshotEventListener(task, nextOrObserver.next);
_complete = wrapSnapshotEventListener(task, nextOrObserver.complete, unsubscribe);
} else if (isNull(nextOrObserver)) {
_error = wrapErrorEventListener(error, unsubscribe);
_complete = wrapSnapshotEventListener(task, complete, unsubscribe);
} else {
throw new Error(
"firebase.storage.StorageTask.on(*, _) 'nextOrObserver' must be a Function, an Object or Null.",
);
}
);
}
if (!isFunction(observer)) {
throw new Error(
"firebase.auth.PhoneAuthListener.on(_, *, _, _) 'observer' must be a function.",
);
}
this._addUserObserver(observer);
if (isFunction(errorCb)) {
this._auth.emitter.once(this._publicEvents.error, errorCb);
}
if (isFunction(successCb)) {
this._auth.emitter.once(this._publicEvents.success, successCb);
}
return this;
}
on(eventType, callback, cancelCallbackOrContext, context) {
if (!eventTypes.includes(eventType)) {
throw new Error(
`firebase.database().ref().on(*) 'eventType' must be one of ${eventTypes.join(', ')}.`,
);
}
if (!isFunction(callback)) {
throw new Error("firebase.database().ref().on(_, *) 'callback' must be a function.");
}
if (
!isUndefined(cancelCallbackOrContext) &&
(!isFunction(cancelCallbackOrContext) && !isObject(cancelCallbackOrContext))
) {
throw new Error(
"firebase.database().ref().on(_, _, *) 'cancelCallbackOrContext' must be a function or object.",
);
}
if (!isUndefined(context) && !isObject(context)) {
throw new Error("firebase.database().ref().on(_, _, _, *) 'context' must be an object.");
}
once(eventType, successCallBack, failureCallbackOrContext, context) {
if (!eventTypes.includes(eventType)) {
throw new Error(
`firebase.database().ref().once(*) 'eventType' must be one of ${eventTypes.join(', ')}.`,
);
}
if (!isUndefined(successCallBack) && !isFunction(successCallBack)) {
throw new Error("firebase.database().ref().once(_, *) 'successCallBack' must be a function.");
}
if (
!isUndefined(failureCallbackOrContext) &&
(!isObject(failureCallbackOrContext) && !isFunction(failureCallbackOrContext))
) {
throw new Error(
"firebase.database().ref().once(_, _, *) 'failureCallbackOrContext' must be a function or context.",
);
}
if (!isUndefined(context) && !isObject(context)) {
throw new Error(
"firebase.database().ref().once(_, _, _, *) 'context' must be a context object.",
);
}
const modifiers = this._modifiers.toArray();
return this._database.native
.once(this.path, modifiers, eventType)
onAdEvent(handler) {
if (!isFunction(handler)) {
throw new Error("firebase.admob() RewardedAd.onAdEvent(*) 'handler' expected a function.");
}
return this._setAdEventHandler(handler);
}
onOpenURL(listener) {
if (!isFunction(listener)) {
throw new Error("firebase.indexing().onOpenURL(*) 'listener' must be a function.");
}
Linking.addEventListener('url', ({ url }) => listener(url));
return () => Linking.removeEventListener('url', listener);
}
}
onAdEvent(handler) {
if (!isFunction(handler)) {
throw new Error(
"firebase.admob() InterstitialAd.onAdEvent(*) 'handler' expected a function.",
);
}
return this._setAdEventHandler(handler);
}