-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(messaging): AngularFireMessaing #1749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
14fcef6
ec6937f
32ed341
ddc769a
a249900
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './messaging.spec'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './public_api'; |
| 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 { } |
| 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); | ||
|
|
||
| this.getToken = from(this.messaging.getToken()); | ||
|
||
|
|
||
| this.tokenChanges = new Observable(subscriber => { | ||
|
||
| 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( | ||
|
||
| mergeMap(() => this.tokenChanges) | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| deleteToken(token: string) { | ||
|
||
| return from(this.messaging.deleteToken(token)!); | ||
| } | ||
|
|
||
| } | ||
| 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()!); | ||
| } |
| 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" | ||
| } |
| 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'; |
| 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" | ||
| }; |
| 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 | ||
| } | ||
| } | ||
|
|
| 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" | ||
| } | ||
| } |
| 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" | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not inline?