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

Fix FCM rxjs Incompatibility #3221

Merged
merged 44 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dde3bfd
Enable the FCM integration test (IT) for Chrome.
Apr 14, 2020
099c76a
[AUTOMATED]: License Headers
Apr 14, 2020
14d38bc
Enable integration test (IT) for FCM.
zwu52 May 13, 2020
910e6a1
Correct int syntax
zwu52 May 13, 2020
b46f232
This file wasn't auto-saved
zwu52 May 13, 2020
1e68ca5
Trigger FCM IT
zwu52 May 15, 2020
b8ed1ba
Test Secrets can be accessed w/o dotenv
zwu52 May 15, 2020
37fb7c9
Add fcm sercret to workflow
zwu52 May 18, 2020
8d3e700
Update test-changed.yml
zwu52 May 18, 2020
cac7b80
test send (background only)
zwu52 May 18, 2020
5909104
remove dotenv
zwu52 May 18, 2020
2df79b5
feed secrest into test:all workflow
zwu52 May 19, 2020
fccb108
Update test-all.yml
zwu52 May 19, 2020
3ea2c73
background messaging checking
zwu52 May 21, 2020
81a84f0
[AUTOMATED]: License Headers
zwu52 May 21, 2020
9038d1a
rerun
zwu52 May 21, 2020
a1345e7
added waiting
zwu52 May 26, 2020
1bcab1c
wait
zwu52 May 26, 2020
75b5ba6
Update test-send.js
zwu52 May 26, 2020
36d2272
Update test-send.js
zwu52 May 26, 2020
8e7c27d
Examine wrong sercret
zwu52 May 27, 2020
976d3cd
Update sendMessage.js
zwu52 May 30, 2020
343af85
Update sendMessage.js
zwu52 Jun 1, 2020
0750f00
Update sendMessage.js
zwu52 Jun 1, 2020
068b173
Update sendMessage.js
zwu52 Jun 1, 2020
e3fcea3
Update sendMessage.js
zwu52 Jun 1, 2020
fdb4ca2
Merge branch 'master' into test
zwu52 Jun 2, 2020
b60d010
update fcm project
zwu52 Jun 2, 2020
3acc255
Update package.json
zwu52 Jun 2, 2020
4f12ef8
Update test-send.js
zwu52 Jun 3, 2020
1d2368c
open new tab for backgournd receive
zwu52 Jun 8, 2020
6ab745f
removed test-send
zwu52 Jun 9, 2020
4c5e360
Adding Reties
zwu52 Jun 10, 2020
2f9b9bc
Change timeout limit
zwu52 Jun 10, 2020
4775b91
retry 3 times
zwu52 Jun 10, 2020
1e54408
adjust mocha setting
zwu52 Jun 11, 2020
5753fa5
update
zwu52 Jun 11, 2020
dc4cca8
Enable foreground tesing
zwu52 Jun 15, 2020
fc3a3fb
Merge branch 'master' into test
zwu52 Jun 15, 2020
9b57708
Fix FCM rxjs incompatibility
zwu52 Jun 16, 2020
af71124
Use one listener to handle next and observer for onMessage
zwu52 Jun 24, 2020
71561e4
Merge branch 'master' of https://github.com/firebase/firebase-js-sdk …
zwu52 Jun 26, 2020
2feb4a7
Add changeset to the PR
zwu52 Jun 26, 2020
4aca0f2
Update tough-rings-bake.md
zwu52 Jun 26, 2020
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
6 changes: 6 additions & 0 deletions .changeset/tough-rings-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'firebase': patch
'@firebase/messaging': patch
---

Added support for `onMessage` so the internal callback can work with [Subscriber](https://rxjs.dev/api/index/class/Subscriber)
42 changes: 22 additions & 20 deletions packages/messaging/src/controllers/window-controller.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
import '../testing/setup';

import * as tokenManagementModule from '../core/token-management';

import {
CONSOLE_CAMPAIGN_ANALYTICS_ENABLED,
CONSOLE_CAMPAIGN_ID,
CONSOLE_CAMPAIGN_NAME,
CONSOLE_CAMPAIGN_TIME,
DEFAULT_SW_PATH,
DEFAULT_SW_SCOPE,
DEFAULT_VAPID_KEY
} from '../util/constants';
import { InternalMessage, MessageType } from '../interfaces/internal-message';
import { SinonFakeTimers, SinonSpy, spy, stub, useFakeTimers } from 'sinon';
import { Spy, Stub } from '../testing/sinon-types';

import { ErrorCode } from '../util/errors';
import { FakeServiceWorkerRegistration } from '../testing/fakes/service-worker';
import { FirebaseAnalyticsInternal } from '@firebase/analytics-interop-types';
import { FirebaseInternalDependencies } from '../interfaces/internal-dependencies';
import { WindowController } from './window-controller';
/**
* @license
* Copyright 2017 Google LLC
Expand All @@ -15,27 +37,7 @@
* limitations under the License.
*/
import { expect } from 'chai';
import { stub, spy, SinonSpy, useFakeTimers, SinonFakeTimers } from 'sinon';

import { FirebaseAnalyticsInternal } from '@firebase/analytics-interop-types';
import { WindowController } from './window-controller';
import { getFakeFirebaseDependencies } from '../testing/fakes/firebase-dependencies';
import { ErrorCode } from '../util/errors';
import { FirebaseInternalDependencies } from '../interfaces/internal-dependencies';
import * as tokenManagementModule from '../core/token-management';
import {
DEFAULT_VAPID_KEY,
DEFAULT_SW_SCOPE,
DEFAULT_SW_PATH,
CONSOLE_CAMPAIGN_ANALYTICS_ENABLED,
CONSOLE_CAMPAIGN_ID,
CONSOLE_CAMPAIGN_NAME,
CONSOLE_CAMPAIGN_TIME
} from '../util/constants';
import { Stub, Spy } from '../testing/sinon-types';
import '../testing/setup';
import { FakeServiceWorkerRegistration } from '../testing/fakes/service-worker';
import { MessageType, InternalMessage } from '../interfaces/internal-message';

type MessageEventListener = (event: Event) => Promise<void>;

Expand Down
34 changes: 18 additions & 16 deletions packages/messaging/src/controllers/window-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,31 @@
* limitations under the License.
*/

import { getToken, deleteToken } from '../core/token-management';
import { FirebaseInternalDependencies } from '../interfaces/internal-dependencies';
import { FirebaseMessaging } from '@firebase/messaging-types';
import { ERROR_FACTORY, ErrorCode } from '../util/errors';
import { NextFn, Observer, Unsubscribe } from '@firebase/util';
import { InternalMessage, MessageType } from '../interfaces/internal-message';
import {
CONSOLE_CAMPAIGN_ID,
CONSOLE_CAMPAIGN_ANALYTICS_ENABLED,
CONSOLE_CAMPAIGN_ID,
CONSOLE_CAMPAIGN_NAME,
CONSOLE_CAMPAIGN_TIME,
DEFAULT_SW_PATH,
DEFAULT_SW_SCOPE,
DEFAULT_VAPID_KEY
} from '../util/constants';
import { FirebaseApp } from '@firebase/app-types';
import { ERROR_FACTORY, ErrorCode } from '../util/errors';
import { InternalMessage, MessageType } from '../interfaces/internal-message';
import { NextFn, Observer, Unsubscribe } from '@firebase/util';
import { deleteToken, getToken } from '../core/token-management';

import { ConsoleMessageData } from '../interfaces/message-payload';
import { isConsoleMessage } from '../helpers/is-console-message';
import { FirebaseApp } from '@firebase/app-types';
import { FirebaseInternalDependencies } from '../interfaces/internal-dependencies';
import { FirebaseMessaging } from '@firebase/messaging-types';
import { FirebaseService } from '@firebase/app-types/private';
import { isConsoleMessage } from '../helpers/is-console-message';

export class WindowController implements FirebaseMessaging, FirebaseService {
private vapidKey: string | null = null;
private swRegistration?: ServiceWorkerRegistration;
private onMessageCallback: NextFn<object> | null = null;
private onMessageCallback: NextFn<object> | Observer<object> | null = null;

constructor(
private readonly firebaseDependencies: FirebaseInternalDependencies
Expand Down Expand Up @@ -131,12 +132,8 @@ export class WindowController implements FirebaseMessaging, FirebaseService {
* message.
* @return The unsubscribe function for the observer.
*/
// TODO: Simplify this to only accept a function and not an Observer.
onMessage(nextOrObserver: NextFn<object> | Observer<object>): Unsubscribe {
this.onMessageCallback =
typeof nextOrObserver === 'function'
? nextOrObserver
: nextOrObserver.next;
this.onMessageCallback = nextOrObserver;

return () => {
this.onMessageCallback = null;
Expand Down Expand Up @@ -193,8 +190,13 @@ export class WindowController implements FirebaseMessaging, FirebaseService {

const { type, payload } = (event.data as InternalMessage).firebaseMessaging;

// onMessageCallback is either a function or observer/subscriber.
if (this.onMessageCallback && type === MessageType.PUSH_RECEIVED) {
this.onMessageCallback(payload);
if (typeof this.onMessageCallback === 'function') {
this.onMessageCallback(payload);
} else {
this.onMessageCallback.next(payload);
}
}

const { data } = payload;
Expand Down