JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12466
  • Score
    100M100P100Q144930F
  • License ISC

Handling media-routes/sensors/events during a audio/video chat on React Native

Package Exports

  • react-native-incall-manager

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-incall-manager) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-native-incall-manager

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, proximity sensors and expose to javascript.
  • automatically route audio to proper device based on events and platform API.
  • ( not implemented yet ) toggle flash light on/off, force microphone mute

This module is desinged to work with react-native-webrtc you can find demo here: https://github.com/oney/RCTWebRTCDemo

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:

After install, you can use rnpm (npm install rnpm -g) to link android.
use rnpm link react-native-incall-manager to link or manually if you like.

===================================================

####ios:

since ios part written in swift and it doesn't support static library yet.
before that, you should add this project manually:

  • Add files in to your project:

    1. Open your project in xcode
    2. find your_project directory under your project's xcodeproject root. ( it's a sub-directoory, not root xcodeproject itself )
    3. you can do either:
    • directly drag your node_modules/react-native-incall-manager/ios/RNInCallManager/ into it.
    • right click on your_project directory, add files to your project and add node_modules/react-native-incall-manager/ios/RNInCallManager/
    1. 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.
  • Setup Objective-C Bridging Header:

    1. click your project's xcodeproject root, go to build setting and search Objective-C Bridging Header
    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

Usage:

This module implement a basic handle logic automatically, just:

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 remote event listeners ...

and interact with events if you want: see API section.

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 detect user closed to screen, turn off screen to avoid accident touch and route voice to earpiece.
  • when newly external device plugged, such as wired-headset, route audio to external device.

on stop:

  • set KeepScreenOn flag = false, remote event listeners, restore original user settings.

Custom Behavior:

you can custom behavior use API/events exposed by this module. see API section.

note: ios only supports auto currently.

API:

Methods

Method android ios description
start({media: ?string, auto: ?boolean}) 😄 😄 start incall manager.
default: {media:'audio', auto: true}
stop() 😄 😄 stop incall manager
turnScreenOn() 😄 😡 force turn screen on
turnScreenOff() 😄 😡 force turn screen off
setKeepScreenOn(enable: ?boolean) 😄 😄 set KeepScreenOn flag = true or false
default: false
setSpeakerphoneOn(enable: ?boolean) 😄 😡 toggle speaker ON/OFF once. but not force
default: false
setForceSpeakerphoneOn(enable: ?boolean) 😄 😄 if set to true, will ignore all logic and force audio route to speaker
default: false
setMicrophoneMute(enable: ?boolean) 😄 😡 mute/unmute micophone
default: false

Events

Event android ios description
'Proximity' 😄 😄 proximity sensor detected changes.
data: {'isNear': boolean}
'WiredHeadset' 😄 😡 fire when wired headset plug/unplug
data: {'isPlugged': boolean, 'hasMic': boolean, 'deviceName': string }
'NoisyAudio' 😄 😡 see andriod doc.
data: null
'MediaButton' 😄 😡 when external device controler pressed button. see android doc
data: {'eventText': string, 'eventCode': number }
'onAudioFocusChange' 😄 😡 see andriod doc
data: {'eventText': string, 'eventCode': number }

NOTE: platform OS always has the final decision, so some toggle api may not work in some case be care when customize your own behavior

LICENSE:

ICS License ( functionality equivalent to MIT License )

Contributing:

I'm not expert neither on ios nor android, any suggestions, pull request, corrections are really appreciated and welcome.