-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update package.json, README.md, and refactor VolumeManager module
- Added new keywords to package.json for better discoverability: "expo", "volume", "mute", "silent". - Enhanced README.md to clarify that the library is not functional on the web, while maintaining existing functionality descriptions. - Refactored imports in hooks.ts and index.ts to use the new module.ts file for improved organization. - Introduced module.ts and module.web.ts to separate platform-specific implementations and provide no-op methods for web compatibility.
- Loading branch information
Showing
6 changed files
with
184 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './native'; | ||
export * from './module'; | ||
export * from './hooks'; | ||
export * from './types'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import type { | ||
AVAudioSessionCategory, | ||
AVAudioSessionMode, | ||
EmitterSubscriptionNoop, | ||
RingMuteSwitchEventCallback, | ||
RingerEventCallback, | ||
RingerModeType, | ||
VolumeManagerSetVolumeConfig, | ||
VolumeResult, | ||
} from './types'; | ||
|
||
// Track if warning has been shown | ||
let hasWarned = false; | ||
|
||
// Helper function to show warning only in development | ||
const warnOnWeb = () => { | ||
if (__DEV__ && !hasWarned) { | ||
console.warn( | ||
'react-native-volume-manager is not functional on the web. While the package exports no-op methods for web usage, allowing you to include it without any issues, these methods have no actual effect. This warning is only visible in development mode.' | ||
); | ||
hasWarned = true; | ||
} | ||
}; | ||
|
||
const noopEmitterSubscription: EmitterSubscriptionNoop = { | ||
remove: () => { | ||
// noop | ||
}, | ||
}; | ||
|
||
// Base volume result for web platform | ||
const defaultVolumeResult: VolumeResult = { | ||
volume: 1, | ||
}; | ||
|
||
export async function getRingerMode(): Promise<RingerModeType | undefined> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function setRingerMode( | ||
_mode: RingerModeType | ||
): Promise<RingerModeType | undefined> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function enable( | ||
_enabled: boolean = true, | ||
_async: boolean = true | ||
): Promise<void> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function setActive( | ||
_value: boolean = true, | ||
_async: boolean = true | ||
): Promise<void> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function setCategory( | ||
_value: AVAudioSessionCategory, | ||
_mixWithOthers: boolean = false | ||
): Promise<void> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function setMode(_value: AVAudioSessionMode): Promise<void> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function enableInSilenceMode( | ||
_enabled: boolean = true | ||
): Promise<void> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function checkDndAccess(): Promise<boolean | undefined> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function requestDndAccess(): Promise<boolean | undefined> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function getVolume(): Promise<VolumeResult> { | ||
warnOnWeb(); | ||
return defaultVolumeResult; | ||
} | ||
|
||
export async function setVolume( | ||
_value: number, | ||
_config: VolumeManagerSetVolumeConfig = {} | ||
): Promise<void> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export async function showNativeVolumeUI(_config: { | ||
enabled: boolean; | ||
}): Promise<void> { | ||
warnOnWeb(); | ||
return undefined; | ||
} | ||
|
||
export function addVolumeListener( | ||
_callback: (result: VolumeResult) => void | ||
): EmitterSubscriptionNoop { | ||
warnOnWeb(); | ||
return noopEmitterSubscription; | ||
} | ||
|
||
export const addSilentListener = ( | ||
_callback: RingMuteSwitchEventCallback | ||
): EmitterSubscriptionNoop => { | ||
warnOnWeb(); | ||
return noopEmitterSubscription; | ||
}; | ||
|
||
export const setNativeSilenceCheckInterval = (_value: number): void => { | ||
warnOnWeb(); | ||
// noop | ||
}; | ||
|
||
export const isAndroidDeviceSilent = (): Promise<boolean | null> => { | ||
warnOnWeb(); | ||
return Promise.resolve(null); | ||
}; | ||
|
||
export const addRingerListener = ( | ||
_callback: RingerEventCallback | ||
): EmitterSubscriptionNoop => { | ||
warnOnWeb(); | ||
return noopEmitterSubscription; | ||
}; | ||
|
||
export const removeRingerListener = ( | ||
_listener: EmitterSubscriptionNoop | ||
): void => { | ||
warnOnWeb(); | ||
// noop | ||
}; | ||
|
||
export const VolumeManager = { | ||
addVolumeListener, | ||
getVolume, | ||
setVolume, | ||
showNativeVolumeUI, | ||
isAndroidDeviceSilent, | ||
addSilentListener, | ||
addRingerListener, | ||
removeRingerListener, | ||
setNativeSilenceCheckInterval, | ||
getRingerMode, | ||
setRingerMode, | ||
checkDndAccess, | ||
requestDndAccess, | ||
enable, | ||
setActive, | ||
setCategory, | ||
setMode, | ||
enableInSilenceMode, | ||
}; | ||
|
||
export default VolumeManager; |