Skip to content

Commit f18d939

Browse files
committed
initial commit
1 parent c3ef15c commit f18d939

File tree

11 files changed

+1189
-33
lines changed

11 files changed

+1189
-33
lines changed

.gitignore

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
6-
# Runtime data
7-
pids
8-
*.pid
9-
*.seed
10-
11-
# Directory for instrumented libs generated by jscoverage/JSCover
12-
lib-cov
13-
14-
# Coverage directory used by tools like istanbul
15-
coverage
16-
17-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18-
.grunt
19-
20-
# node-waf configuration
21-
.lock-wscript
22-
23-
# Compiled binary addons (http://nodejs.org/api/addons.html)
24-
build/Release
25-
26-
# Dependency directory
27-
node_modules
28-
29-
# Optional npm cache directory
30-
.npm
31-
32-
# Optional REPL history
33-
.node_repl_history
1+
# CUSTOM
2+
#
3+
.*.swp
4+
5+
# OSX
6+
#
7+
.DS_Store
8+
9+
# Xcode
10+
#
11+
build/
12+
*.pbxuser
13+
!default.pbxuser
14+
*.mode1v3
15+
!default.mode1v3
16+
*.mode2v3
17+
!default.mode2v3
18+
*.perspectivev3
19+
!default.perspectivev3
20+
xcuserdata
21+
*.xccheckout
22+
*.moved-aside
23+
DerivedData
24+
*.hmap
25+
*.ipa
26+
*.xcuserstate
27+
project.xcworkspace
28+
29+
# Android/IJ
30+
#
31+
.idea
32+
.gradle
33+
local.properties
34+
35+
# node.js
36+
#
37+
node_modules/
38+
npm-debug.log

