Skip to content
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

FCM rxjs compatibility broken? #3142

Closed
zwu52 opened this issue May 30, 2020 · 4 comments · Fixed by #3221
Closed

FCM rxjs compatibility broken? #3142

zwu52 opened this issue May 30, 2020 · 4 comments · Fixed by #3221
Assignees

Comments

@zwu52
Copy link
Member

zwu52 commented May 30, 2020

FCM API suggests that it offers rxjs compatibility out of box. Specifically, you could do

let foregroundMessages$ = rxjs.Observable.create(function subscribe(observer) {
  messaging.onMessage(observer);
});

foregroundMessages$.subscribe({
  next: (msg) => handleForegroundMessage(msg),
  error: (err) => console.log("err: " + err),
});

However, an error is thrown:

Uncaught (in promise) TypeError: this._next is not a function
    at rt.Subscriber.next [as onMessageCallback] (rxjs.umd.js:472)
    at rt.<anonymous> (window-controller.ts:197)
    at tslib.es6.js:100
    at Object.next (tslib.es6.js:81)
    at tslib.es6.js:74
    at new Promise (<anonymous>)
    at v (tslib.es6.js:70)
    at rt.messageEventListener (window-controller.ts:188)
    at ServiceWorkerContainer.<anonymous> (window-controller.ts:47)

Came across this error here as well (angular/angularfire#2299)

@zwu52 zwu52 self-assigned this May 30, 2020
@zwu52
Copy link
Member Author

zwu52 commented May 30, 2020

ref: FCM API

@Feiyang1
Copy link
Member

Feiyang1 commented Jun 1, 2020

Reading angular/angularfire#2299 (comment), seems it was working before 7.6.0. Any idea what changed?

@zwu52
Copy link
Member Author

zwu52 commented Jun 15, 2020

Finally got a chance to route back to this. I think I found the cause for this: currently window controller stores a member variable onMessageCallback which gets fed with value from nextOrObserver. Internally, if this nextOrObserver is not a callback function, we do this.onMessageCallback = nextOrObserver.next assuming the next callback is passed directly from the observer object developer provided in

{
  next: (msg) => handleForegroundMessage(msg),
  error: (err) => console.log("err: " + err),
}

However, rxjs actually does some internal operation and converts the observer into a subscriber instance, such instance should be used as a unit as it is (e.x. subscriber.next()). Trying to extract the next callback from it will result in

this.onMessageCallback = function: ƒ (value) {
           if (!this.isStopped) {
               this._next(value);
           }
       }

since next is stripped away from the generated subscriber, this._next nor this.isStopped is undefined.
I have a PR that would resolve this issue.

@hiepxanh
Copy link

perfect, I'm coming from angular/angularfire#2497 (comment) and I'm wating for your fix to update my PR

@firebase firebase locked and limited conversation to collaborators Aug 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants