Skip to content

Commit 3ac899e

Browse files
Merge pull request #665 from martijnpoppen/bugfix/google-gcm
FIX: GCM error
2 parents ecca72e + 321f147 commit 3ac899e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/push/service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export class PushNotificationService extends TypedEmitter<PushNotificationServic
189189

190190
private async createPushCredentials(): Promise<Credentials> {
191191
const generatedFid = generateFid();
192+
192193
return await this.registerFid(generatedFid)
193194
.then(async (registerFidResponse) => {
194195
const checkinResponse = await this.executeCheckin();
@@ -229,6 +230,7 @@ export class PushNotificationService extends TypedEmitter<PushNotificationServic
229230
}
230231

231232
private async loginPushCredentials(credentials: Credentials): Promise<Credentials> {
233+
rootPushLogger.info('fidresponse', credentials.fidResponse)
232234
return await this.executeCheckin()
233235
.then(async (response) => {
234236
const registerGcmResponse = await this.registerGcm(credentials.fidResponse, response);
@@ -704,8 +706,8 @@ export class PushNotificationService extends TypedEmitter<PushNotificationServic
704706
return this.persistentIds;
705707
}
706708

707-
private async _open(renew = false): Promise<void> {
708-
if (!this.credentials || Object.keys(this.credentials).length === 0 || (this.credentials && this.credentials.fidResponse && new Date().getTime() >= this.credentials.fidResponse.authToken.expiresAt)) {
709+
private async _open(renew = false, forceNew = false): Promise<void> {
710+
if (forceNew || !this.credentials || Object.keys(this.credentials).length === 0 || (this.credentials && this.credentials.fidResponse && new Date().getTime() >= this.credentials.fidResponse.authToken.expiresAt)) {
709711
rootPushLogger.debug(`Create new push credentials...`, { credentials: this.credentials, renew: renew });
710712
this.credentials = await this.createPushCredentials().catch(err => {
711713
const error = ensureError(err);
@@ -775,7 +777,7 @@ export class PushNotificationService extends TypedEmitter<PushNotificationServic
775777
public async open(): Promise<Credentials | undefined> {
776778
if (!this.connecting && !this.connected) {
777779
this.connecting = true;
778-
await this._open().catch((err) => {
780+
await this._open(false, true).catch((err) => {
779781
const error = ensureError(err);
780782
rootPushLogger.error(`Got exception trying to initialize push notifications`, { error: getError(error), credentials: this.credentials });
781783
});

src/push/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { load } from "protobufjs";
44

55
import { CheckinResponse } from "./models";
66
import { FidGenerationError } from "./error";
7+
import { rootPushLogger } from "../logging";
78

89
export const VALID_FID_PATTERN = /^[cdef][\w-]{21}$/;
910

@@ -17,7 +18,10 @@ export function generateFid(): string {
1718
const b64 = Buffer.from(fidByteArray).toString("base64");
1819
const b64_safe = b64.replace(/\+/g, "-").replace(/\//g, "_");
1920
const fid = b64_safe.substr(0, 22);
21+
22+
2023
if (VALID_FID_PATTERN.test(fid)) {
24+
rootPushLogger.info('generateFid', fid)
2125
return fid;
2226
}
2327
throw new FidGenerationError("Generated invalid FID", { context: { fid: fid } });

0 commit comments

Comments
 (0)