Skip to content

Commit

Permalink
Ignore all Pusher events when forcing offline
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-marcellini committed Nov 28, 2022
1 parent 6d86036 commit 41fa6c1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libs/Pusher/pusher.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import Onyx from 'react-native-onyx';
import _ from 'underscore';
import ONYXKEYS from '../../ONYXKEYS';
import Pusher from './library';
import TYPE from './EventType';
import Log from '../Log';

let shouldForceOffline = false;
Onyx.connect({
key: ONYXKEYS.NETWORK,
callback: (network) => {
if (!network) {
return;
}
shouldForceOffline = Boolean(network.shouldForceOffline);
},
});

let socket;
const socketEventCallbacks = [];
let customAuthorizer;
Expand Down Expand Up @@ -112,6 +125,11 @@ function bindEventToChannel(channel, eventName, eventCallback = () => {}) {

const chunkedDataEvents = {};
const callback = (eventData) => {
if (shouldForceOffline) {
Log.info('[Pusher] Ignoring a Push event because shouldForceOffline = true');
return;
}

let data;
try {
data = _.isObject(eventData) ? eventData : JSON.parse(eventData);
Expand Down

0 comments on commit 41fa6c1

Please sign in to comment.