0.1.1 • Published 9 months ago

silent-detector v0.1.1

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
9 months ago

Silent Detector

Silent Detector is a React Native/Expo module that allows you to detect if silent mode is enabled on an iOS or Android mobile device.

Features

  • Silent mode detection on iOS and Android
  • Notification of mode changes via events
  • Checking the current state of silent mode
  • Configuration of a periodic check interval

Installation

In a managed Expo project

For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release. If you follow the link and there is no documentation available, this library is not yet usable within managed projects it is likely to be included in an upcoming Expo SDK release.

In a bare React Native project

For bare React Native projects, you must ensure that you have installed and configured the expo package before continuing.

Add the package to your npm dependencies

npm install silent-detector

Configure for iOS

Run npx pod-install after installing the npm package.

Configure for Android

No additional configuration is necessary for Android.

Usage

import { isSilentModeEnabled, addSilentModeListener, check, setCheckInterval, setAlwaysNotify } from 'silent-detector';

// Check if silent mode is enabled
const checkSilentMode = async () => {
  const isSilent = await isSilentModeEnabled();
  console.log('Silent mode enabled:', isSilent);
};

// Listen for silent mode changes
const listener = addSilentModeListener(({ isSilent }) => {
  console.log('Silent mode has changed:', isSilent);
});

// Force a check
check();

// Set a check interval (in seconds)
setCheckInterval(30);

// Configure to always notify, even if the state hasn't changed
setAlwaysNotify(true);

// Don't forget to remove the listener when you no longer need it
listener.remove();

API

  • isSilentModeEnabled(): Promise<boolean> - Checks if silent mode is enabled
  • check(): void - Forces an immediate check of silent mode
  • setCheckInterval(interval: number): void - Sets the check interval in seconds
  • setAlwaysNotify(always: boolean): void - Configures whether notifications should be sent even if the state hasn't changed
  • addSilentModeListener(listener: (event: SilentModeChangedEvent) => void): Subscription - Adds a listener for silent mode changes

Contributing

Contributions are very welcome! Please refer to guidelines described in the contributing guide.

License

This project is licensed under the MIT License. See the LICENSE file for details.

0.1.1

9 months ago

0.1.0

9 months ago