flutter_voximplant 2.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

flutter_voximplant #

Voximplant Flutter SDK for embedding voice and video communication into Flutter applications.

Demo #

https://github.com/voximplant/flutter_demos

Install #

Add flutter_voximplant as a dependency in your pubspec.yaml file.

iOS #

Add the following entry to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>Microphone is required to make audio calls</string>
<key>NSCameraUsageDescription</key>
<string>Camera is required to make video calls</string>

This entry allows your app to access the microphone and cameras.

Android #

It is required to add Java 8 support.

Open <project root>android/app/build.gradle file and add the following lines to ‘android’ section:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Usage #

To get started, you'll need to register a free Voximplant developer account.

Initialization

Client is the main class of the SDK that provides access to Voximplant’s functions, the Voximplant().getClient() method is used to get its instance:

import 'package:flutter_voximplant/flutter_voximplant.dart';


VIClient client = Voximplant().getClient();

Connect and log in to the Voximplant Cloud

The VIClient.getClientState() method is used to get the current state of connection to the Voximplant cloud and perform the actions according to it.

  Future<String> loginWithPassword(String username, String password) async {
    VIClientState clientState = await _client.getClientState();
    if (clientState == VIClientState.LoggedIn) {
      return _displayName;
    }
    if (clientState == VIClientState.Disconnected) {
      await _client.connect();
    }
    VIAuthResult authResult = await _client.login(username, password);
    _displayName = authResult.displayName;
    return _displayName;
  }

Make calls

To initiate a call we need the VIClient.call method. There is a VICallSettings class which could contain custom data and extra headers (SIP headers).

Since the call can behave in different ways, there is a group of call events. They can be triggered by the VICall class instance as the class contains all the functionality for call management.

  Future<VICall> makeAudioCall(String number) async {
     VICall call = await _client.call(number);
     call.onCallDisconnected = _onCallDisconnected;
     call.onCallFailed = _onCallFailed;
     call.onCallConnected = _onCallConnected;
     call.onCallRinging = _onCallRinging;
     call.onCallAudioStarted = _onCallAudioStarted;
     return call;
  }
   
  _onCallConnected(VICall call, Map<String, String> headers) {
      print('Call connected');
  }

Receiving calls

Client.onIncomingCall is used to get incoming calls.

There are three methods for an incoming call: answer, decline and reject. An audio stream can be sent only after the answer method call.

  CallService._() {
    _client = Voximplant().getClient();
    _client.onIncomingCall = _onIncomingCall;
  }

  _onIncomingCall(VIClient client, VICall call, bool video, Map<String, String> headers) async {
    await call.answer();
  }

Mid-call operations

Audio call can be put on/off hold

  _hold() async {
    try {
      await _call.hold(!_isOnHold);
      setState(() {
        _isOnHold = !_isOnHold;
      });
    } catch (e) {
      
    }

  }

Audio device management

VIAudioDeviceManager class API allow to:

  • get all available audio devices
  • get currently selected audio device
  • select audio device
  • handle active audio device changes and new audio devices (for example, Bluetooth headset or wired headset connection). These changes trigger the appropriate events.

All types of audio devices are represented in the VIAudioDevice enum.

Note that there are platform specific nuances in audio device management.

To select an audio device:

  _selectAudioDevice(VIAudioDevice device) async{
    VIAudioDeviceManager audioDeviceManager = Voximplant().getAudioDeviceManager();
    audioDeviceManager.onAudioDeviceChanged = _onAudioDeviceChange;
    await audioDeviceManager.selectAudioDevice(device);
  }

  _onAudioDeviceChange(VIAudioDeviceManager audioDeviceManager, AudioDevice audioDevice) {
    // audio device is changed
  }

Changelog #

2.2.0 #

  • Update Android and iOS platform code to use Voximplant Android SDK 2.17.0 and Voximplant iOS SDK 2.31.0
  • Supporting the new Android plugins APIs based on FlutterPlugin
  • VIClient.conference method added
  • VIEndpoint.place value added
  • VIEndpoint.onEndpointRemoved callback added

2.1.2 #

  • Update iOS platform code to use Voximplant iOS SDK 2.30.0
  • Xcode 11.4 support added
  • VIVideoRenderer null handling improvements
  • VIClient bundleId won't be set to native SDK if it is null

