# react-native-incall-manager
[![npm version](https://badge.fury.io/js/react-native-incall-manager.svg)](https://badge.fury.io/js/react-native-incall-manager)
[![npm downloads](https://img.shields.io/npm/dm/react-native-incall-manager.svg?maxAge=2592000)](https://img.shields.io/npm/dm/react-native-incall-manager.svg?maxAge=2592000)
Handling media-routes/sensors/events during a audio/video chat on React Native
## Purpose:
The purpose of this module is to handle actions/events during a phone call (audio/video) on `react-native`, ex:
* Manage devices events like wired-headset plugged-in state, proximity sensors and expose functionalities to javascript.
* Automatically route audio to proper devices based on events and platform API.
* Toggle speaker or microphone on/off, toggle flashlight on/off
* Play ringtone/ringback/dtmftone
Basically, it is a telecommunication module which handles most of the requirements when making/receiving/talking with a call.
This module is designed to work with [react-native-webrtc](https://github.com/oney/react-native-webrtc)
## TODO / Contribution Wanted:
* Make operations run on the main thread. ( iOS/Android )
* Fix iOS audio shared instance singleton conflict with internal webrtc.
* Detect hardware button press event and react to it.
ex: press bluetooth button, send an event to JS to answer/hangup.
ex: press power button to mute incoming ringtone.
* Use config-based to decide which event should start and report. maybe control behavior as well.
* Flash API on Android.
## Installation:
**From npm package**: `npm install react-native-incall-manager`
**From git package**: `npm install git://github.com/zxcpoiu/react-native-incall-manager.git`
===================================================
### Android:
note: you might need `android.permission.BLUETOOTH` permisions for Bluetooth to work.
After install, you can use `rnpm` (`npm install rnpm -g`) to link android.
use `react-native link react-native-incall-manager` to link or manually if you like.
We use android support library v4 to check/request permissions.
You should add `compile "com.android.support:support-v4:$YOUR_VERSION"` in `$YOUR_PROJECT/android/app/build.gradle` dependencies on android.
#### Manually Linking
If `react-native link` doesn't work, ( see: https://github.com/zxcpoiu/react-native-incall-manager/issues/21#issuecomment-279575516 ) please add it manually in your main project:
1. In `android/app/build.gradle`
Should have a line `compile(project(':react-native-incall-manager'))` in `dependencies {}` section
2. In `android/settings.gradle`
Should have:
```
include ':react-native-incall-manager'
project(':react-native-incall-manager').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-incall-manager/android')
```
3. In `MainApplication.java`
```java
import com.zxcpoiu.incallmanager.InCallManagerPackage;
private static List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new InCallManagerPackage(),
);
}
```
#### Optional sound files on android
If you want to use bundled ringtone/ringback/busytone sound instead of system sound,
put files in `android/app/src/main/res/raw`
and rename file correspond to sound type:
```
incallmanager_busytone.mp3
incallmanager_ringback.mp3
incallmanager_ringtone.mp3
```
On android, as long as your file extension supported by android, this module will load it.
===================================================
### ios:
`react-native link react-native-incall-manager`
#### Using CocoaPods
Update the following line with your path to node_modules/ and add it to your Podfile:
`pod 'ReactNativeIncallManager', :path => '../node_modules/react-native-incall-manager'`
#### Manually Linking
In case `react-native link` doesn't work,
- Drag `node_modules/react-native-incall-manager/ios/RNInCallManager.xcodeproj` under `<your_xcode_project>/Libraries`
- Select `<your_xcode_project>` --> `Build Phases` --> `Link Binary With Libraries`
- Drag `Libraries/RNInCallManager.xcodeproj/Products/libRNInCallManager.a` to `Link Binary With Libraries`
- Select `<your_xcode_project>` --> `Build Settings`
- In `Header Search Paths`, add `$(SRCROOT)/../node_modules/react-native-incall-manager/ios/RNInCallManager`
#### Clean project if messed up:
The installation steps are a bit complex, it might be related your xcode version, xcode cache, converting swift version, and your own path configurations. if something messed up, please follow steps below to clean this project, then do it again steps by steps.
1. Delete all project/directory in xcode related to incall-manager
2. Delete `react-native-incall-manager` in node_modules ( rm -rf )
3. Xcode -> Product -> clean
4. Close xcode
5. Run `npm install` again
6. Open xcode and try the install process again steps by steps
If someone knows a simpler way to set this project up, let me know plz.
#### Optional sound files on iOS
If you want to use bundled ringtone/ringback/busytone sound instead of system sound
1. Add files into your_project directory under your project's xcodeproject root. ( or drag into it as described above. )
2. Check `copy file if needed`
3. Make sure filename correspond to sound type:
```
incallmanager_busytone.mp3
incallmanager_ringback.mp3
incallmanager_ringtone.mp3
```
On ios, we only support mp3 files currently.
## Usage:
This module implements a basic handle logic automatically, just:
```javascript
import InCallManager from 'react-native-incall-manager';
// --- start manager when the chat start based on logics of your app
// On Call Established:
InCallManager.start({media: 'audio'}); // audio/video, default: audio
// ... it will also register and emit events ...
// --- On Call Hangup:
InCallManager.stop();
// ... it will also remove event listeners ...
```
If you want to use ringback:
```javascript
// ringback is basically for OUTGOING call. and is part of start().
InCallManager.start({media: 'audio', ringback: '_BUNDLE_'}); // or _DEFAULT_ or _DTMF_
//when callee answered, you MUST stop ringback explicitly:
InCallManager.stopRingback();
```
If you want to use busytone:
```javascript
// busytone is basically for OUTGOING call. and is part of stop()
// If the call failed or callee are busing,
// you may want to stop the call and play busytone
InCallManager.stop({busytone: '_DTMF_'}); // or _BUNDLE_ or _DEFAULT_
```
If you want to use ringtone:
```javascript
// ringtone is basically for INCOMING call. it's independent to start() and stop()
// if you receiving an incoming call, before user pick up,
// you may want to play ringtone to notify user.
InCallManager.startRingtone('_BUNDLE_'); // or _DEFAULT_ or system filename with extension
// when user pickup
InCallManager.stopRingtone();
InCallManager.start();
// or user hangup
InCallManager.stopRingtone();
InCallManager.stop();
```
Also can interact with events if you want:
See API section.
```javascript
import { DeviceEventEmitter } from 'react-native';
DeviceEventEmitter.addListener('Proximity', function (data) {
// --- do something with events
});
```
## Automatic Basic Behavior:
**On start:**
* Store current settings, set KeepScreenOn flag = true, and register some event listeners.
* If media type is `audio`, route voice to earpiece, otherwise route to speaker.
* Audio will enable proximity sensor which is disabled by default if media=video
* When proximity detects user close to screen, turn off screen to avoid accident touch and route voice to the earpiece.
* When newly external device plugged, such as wired-headset, route audio to an external device.
* Optional play ringback
**On stop:**
* Set KeepScreenOn flag = false, remote event listeners, restore original user settings.
* Optionally play busytone
## Custom Behavior:
You can
没有合适的资源?快使用搜索试试~ 我知道了~
在 React Native 上的音频/视频聊天期间处理媒体路由/传感器/事件_Java_代码_相关文件Objective-C
共25个文件
java:8个
diff:4个
license:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 170 浏览量
2022-07-14
01:15:34
上传
评论
收藏 59KB ZIP 举报
温馨提示
在 React Native 上的音频/视频聊天期间处理媒体路由/传感器/事件 目的: 此模块的目的是处理电话(音频/视频)期间的操作/事件react-native,例如: 管理设备事件,如有线耳机插入状态、接近传感器并将功能公开给 javascript。 根据事件和平台 API 自动将音频路由到适当的设备。 打开/关闭扬声器或麦克风,打开/关闭手电筒 播放铃声/回铃音/dtmftone 基本上,它是一个电信模块,可以处理拨打/接听/通话时的大部分要求。 该模块旨在与react-native-webrtc 一起使用 待办事项/想要的贡献: 使操作在主线程上运行。(iOS/安卓) 修复 iOS 音频共享实例单例与内部 webrtc 冲突。 检测硬件按钮按下事件并对其做出反应。 例如:按下蓝牙按钮,向 JS 发送事件以接听/挂断。 例如:按电源按钮静音传入铃声。 使用基于配置来决定应该启动和报告哪个事件。也许也可以控制行为。 Android 上的 Flash API。 更多详情、使用方法,请下载后细读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
react-native-incall-manager-master.zip (25个子文件)
react-native-incall-manager-master
ios
RNInCallManager
RNInCallManager.h 394B
RNInCallManager.m 51KB
RNInCallManager.xcodeproj
project.pbxproj 9KB
index.js 5KB
android
src
main
java
com
zxcpoiu
incallmanager
InCallManagerModule.java 75KB
InCallWakeLockUtils.java 4KB
AppRTC
AppRTCBluetoothManager.java 22KB
diff
AppRTCUtils.java.diff 404B
ThreadUtils.java.diff 6KB
AppRTCProximitySensor.java.diff 1KB
AppRTCBluetoothManager.java.diff 2KB
LICENSE 1KB
README 411B
util
ThreadUtils.java 1KB
AppRTCUtils.java 2KB
AppRTCProximitySensor.java 6KB
InCallProximityManager.java 6KB
InCallManagerPackage.java 2KB
AndroidManifest.xml 163B
build.gradle 586B
package.json 855B
LICENSE 739B
ReactNativeIncallManager.podspec 844B
.gitignore 360B
README.md 11KB
共 25 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功