Skip to content

Commit ce12956

Browse files
authored
feat(afs/fcm): Allow feature use in non-server environments such as workers (#2015)
* Allow offline in all non-server environments e.g, workers * Allow messaging in all non-server environments e.g, workers
1 parent a6de2e7 commit ce12956

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/firestore/firestore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { AngularFirestoreDocument } from './document/document';
77
import { AngularFirestoreCollection } from './collection/collection';
88

99
import { FirebaseFirestore, FirebaseOptions, FirebaseAppConfig, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from '@angular/fire';
10-
import { isPlatformBrowser } from '@angular/common';
10+
import { isPlatformServer } from '@angular/common';
1111

1212
import { firestore, SDK_VERSION } from 'firebase/app';
1313

@@ -123,7 +123,7 @@ export class AngularFirestore {
123123
return firestore;
124124
});
125125

126-
if (shouldEnablePersistence && isPlatformBrowser(platformId)) {
126+
if (shouldEnablePersistence && !isPlatformServer(platformId)) {
127127
// We need to try/catch here because not all enablePersistence() failures are caught
128128
// https://github.com/firebase/firebase-js-sdk/issues/608
129129
const enablePersistence = () => {

src/messaging/messaging.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core';
2-
import { isPlatformBrowser } from '@angular/common';
2+
import { isPlatformServer } from '@angular/common';
33
import { messaging } from 'firebase/app';
44
import { Observable, empty, from, of, throwError } from 'rxjs';
55
import { mergeMap, catchError, map, switchMap, concat, defaultIfEmpty } from 'rxjs/operators';
@@ -23,7 +23,7 @@ export class AngularFireMessaging {
2323
zone: NgZone
2424
) {
2525

26-
if (isPlatformBrowser(platformId)) {
26+
if (!isPlatformServer(platformId)) {
2727

2828
// @ts-ignore
2929
const requireMessaging = from(import('firebase/messaging'));

0 commit comments

Comments
 (0)