Skip to content

Commit 28e0d95

Browse files
committed
Temporary or permanent solution for fcm listener notify on wrong PushReceiverClient, means fcm alarms, offline death, teamlogin, and news wont notify.
1 parent cf787d0 commit 28e0d95

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/managers/fcmListenerManager.ts

+16-20
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,8 @@ export class FcmListenerManager {
224224
const androidId = credentials.gcm.androidId;
225225
const securityToken = credentials.gcm.securityToken;
226226
this.listeners[steamId] = new PushReceiverClient(androidId, securityToken, []);
227-
// TODO! Something is messed up here. I tested with two steam accounts with credentials on the same discord
228-
// guild. For some reason the two fcm instances wont work together properly. When I pair in-game with account
229-
// 1, the above steamId is the one for account 2, but the data below is correct and from account 1. For the
230-
// love of god I cant figure out how to solve it. When I print each fcm listener (this.listeners) I can see
231-
// that each listener have the correct androidId and securityToken for the given steamId. This needs to be
232-
// solved before v2 release.
233227
this.listeners[steamId].on('ON_DATA_RECEIVED', (data: unknown) => {
234-
const funcName = `[FcmListenerManager: ON_DATA_RECEIVED: ${steamId}]`;
228+
const funcName = `[FcmListenerManager: ON_DATA_RECEIVED]`;
235229
if (!isValidFcmNotificaton(data)) {
236230
log.warn(`${funcName} data is not of type FcmNotification. Data: ${JSON.stringify(data)}`);
237231
return;
@@ -242,7 +236,7 @@ export class FcmListenerManager {
242236
return;
243237
}
244238

245-
this.onDataReceived(steamId, data);
239+
this.onDataReceived(data);
246240
});
247241
this.listeners[steamId].connect();
248242
log.info(`${funcName} FCM Listener started.`);
@@ -259,8 +253,8 @@ export class FcmListenerManager {
259253
}
260254
}
261255

262-
private onDataReceived(steamId: types.SteamId, data: FcmNotification): void {
263-
const funcName = `[FcmListenerManager: onDataReceived: ${steamId}]`;
256+
private onDataReceived(data: FcmNotification): void {
257+
const funcName = `[FcmListenerManager: onDataReceived]`;
264258
const appData: AppDataItem[] = data.appData;
265259

266260
const title = appData.find(item => item.key === 'title')?.value;
@@ -290,9 +284,11 @@ export class FcmListenerManager {
290284

291285
switch (channelId) {
292286
case ChannelIds.PAIRING: {
287+
const steamId = (body as PairingServerBody || body as PairingEntityBody).playerId;
288+
const funcNamePairing = `[FcmListenerManager: onDataReceived: ${steamId}]`;
293289
switch (body.type) {
294290
case PairingTypes.SERVER: {
295-
log.info(`${funcName} ${ChannelIds.PAIRING}: ${PairingTypes.SERVER}`);
291+
log.info(`${funcNamePairing} ${ChannelIds.PAIRING}: ${PairingTypes.SERVER}`);
296292
if (!isValidPairingServerBody(body)) return;
297293

298294
pairingServer(this, steamId, body);
@@ -303,31 +299,31 @@ export class FcmListenerManager {
303299
// entity pairing body
304300
switch (body.entityType) {
305301
case PairingEntityTypes.SMART_SWITCH: {
306-
log.info(`${funcName} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: ` +
302+
log.info(`${funcNamePairing} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: ` +
307303
`${PairingEntityNames.SMART_SWITCH}`);
308304
if (!isValidPairingEntityBody(body)) return;
309305

310306
pairingEntitySmartSwitch(this, steamId, body);
311307
} break;
312308

313309
case PairingEntityTypes.SMART_ALARM: {
314-
log.info(`${funcName} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: ` +
310+
log.info(`${funcNamePairing} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: ` +
315311
`${PairingEntityNames.SMART_ALARM}`);
316312
if (!isValidPairingEntityBody(body)) return;
317313

318314
pairingEntitySmartAlarm(this, steamId, body);
319315
} break;
320316

321317
case PairingEntityTypes.STORAGE_MONITOR: {
322-
log.info(`${funcName} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: ` +
318+
log.info(`${funcNamePairing} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: ` +
323319
`${PairingEntityNames.STORAGE_MONITOR}`);
324320
if (!isValidPairingEntityBody(body)) return;
325321

326322
pairingEntityStorageMonitor(this, steamId, body);
327323
} break;
328324

329325
default: {
330-
log.info(`${funcName} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: other.`);
326+
log.info(`${funcNamePairing} ${ChannelIds.PAIRING}: ${PairingTypes.ENTITY}: other.`);
331327
if (!isValidPairingEntityBody(body)) return;
332328
} break;
333329
}
@@ -346,7 +342,7 @@ export class FcmListenerManager {
346342
log.info(`${funcName} ${ChannelIds.ALARM}: ${AlarmTypes.ALARM}`);
347343
if (!isValidAlarmAlarmBody(body)) return;
348344

349-
alarmAlarm(this, steamId, title, message, body);
345+
//alarmAlarm(this, steamId, title, message, body);
350346
} break;
351347

352348
default: {
@@ -355,7 +351,7 @@ export class FcmListenerManager {
355351
log.info(`${funcName} ${ChannelIds.ALARM}: plugin`);
356352
if (!isValidAlarmPluginBody(body)) return;
357353

358-
alarmPlugin(this, steamId, title, message, body);
354+
//alarmPlugin(this, steamId, title, message, body);
359355
break;
360356
}
361357

@@ -371,7 +367,7 @@ export class FcmListenerManager {
371367
log.info(`${funcName} ${ChannelIds.PLAYER}: ${PlayerTypes.DEATH}`);
372368
if (!isValidPlayerDeathBody(body)) return;
373369

374-
playerDeath(this, steamId, title, body);
370+
//playerDeath(this, steamId, title, body);
375371
} break;
376372

377373
default: {
@@ -387,7 +383,7 @@ export class FcmListenerManager {
387383
log.info(`${funcName} ${ChannelIds.TEAM}: ${TeamTypes.LOGIN}`);
388384
if (!isValidTeamLoginBody(body)) return;
389385

390-
teamLogin(this, steamId, body);
386+
//teamLogin(this, steamId, body);
391387
} break;
392388

393389
default: {
@@ -403,7 +399,7 @@ export class FcmListenerManager {
403399
log.info(`${funcName} ${ChannelIds.NEWS}: ${NewsTypes.NEWS}`);
404400
if (!isValidNewsNewsBody(body)) return;
405401

406-
newsNews(this, steamId, title, message, body);
402+
//newsNews(this, steamId, title, message, body);
407403
} break;
408404

409405
default: {

0 commit comments

Comments
 (0)