Comments (5)
Hey, sorry it's taken me a while to get to this.
Reading through it, it looks great. I'm going to spin up a new app with the cloud client and test it out this weekend.
I've been testing my push-plugin wrapper service in different app states, and have gotten some inconsistent behavior when the app is dead. My criteria has been that when the phone receives a notification, it is able to send an http request.
I'll test yours in the same conditions and let you know what I find!
from ionic-cloud-angular.
Here is our use case for push notification observables.
We have a couple different cases for what to do when a notification is received:
New message for the user - go to the message details page and load the message
New update available (via Deploy) - update and then close the app
Silent notification - do some background stuff, download new stuff, etc
I'd like to have multiple subscribers to the stream so that the business logic for a feature can be contained in its component(s). For example all the logic to determine if an update should be downloaded and extracted should be contained in the DeployService, all the logic to navigate to and show a new message should be in the MessagePage class.
I'd like to avoid having a bunch of business logic and dependencies where the Push.init happens like:
push.on('notification', data => {
if (data.additionalData.messageId) {
nav.push(MessagePage, {id: data.additionalData.messageId});
} else if (data.additionalData.deploy === true) {
DeployService.update();
} else if (newFeature) (
// bunch of logic
} else {
// do some background stuff
}
});
Right now I've written a class (PushService) that inits the push plugin and returns observables that I consume like this:
import {NavController} from 'ionic-angular';
import {Component} from '@angular/core';
import {AzureService} from '../../shared';
import {MessagePage} from '../../dashboard';
import {PushService} from './';
import {Observable} from 'rxjs/Observable';
@Component({
templateUrl: 'build/shared/native/native.html',
providers: [PushService]
})
export class NativePage {
constructor(
private nav: NavController,
private azureService: AzureService,
private pushService: PushService
) {
this.pushService.notification()
.subscribe(
data => {
console.debug('subscribed data: ', data);
azureService.api('pushRecieved').post(data);
if (data && data.additionalData && data.additionalData.messagesId)
nav.push(MessagePage, {id: data.additionalData.messagesId});
}
);
}
// Push
register(): void {
this.pushService.register();
}
}
Right now my PushService is doing the observable wrapping, but I think that wrapping should happen at a lower level. Maybe Ionic Native should included the observable wrapper?
tl;dr Observables would be cool, but I think it should be done at the plugin level for push notifications.
Let me know what you think!
from ionic-cloud-angular.
@justinschuldt Can I have you update and test observable support for push notifications? (FYI there are breaking changes.) I only did it for push notifications because I'd like you to validate my approach.
import { Push } from '@ionic/cloud-angular';
this.push.rx.notification()
.subscribe((msg) => {
console.log('OBSERVABLE got notification!', msg);
});
I was able to use filter()
on a deploy flag to simulate one of your use cases.
Check it out: https://github.com/driftyco/ionic-cloud-angular/blob/master/src/index.ts#L21-L38
You may notice there's no support for dispose yet. I'm waiting on an issue whose URL I left in the comment.
Likes/dislikes?
from ionic-cloud-angular.
What other observables might be suited in the Cloud Client? I know it would be nice to subscribe to a deploy channel, but the deploy plugin doesn't let us push out changes (we'd have to poll).
from ionic-cloud-angular.
As far as observables for other parts of the cloud client, I'm not sure an observable deploy service would be very valuable to most people. I cant think of a realistic situation where I would want to watch for updates that vigilantly.
it could be cool to see analytics in real time, but that wouldn't be needed in the client.
from ionic-cloud-angular.
Related Issues (20)
- Using with Ionic-Super-Starter HOT 6
- platform.toLowerCase is not a function HOT 5
- Deploy.load fails silently HOT 1
- Version 0.10.0 - Object prototype may only be an Object or null: undefined HOT 5
- access_token for linkedIn in undefined all the time
- rollup failed: Unexpected token HOT 2
- Build failure in iOS using ionic Packge HOT 42
- Doesnt work with Angular 4.0.0-rc.2 aot build HOT 10
- Able to use WKWebView 3.0? HOT 1
- Clearing notifications opens up Ionic app HOT 1
- I think ionic 2 is a nightmare, don't use it HOT 4
- Push imports complete RxJS library HOT 1
- CocoaPods was not found - [phonegap-plugin-push] HOT 1
- How to use this in browser ?
- not compatible with ionic3
- Ionic Deploy Error
- unable to install plugin in new ionic 3 project HOT 3
- cant build PROD HOT 2
- iOS app is crashing due to NSInvalidArgumentException in deploy plugin HOT 1
- OpaqueToken deprecated in Angular 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ionic-cloud-angular.