2.1.1 #

  • VIVideoFlags incorrect initialisation fix

2.1.0 #

  • Update Android and iOS platform code to use Voximplant Android SDK 2.16.1 and Voximplant iOS SDK 2.29.0
  • Improve video rendering on iOS
  • VICameraManager.selectCamera is now available for iOS
  • Add VICall.getCallDuration API

2.0.0 #

  • Update iOS platform code to use Voximplant iOS SDK 2.26.0
  • Add 'VI' prefix to public API to avoid conflicts with other packages
  • Add video call functionality
  • Add camera management functionality
  • Improve multiple call management
  • Improve error descriptions for iOS
  • Public API will no longer throw PlatformException. All exceptions are now wrapped with VIException. Error codes for VIClient and VICall are described in VIClientError and VICallError classes.
  • Fix build issues in example project
  • Changed minimum Flutter SDK version to 1.10.0

1.2.0 #

  • Update Android and iOS platform code to use Voximplant Android SDK 2.15.0 and Voximplant iOS SDK 2.25.2
  • Native code refactoring

1.1.0 #

  • Add API for CallKit integration on iOS platform
  • Update Android and iOS platform code to use Voximplant Android SDK 2.14.1 and Voximplant iOS SDK 2.25.1

1.0.0 #

  • Audio call functionality

example/lib/main.dart

/// Copyright (c) 2011-2020, Zingaya, Inc. All rights reserved.

import 'package:audio_call/screens/call_screen.dart';
import 'package:audio_call/screens/incoming_call_screen.dart';
import 'package:audio_call/screens/login_screen.dart';
import 'package:audio_call/screens/main_screen.dart';
import 'package:audio_call/theme/voximplant_theme.dart';
import 'package:audio_call/utils/screen_arguments.dart';
import 'package:audio_call/services/navigation_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get_it/get_it.dart';

GetIt getIt = GetIt.instance;

void main() {
  setupLocator();
  runApp(MyApp());
}

void setupLocator() {
  getIt.registerLazySingleton(() => NavigationService());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
    return MaterialApp(
      title: 'Audio call',
      theme: ThemeData(
        primaryColor: VoximplantColors.primary,
        primaryColorDark: VoximplantColors.primaryDark,
        accentColor: VoximplantColors.accent,
      ),
      navigatorKey: getIt<NavigationService>().navigatorKey,
      onGenerateRoute: (settings) {
        if (settings.name == CallScreen.routeName) {
          final CallArguments args = settings.arguments;
          return MaterialPageRoute(
            builder: (context) {
              return CallScreen(
                call: args.call,
              );
            },
          );
        } else if (settings.name == IncomingCallScreen.routeName) {
          final CallArguments args = settings.arguments;
          return MaterialPageRoute(
            builder: (context) {
              return IncomingCallScreen(
                call: args.call
              );
            },
          );
        } else if (settings.name == MainScreen.routeName) {
          return MaterialPageRoute(
            builder: (context) {
              return MainScreen();
            }
          );
        } else {
          return MaterialPageRoute(
            builder: (context) {
              return LoginScreen();
            }
          );
        }
      },
      initialRoute: LoginScreen.routeName,
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_voximplant: ^2.2.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_voximplant/flutter_voximplant.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:flutter_voximplant/flutter_voximplant.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:flutter_voximplant/flutter_voximplant.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:flutter_voximplant/flutter_voximplant.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:flutter_voximplant/flutter_voximplant.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [flutter_voximplant] that is in a package requiring null.

Health suggestions

Format lib/src/call/call.dart.

Run flutter format to format lib/src/call/call.dart.

Format lib/src/call/video_stream.dart.

Run flutter format to format lib/src/call/video_stream.dart.

Format lib/src/call/video_view.dart.

Run flutter format to format lib/src/call/video_view.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/client/client.dart (Run flutter format to format lib/src/client/client.dart.)
  • lib/src/client/client_config.dart (Run flutter format to format lib/src/client/client_config.dart.)
  • lib/src/error_codes.dart (Run flutter format to format lib/src/error_codes.dart.)
  • lib/src/hardware/audio_device_manager.dart (Run flutter format to format lib/src/hardware/audio_device_manager.dart.)
  • lib/src/hardware/camera_manager.dart (Run flutter format to format lib/src/hardware/camera_manager.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
flutter_test