Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
navigation,
isPickingImage,
isBrowsingWebView,
stopListeningForBalanceChange,
endWalkthrough,
} = this.props;
const { lastAppState } = this.state;
BackgroundTimer.clearTimeout(lockTimer);
if (isPickingImage || isBrowsingWebView) return;
// only checking if background state for logout or websocket channel close
if (APP_LOGOUT_STATES.includes(nextAppState)) {
// close websocket channel instantly to receive PN while in background
stopListeningChatWebSocket();
// close walkthrough shade or tooltips
endWalkthrough();
lockTimer = BackgroundTimer.setTimeout(() => {
const pathAndParams = navigation.router.getPathAndParamsForState(navigation.state);
const lastActiveScreen = pathAndParams.path.split('/').slice(-1)[0];
const lastActiveScreenParams = pathAndParams.params;
updateNavigationLastScreenState({ lastActiveScreen, lastActiveScreenParams });
navigation.navigate(AUTH_FLOW);
stopListeningNotifications();
stopListeningIntercomNotifications();
updateSignalInitiatedState(false);
stopListeningForBalanceChange();
}, SLEEP_TIMEOUT);
} else if (APP_LOGOUT_STATES.includes(lastAppState)
&& nextAppState === ACTIVE_APP_STATE) {
startListeningChatWebSocket();
}
this.setState({ lastAppState: nextAppState });
};
export const connectDevice = (device) => (dispatch, getState) => {
RFDuinoLib.connectDevice(device);
const state = getState();
logAttemptConnectDeviceAnalytics(false, state);
// HACK: ideally this is a connect timeout saga
// but it requires both background timer and access to actions
// therefore putting it here
connectTimeoutTimer = BackgroundTimer.setTimeout(() => {
// check to see if stuck connecting
const state = getState();
const status = ConnectedDeviceStatusSelectors.getConnectedDeviceStatus(state);
if (status === 'CONNECTING') {
// disconnect
logConnectedToDeviceTimedOutAnalytics(false, state);
dispatch(disconnectDevice(false)); // in case it's trying to connect, ensure it's actually disconnecting
dispatch(disconnectedFromDevice()); // in case it can never find it, visually update
}
}, 5000);
dispatch({
type: CONNECT_DEVICE,
device: device
});
};
export const reconnectDevice = (device, identifier) => (dispatch, getState) => {
const state = getState();
logAttemptConnectDeviceAnalytics(true, state);
// reconnect after a second as V2s have issues
reconnectTimer = BackgroundTimer.setTimeout(() => {
RFDuinoLib.connectDevice(device);
}, 2000);
// HACK: ideally this is a connect timeout saga
// but it requires both background timer and access to actions
// therefore putting it here
reconnectTimeoutTimer = BackgroundTimer.setTimeout(() => {
// check to see if stuck connecting
const state = getState();
const status = ConnectedDeviceStatusSelectors.getConnectedDeviceStatus(state);
if (status !== 'CONNECTED') {
// disconnect
dispatch(disconnectDevice(false)); // in case it's trying to connect, ensure it's actually disconnecting
dispatch(disconnectedFromDevice(device, identifier)); // in case it can never find it, visually update and trigger another reconnect
logConnectedToDeviceTimedOutAnalytics(true, state);
}
const didReceiveStartCallAction = ({ handle }) => {
if (!handle) {
// @TODO: sometime we receive `didReceiveStartCallAction` with handle` undefined`
return;
}
const callUUID = getNewUuid();
addCall(callUUID, handle);
log(`[didReceiveStartCallAction] ${callUUID}, number: ${handle}`);
RNCallKeep.startCall(callUUID, handle, handle);
BackgroundTimer.setTimeout(() => {
log(`[setCurrentCallActive] ${format(callUUID)}, number: ${handle}`);
RNCallKeep.setCurrentCallActive(callUUID);
}, 1000);
};
export const connectDevice = (device) => (dispatch, getState) => {
RFDuinoLib.connectDevice(device);
const state = getState();
logAttemptConnectDeviceAnalytics(false, state);
// HACK: ideally this is a connect timeout saga
// but it requires both background timer and access to actions
// therefore putting it here
connectTimeoutTimer = BackgroundTimer.setTimeout(() => {
// check to see if stuck connecting
const state = getState();
const status = ConnectedDeviceStatusSelectors.getConnectedDeviceStatus(state);
if (status === 'CONNECTING') {
// disconnect
logConnectedToDeviceTimedOutAnalytics(false, state);
dispatch(disconnectDevice(false)); // in case it's trying to connect, ensure it's actually disconnecting
dispatch(disconnectedFromDevice()); // in case it can never find it, visually update
}
}, 5000);
dispatch({
type: CONNECT_DEVICE,
device: device
});
};
export const reconnectDevice = (device, identifier) => (dispatch, getState) => {
const state = getState();
logAttemptConnectDeviceAnalytics(true, state);
// reconnect after a second as V2s have issues
reconnectTimer = BackgroundTimer.setTimeout(() => {
RFDuinoLib.connectDevice(device);
}, 2000);
// HACK: ideally this is a connect timeout saga
// but it requires both background timer and access to actions
// therefore putting it here
reconnectTimeoutTimer = BackgroundTimer.setTimeout(() => {
// check to see if stuck connecting
const state = getState();
const status = ConnectedDeviceStatusSelectors.getConnectedDeviceStatus(state);
if (status !== 'CONNECTED') {
// disconnect
dispatch(disconnectDevice(false)); // in case it's trying to connect, ensure it's actually disconnecting
dispatch(disconnectedFromDevice(device, identifier)); // in case it can never find it, visually update and trigger another reconnect
logConnectedToDeviceTimedOutAnalytics(true, state);
}
}, 7000);
dispatch({
type: RECONNECT_DEVICE,
device: device
});
};
const runTimer = (duration, dispatch) => {
console.tron.log("Running timer with duration " + duration);
startTime = Date.now();
isPaused = false;
timer = BackgroundTimer.setTimeout(() => {
console.tron.log("End set timer executed with duration " + duration + "! time to end set");
timeRemaining = null;
startTime = null;
timer = null;
isPaused = false;
dispatch(SetsActionCreators.endSet());
}, duration);
};
const displayIncomingCallDelayed = () => {
BackgroundTimer.setTimeout(() => {
displayIncomingCall(getRandomNumber());
}, 3000);
};
indicateRing() {
if (!this.verto.ringer) {
printWarning(`Call is ringing, but no ringer set. ${this}`);
return;
}
if (!this.verto.ringer.src && this.verto.options.ringFile) {
this.verto.ringer.src = this.verto.options.ringFile;
}
this.verto.ringer.play();
BackgroundTimer.setTimeout(() => {
this.stopRinging();
if (this.state === ENUM.state.ringing) {
this.indicateRing();
} else {
printWarning(`Call stopped ringing, but no ringer set. ${this}`);
}
}, this.verto.options.ringSleep);
}
} else if (data.type == 'remote-pause') {
TrackPlayer.pause();
} else if (data.type == 'remote-next') {
TrackPlayer.skipToNext();
} else if (data.type == 'remote-previous') {
TrackPlayer.skipToPrevious();
} else if (data.type == 'remote-seek') {
TrackPlayer.seekTo(data.position);
} else if (data.type == 'remote-duck') {
if (data.paused) TrackPlayer.pause();
if (data.permanent) TrackPlayer.stop();
if (data.ducking) {
const prevVolume = await TrackPlayer.getVolume();
TrackPlayer.setVolume(0.1);
BackgroundTimer.setTimeout(() => {
TrackPlayer.setVolume(prevVolume);
}, 3 * 1000);
}
}
};