README.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# react-native-incall-manager
2+
Handling media-routes/sensors/events during a audio/video chat on React Native
3+
4+
## Purpose:
5+
The purpose of this module is to handle actions/events during a phone call (audio/video) on `react-native`, ex:
6+
* manage devices events like wired-headset plugged, proximity sensors and expose to javascript.
7+
* automatically route audio to proper device based on events and platform API.
8+
* ( not implemented yet ) toggle flash light on/off, force microphone mute
9+
10+
This module is desinged to work with [react-native-webrtc](https://github.com/oney/react-native-webrtc)
11+
you can find demo here: https://github.com/oney/RCTWebRTCDemo
12+
13+
## Installation:
14+
15+
**from npm package**: `npm install react-native-incall-manager`
16+
**from git package**: `npm install git://github.com/zxcpoiu/react-native-incall-manager.git`
17+
18+
===================================================
19+
####android:
20+
21+
After install, you can use `rnpm` (`npm install rnpm -g`) to link android.
22+
use `rnpm link react-native-incall-manager` to link or manually if you like.
23+
24+
===================================================
25+
26+
####ios:
27+
28+
since ios part written in swift and it doesn't support static library yet.
29+
before that, you should add this project manually:
30+
31+
- **Add files in to your project:**
32+
33+
1. Open your project in xcode
34+
2. find your_project directory under your project's xcodeproject root. ( it's a sub-directoory, not root xcodeproject itself )
35+
3. you can do either:
36+
* directly drag your node_modules/react-native-incall-manager/ios/RNInCallManager/ into it.
37+
* right click on your_project directory, `add files` to your project and add `node_modules/react-native-incall-manager/ios/RNInCallManager/`
38+
4. on the pou-up window, uncheck `Copy items if needed` and select `Added folders: Create groups` then add it. you will see a new directory named `RNInCallmanager under your_project` directory.
39+
40+
- **Setup Objective-C Bridging Header:**
41+
1. click your `project's xcodeproject root`, go to `build setting` and search `Objective-C Bridging Header`
42+
2. set you header location, the default path is: `ReactNativeProjectRoot/ios/`, in this case, you should set `../node_modules/react-native-incall-manager/ios/RNInCallManager/RNInCallManager-Bridging-Header.h`
43+
44+
## Usage:
45+
46+
This module implement a basic handle logic automatically, just:
47+
48+
```javascript
49+
import InCallManager from 'react-native-incall-manager';
50+
51+
// --- start manager when the chat start based on logics of your app
52+
// On Call Established:
53+
InCallManager.start({media: 'audio'}); // audio/video, default: audio
54+
55+
// ... it will also register and emit events ...
56+
57+
// --- On Call Hangup:
58+
InCallManager.stop();
59+
// ... it will also remote event listeners ...
60+
```
61+
62+
63+
and interact with events if you want:
64+
see API section.
65+
66+
```javascript
67+
import { DeviceEventEmitter } from 'react-native';
68+
69+
DeviceEventEmitter.addListener('Proximity', function (data) {
70+
// --- do something with events
71+
});
72+
73+
```
74+
75+
## Automatic Basic Behavior:
76+
77+
**on start:**
78+
* store current settings, set KeepScreenOn flag = true, and register some event listeners.
79+
* if media type is `audio`, route voice to earpiece, otherwise route to speaker.
80+
* when proximity detect user closed to screen, turn off screen to avoid accident touch and route voice to earpiece.
81+
* when newly external device plugged, such as wired-headset, route audio to external device.
82+
83+
**on stop:**
84+
85+
* set KeepScreenOn flag = false, remote event listeners, restore original user settings.
86+
87+
## Custom Behavior:
88+
89+
you can custom behavior use API/events exposed by this module. see `API` section.
90+
91+
note: ios only supports `auto` currently.
92+
93+
## API:
94+
95+
**Methods**
96+
97+
| Method | android | ios | description |
98+
| :--- | :---: | :---: | :--- |
99+
| start(`{media: ?string, auto: ?boolean}`) | :smile: | :smile: | start incall manager.</br>default: `{media:'audio', auto: true}` |
100+
| stop() | :smile: | :smile: | stop incall manager |
101+
| turnScreenOn() | :smile: | :rage: | force turn screen on |
102+
| turnScreenOff() | :smile: | :rage: | force turn screen off |
103+
| setKeepScreenOn(`enable: ?boolean`) | :smile: | :smile: | set KeepScreenOn flag = true or false</br>default: false |
104+
| setSpeakerphoneOn(`enable: ?boolean`) | :smile: | :rage: | toggle speaker ON/OFF once. but not force</br>default: false |
105+
| setForceSpeakerphoneOn(`enable: ?boolean`) | :smile: | :smile: | if set to true, will ignore all logic and force audio route to speaker</br>default: false |
106+
| setMicrophoneMute(`enable: ?boolean`) | :smile: | :rage: | mute/unmute micophone</br>default: false |
107+
108+
**Events**
109+
110+
| Event | android | ios | description |
111+
| :--- | :---: | :---: | :--- |
112+
| 'Proximity' | :smile: | :smile: | proximity sensor detected changes.<br>data: `{'isNear': boolean}` |
113+
| 'WiredHeadset'| :smile: | :rage: | fire when wired headset plug/unplug<br>data: `{'isPlugged': boolean, 'hasMic': boolean, 'deviceName': string }` |
114+
| 'NoisyAudio' | :smile: | :rage: | see [andriod doc](http://developer.android.com/reference/android/media/AudioManager.html#ACTION_AUDIO_BECOMING_NOISY).<br>data: `null` |
115+
| 'MediaButton' | :smile: | :rage: | when external device controler pressed button. see [android doc](http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_BUTTON) <br>data: `{'eventText': string, 'eventCode': number }` |
116+
| 'onAudioFocusChange' | :smile: | :rage: | see [andriod doc](http://developer.android.com/reference/android/media/AudioManager.OnAudioFocusChangeListener.html#onAudioFocusChange(int)) <br>data: `{'eventText': string, 'eventCode': number }` |
117+
118+
**NOTE: platform OS always has the final decision, so some toggle api may not work in some case
119+
be care when customize your own behavior**
120+
121+
## LICENSE:
122+
123+
**[ICS License](https://opensource.org/licenses/ISC)** ( functionality equivalent to **MIT License** )
124+
125+
## Contributing:
126+
127+
I'm not expert neither on ios nor android, any suggestions, pull request, corrections are really appreciated and welcome.

android/build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.1"
6+
7+
defaultConfig {
8+
minSdkVersion 16
9+
targetSdkVersion 22
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
}
14+
15+
dependencies {
16+
compile 'com.facebook.react:react-native:0.20.+'
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.zxcpoiu.incallmanager" >
4+
</manifest>
5+

0 commit comments

Comments
 (0)