Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/messaging/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './messaging.spec';
1 change: 1 addition & 0 deletions src/messaging/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './public_api';
24 changes: 24 additions & 0 deletions src/messaging/messaging.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NgModule } from '@angular/core';
import { AngularFireModule, FirebaseApp } from 'angularfire2';
import { AngularFireMessaging } from './messaging';
import 'firebase/messaging';

export function _getAngularFireMessaging(app: FirebaseApp) {
return new AngularFireMessaging(app);
}

export const AngularFireMessagingProvider = {
provide: AngularFireMessaging,
useFactory: _getAngularFireMessaging,
deps: [ FirebaseApp ]
};

export const STORAGE_PROVIDERS = [
AngularFireMessagingProvider,
];

@NgModule({
imports: [ AngularFireModule ],
providers: [ STORAGE_PROVIDERS ]
})
export class AngularFireMessagingModule { }
44 changes: 44 additions & 0 deletions src/messaging/messaging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { FirebaseApp } from 'angularfire2';
import { messaging } from 'firebase';
import { requestPermission } from './observable/request-permission';
import { from } from 'rxjs';
import { mergeMap } from 'rxjs/operators';

@Injectable()
export class AngularFireMessaging {
messaging: messaging.Messaging;
requestPermission: Observable<void>;
getToken: Observable<string|null>;
tokenChanges: Observable<string|null>;
messages: Observable<{}>;
requestToken: Observable<string|null>;

constructor(public app: FirebaseApp) {
this.messaging = app.messaging();

this.requestPermission = requestPermission(this.messaging);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not inline?


this.getToken = from(this.messaging.getToken());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this a single IMO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, that's a Promise hance a single... nevermind.


this.tokenChanges = new Observable(subscriber => {
Copy link
Member

@jamesdaniels jamesdaniels Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now that I'm playing with this I'm not sure I like this API. I think I'd prefer:

this.tokenChanges => from(this.messaging.onTokenRefresh);

this.token => this.getToken.pipe(concat(this.tokenChanges))

Thoughts?

this.messaging.getToken().then(t => subscriber.next(t));
this.messaging.onTokenRefresh(subscriber);
});

this.messages = new Observable(subscriber => {
this.messaging.onMessage(subscriber);
});

this.requestToken = this.requestPermission.pipe(
Copy link
Member

@jamesdaniels jamesdaniels Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should catch the requestPermission exception and complete with null

mergeMap(() => this.tokenChanges)
);

}

deleteToken(token: string) {
Copy link
Member

@jamesdaniels jamesdaniels Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... not sure about this API either, how about

this.deleteToken = this.getToken.pipe(
  mergeMap(t => t ? this.messaging.deleteToken(t) : empty() )
)

return from(this.messaging.deleteToken(token)!);
}

}
6 changes: 6 additions & 0 deletions src/messaging/observable/request-permission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Observable, from } from 'rxjs';
import { messaging } from 'firebase';

export function requestPermission(messaging: messaging.Messaging): Observable<void> {
return from(messaging.requestPermission()!);
}
31 changes: 31 additions & 0 deletions src/messaging/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "angularfire2/messaging",
"version": "ANGULARFIRE2_VERSION",
"description": "The messaging module",
"main": "../bundles/messaging.umd.js",
"module": "index.js",
"es2015": "./es2015/index.js",
"keywords": [
"angular",
"firebase",
"rxjs"
],
"repository": {
"type": "git",
"url": "git+https://github.com/angular/angularfire2.git"
},
"author": "angular,firebase",
"license": "MIT",
"peerDependencies": {
"angularfire2": "ANGULARFIRE2_VERSION",
"@angular/common": "ANGULAR_VERSION",
"@angular/core": "ANGULAR_VERSION",
"@angular/platform-browser": "ANGULAR_VERSION",
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
"@firebase/app": "FIREBASE_APP_VERSION",
"@firebase/messaging": "FIREBASE_MESSAGING_VERSION",
"rxjs": "RXJS_VERSION",
"zone.js": "ZONEJS_VERSION"
},
"typings": "index.d.ts"
}
3 changes: 3 additions & 0 deletions src/messaging/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './observable/request-permission';
export * from './messaging';
export * from './messaging.module';
8 changes: 8 additions & 0 deletions src/messaging/test-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export const COMMON_CONFIG = {
apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA",
authDomain: "angularfire2-test.firebaseapp.com",
databaseURL: "https://angularfire2-test.firebaseio.com",
storageBucket: "angularfire2-test.appspot.com",
messagingSenderId: "920323787688"
};
33 changes: 33 additions & 0 deletions src/messaging/tsconfig-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"baseUrl": ".",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"module": "es2015",
"target": "es2015",
"noImplicitAny": false,
"outDir": "../../dist/packages-dist/messaging/es2015",
"rootDir": ".",
"sourceMap": true,
"inlineSources": true,
"declaration": false,
"removeComments": true,
"strictNullChecks": true,
"lib": ["es2015", "dom", "es2015.promise", "es2015.collection", "es2015.iterable"],
"skipLibCheck": true,
"moduleResolution": "node",
"paths": {
"angularfire2": ["../../dist/packages-dist"]
}
},
"files": [
"index.ts",
"../../node_modules/zone.js/dist/zone.js.d.ts"
],
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableSummariesForJit": false
}
}

