Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "react-native-background-timer in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'react-native-background-timer' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

handleAppStateChange = (nextAppState: string) => {
    const {
      stopListeningNotifications,
      stopListeningIntercomNotifications,
      startListeningChatWebSocket,
      stopListeningChatWebSocket,
      updateSignalInitiatedState,
      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);
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 default async function photosTask (dispatch, failedImages) {
  // console.log('FAILED IMAGES:', failedImages)
  console.log('running photos task')
  BackgroundTimer.start() // This requests some background time from the OS

  // Start IPFS
  const path = RNFS.DocumentDirectoryPath
  await IPFS.createNodeWithDataDir(path)
  await IPFS.startNode()

  // Get a list of the jobs already in the queue
  // const existingJobs = await queue.getJobs(true)

  // Query for any new photos, add jobs to queue
  const photos = await queryPhotos()
  // PushNotificationIOS.presentLocalNotification({
  //   alertBody: 'fetch of ' + photos.length + ' photos',
  //   userInfo: {}
  // })
  for (const photo of photos) {
dispatch(Actions.imageAdded(photo, multipartData.payloadPath))
    UploadTask.uploadFile(multipartData.payloadPath, 'https://ipfs.textile.io/api/v0/add?wrap-with-directory=true', 'POST', multipartData.boundary)

    // PushNotificationIOS.presentLocalNotification({
    //   alertBody: 'uploading photo ' + multipartData.payloadPath,
    //   userInfo: {}
    // })
  }

  // PushNotificationIOS.presentLocalNotification({
  //   alertBody: 'photos task done',
  //   userInfo: {}
  // })
  console.log('photos task done')

  BackgroundTimer.stop() // This alerts the OS that we're done with our background task
}
export const startEndSetTimer = () => (dispatch, getState) => {
    BackgroundTimer.clearTimeout(timer);
    timer = null;
    timeRemaining = null;
    startTime = null;
    isPaused = false;
    
    let state = getState();
    let durationInSeconds = state.settings.endSetTimerDuration;
    let isEditing = WorkoutSelectors.getIsEditing(state);

    if (durationInSeconds == null || durationInSeconds == 0) {
        timer = null;
    } else if (isEditing) {
        timeRemaining = durationInSeconds * 1000;
        isPaused = true;
        startTime = Date.now();
        // start it paused
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
    });
};

Is your System Free of Underlying Vulnerabilities?
Find Out Now