flutter_incall 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

flutter-incall-manager #

Port from react-native-incall-manager #

  • Handling media-routes/sensors/events during a audio/video chat on Flutter

API: #

Methods

Methodandroidiosdescription
start({media: ?string, auto: ?boolean, ringback: ?string})😄😄start incall manager.
ringback accept non-empty string or it won't play
default: {media:'audio', auto: true, ringback: ''}
stop({busytone: ?string})😄😄stop incall manager
busytone accept non-empty string or it won't play
default: {busytone: ''}
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(flag: ?boolean)😄😄true -> force speaker on
false -> force speaker off
null -> use default behavior according to media type
default: null
setMicrophoneMute(enable: ?boolean)😄😡mute/unmute micophone
default: false
p.s. if you use webrtc, you can just use track.enabled = false to mute
async checkRecordPermission()😄😄check record permission without promt. return Promise. see about permission section above
async requestRecordPermission()😄😄request record permission to user. return Promise. see about permission section above
startRingtone(ringtone: string, ?vibrate_pattern: array, ?ios_category: string, ?seconds: number)😄😄play ringtone.
ringtone: 'DEFAULT' or 'BUNDLE'
vibrate_pattern: same as RN, but does not support repeat
ios_category: ios only, if you want to use specific audio category
seconds: android only, specify how long do you want to play rather than play once nor repeat. in sec.
stopRingtone()😄😄stop play ringtone if previous started via startRingtone()
stopRingback()😄😄stop play ringback if previous started via start()
setFlashOn(enable: ?boolean, brightness: ?number)😡😄set flash light on/off
async getIsWiredHeadsetPluggedIn()😡😄return wired headset plugged in state

Events

Eventandroidiosdescription
'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 }

[1.0.0] - 2020.02.01 #

  • Initial release.

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_incall/flutter_incall.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  IncallManager incallManager = new IncallManager();

  @override
  initState() {
    super.initState();
  }

  void showResult(title, result) {
    print('$title => $result.');
  }

  List<Widget> buildTestButtons() {
    List<Map<String, dynamic>> items = [
      {
        'InCallManager.start(audio)': () {
          incallManager.start(
              media: MediaType.AUDIO, auto: false, ringback: '_DEFAULT_');
        }
      },
      {
        'InCallManager.start(video)': () {
          incallManager.start(
              media: MediaType.VIDEO, auto: false, ringback: '_DEFAULT_');
        }
      },
      {
        'InCallManager.stop': () {
          incallManager.stop();
        }
      },
      {
        'enableProximitySensor(true)': () {
          incallManager.enableProximitySensor(true);
        }
      },
      {
        'enableProximitySensor(false)': () {
          incallManager.enableProximitySensor(false);
        }
      },
      {
        'checkRecordPermission': () async {
          showResult('checkRecordPermission',
              await incallManager.checkRecordPermission());
        }
      },
      {
        'checkCameraPermission': () async {
          showResult('checkCameraPermission',
              await incallManager.checkCameraPermission());
        }
      },
      {
        'requestRecordPermission': () {
          incallManager.requestRecordPermission();
        }
      },
      {
        'requestCameraPermission': () {
          incallManager.requestCameraPermission();
        }
      },
      {
        'setKeepScreenOn(true)': () {
          incallManager.setKeepScreenOn(true);
        }
      },
      {
        'setKeepScreenOn(false)': () {
          incallManager.setKeepScreenOn(false);
        }
      },
      {
        'setSpeakerphoneOn(true)': () {
          incallManager.setSpeakerphoneOn(true);
        }
      },
      {
        'setSpeakerphoneOn(false)': () {
          incallManager.setSpeakerphoneOn(false);
        }
      },
      {
        'startRingback': () {
          incallManager.startRingback();
        }
      },
      {
        'stopRingback': () {
          incallManager.stopRingback();
        }
      },
      {
        'startRingtone(30)': () {
          incallManager.startRingtone(RingtoneUriType.DEFAULT, 'default', 30);
        }
      },
      {
        'stopRingtone': () {
          incallManager.stopRingtone();
        }
      },
    ];

    if (Platform.isAndroid) {
      items.addAll([
        {
          'turnScreenOn': () {
            incallManager.turnScreenOn();
          }
        },
        {
          'turnScreenOff': () {
            incallManager.turnScreenOff();
          }
        },
        {
          'setMicrophoneMute(true)': () {
            incallManager.setMicrophoneMute(true);
          }
        },
        {
          'setMicrophoneMute(false)': () {
            incallManager.setMicrophoneMute(false);
          }
        }
      ]);
    }

    return items
        .map((item) => RaisedButton(
              onPressed: () async {
                print('${item.keys.first}');
                await item.values.first();
              },
              child: new Text(item.keys.first),
            ))
        .toList();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Flutter InCallManager example'),
        ),
        body: new SingleChildScrollView(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: buildTestButtons(),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_incall: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_incall/flutter_incall.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
86
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Fix lib/flutter_incall.dart. (-1.49 points)

Analysis of lib/flutter_incall.dart reported 3 hints:

line 194 col 13: The value of the local variable 'eventCode' isn't used.

line 199 col 14: The value of the local variable 'eventCode' isn't used.

line 203 col 16: The value of the local variable 'availableAudioDeviceList' isn't used.

Maintenance suggestions

The package description is too short. (-14 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8