19 changes: 19 additions & 0 deletions src/messaging/tsconfig-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./tsconfig-build.json",
"compilerOptions": {
"target": "es5",
"outDir": "../../dist/packages-dist/messaging",
"declaration": true
},
"files": [
"public_api.ts",
"../../node_modules/zone.js/dist/zone.js.d.ts"
],
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableSummariesForJit": false,
"flatModuleOutFile": "index.js",
"flatModuleId": "angularfire2/messaging"
}
}
13 changes: 13 additions & 0 deletions src/messaging/tsconfig-test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig-esm.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"angularfire2": ["../../dist/packages-dist"]
}
},
"files": [
"index.spec.ts",
"../../node_modules/zone.js/dist/zone.js.d.ts"
]
}
1 change: 1 addition & 0 deletions src/root.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from './packages-dist/database/list/snapshot-changes.spec';
export * from './packages-dist/database/list/state-changes.spec';
export * from './packages-dist/database/list/audit-trail.spec';
export * from './packages-dist/storage/storage.spec';
export * from './packages-dist/messaging/messaging.spec';

// // Since this a deprecated API, we run on it on manual tests only
// // It needs a network connection to run which makes it flaky on Travis
Expand Down
1 change: 1 addition & 0 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"angularfire2/firestore": ["./firestore"],
"angularfire2/functions": ["./functions"],
"angularfire2/storage": ["./storage"],
"angularfire2/messaging": ["./messaging"],
"angularfire2/database-deprecated": ["./database-deprecated"]
},
"rootDir": ".",
Expand Down
22 changes: 16 additions & 6 deletions tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const GLOBALS = {
'angularfire2/database-deprecated': 'angularfire2.database_deprecated',
'angularfire2/firestore': 'angularfire2.firestore',
'angularfire2/functions': 'angularfire2.functions',
'angularfire2/storage': 'angularfire2.storage'
'angularfire2/storage': 'angularfire2.storage',
'angularfire2/messaging': 'angularfire2.messaging',
};

// Map of dependency versions across all packages
Expand All @@ -53,7 +54,8 @@ const MODULE_NAMES = {
"database-deprecated": 'angularfire2.database_deprecated',
firestore: 'angularfire2.firestore',
functions: 'angularfire2.functions',
storage: 'angularfire2.storage'
storage: 'angularfire2.storage',
messaging: 'angularfire2.messaging',
};

const ENTRIES = {
Expand All @@ -63,7 +65,8 @@ const ENTRIES = {
"database-deprecated": `${process.cwd()}/dist/packages-dist/database-deprecated/index.js`,
firestore: `${process.cwd()}/dist/packages-dist/firestore/index.js`,
functions: `${process.cwd()}/dist/packages-dist/functions/index.js`,
storage: `${process.cwd()}/dist/packages-dist/storage/index.js`
storage: `${process.cwd()}/dist/packages-dist/storage/index.js`,
messaging: `${process.cwd()}/dist/packages-dist/messaging/index.js`,
};

const SRC_PKG_PATHS = {
Expand All @@ -74,7 +77,8 @@ const SRC_PKG_PATHS = {
firestore: `${process.cwd()}/src/firestore/package.json`,
"firebase-node": `${process.cwd()}/src/firebase-node/package.json`,
functions: `${process.cwd()}/src/functions/package.json`,
storage: `${process.cwd()}/src/storage/package.json`
storage: `${process.cwd()}/src/storage/package.json`,
messaging: `${process.cwd()}/src/messaging/package.json`,
};

const DEST_PKG_PATHS = {
Expand All @@ -85,7 +89,8 @@ const DEST_PKG_PATHS = {
firestore: `${process.cwd()}/dist/packages-dist/firestore/package.json`,
"firebase-node": `${process.cwd()}/dist/packages-dist/firebase-node/package.json`,
functions: `${process.cwd()}/dist/packages-dist/functions/package.json`,
storage: `${process.cwd()}/dist/packages-dist/storage/package.json`
storage: `${process.cwd()}/dist/packages-dist/storage/package.json`,
messaging: `${process.cwd()}/dist/packages-dist/messaging/package.json`,
};

// Constants for running typescript commands
Expand Down Expand Up @@ -246,6 +251,7 @@ function getVersions() {
getDestPackageFile('firebase-node'),
getDestPackageFile('functions'),
getDestPackageFile('storage'),
getDestPackageFile('messaging'),
getDestPackageFile('database-deprecated')
];
return paths
Expand Down Expand Up @@ -285,14 +291,16 @@ function buildModules(globals) {
const firestore$ = buildModule('firestore', globals);
const functions$ = buildModule('functions', globals);
const storage$ = buildModule('storage', globals);
const messaging$ = buildModule('messaging', globals);
const dbdep$ = buildModule('database-deprecated', globals);
return forkJoin(core$, from(copyRootTest())).pipe(
switchMapTo(auth$),
switchMapTo(db$),
switchMapTo(firestore$),
switchMapTo(functions$),
switchMapTo(storage$),
switchMapTo(dbdep$)
switchMapTo(messaging$),
switchMapTo(dbdep$),
);
}

Expand All @@ -312,6 +320,7 @@ function buildLibrary(globals) {
const fsStats = measure('firestore');
const functionsStats = measure('functions');
const storageStats = measure('storage');
const messagingStats = measure('messaging');
const dbdepStats = measure('database-deprecated');
console.log(`
core.umd.js - ${coreStats.size}, ${coreStats.gzip}
Expand All @@ -320,6 +329,7 @@ function buildLibrary(globals) {
firestore.umd.js - ${fsStats.size}, ${fsStats.gzip}
functions.umd.js - ${functionsStats.size}, ${functionsStats.gzip}
storage.umd.js - ${storageStats.size}, ${storageStats.gzip}
messaging.umd.js - ${messagingStats.size}, ${messagingStats.gzip}
database-deprecated.umd.js - ${dbdepStats.size}, ${dbdepStats.gzip}
`);
verifyVersions();
Expand Down