Giter Site home page Giter Site logo

Comments (5)

justinschuldt avatar justinschuldt commented on May 18, 2024 1

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.

justinschuldt avatar justinschuldt commented on May 18, 2024

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.

imhoffd avatar imhoffd commented on May 18, 2024

@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.

imhoffd avatar imhoffd commented on May 18, 2024

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.

justinschuldt avatar justinschuldt commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.