flutter_webrtc 0.2.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

Flutter-WebRTC #

Financial Contributors on Open Collective pub package Gitter

WebRTC plugin for Flutter Mobile/Desktop/Web

Functionality #

FeatureAndroidiOSWebmacOSWindowsLinuxFuchsia
Audio/Video✔️✔️✔️✔️[WIP][WIP]
Data Channel✔️✔️✔️✔️[WIP][WIP]
Screen Capture✔️✔️✔️
Unified-Plan
MediaRecorder⚠️⚠️✔️

Usage #

Add flutter_webrtc 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>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) Camera Usage!</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) Microphone Usage!</string>

This entry allows your app to access camera and microphone.

Android #

Ensure the following permission is present in your Android Manifest file, located in <project root>/android/app/src/main/AndroidManifest.xml:

<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

The Flutter project template adds it, so it may already be there.

Also you will need to set your build settings to Java 8, because official WebRTC jar now uses static methods in EglBase interface. Just add this to your app level build.gradle:

android {
    //...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Contributing #

The project is inseparable from the contributors of the community.

Example #

For more examples, please refer to flutter-webrtc-demo.

Contributors #

Code Contributors #

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors #

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

Changelog #


[0.2.7] - 2020.03.15

  • [macOS] Fix crash with H264 HW Encoder.
  • [Web] Add addTransceiver API.
  • [Android] Removed duplicate method that was causing compilation error.
  • [iOS] Use MrAlek Libyuv pod fixing incompatibility with FirebaseFirestore.
  • [iOS] Upgrade GoogleWebRTC dependency to 1.1.29400.

[0.2.6] - 2020.02.03

  • Fixed the interruption of the Bluetooth headset that was playing music after the plugin started.

[0.2.4] - 2020.02.03

  • Fixed bug.

[0.2.3] - 2020.02.03

  • Fixed bug for enableSpeakerphone (Android/iOS).
  • Fix RtcVideoView not rebuild when setState called and renderer is changed.
  • Fix Android frame orientation.

[0.2.2] - 2019.12.13

  • Removed the soft link of WebRTC.framework to fix compile errors of macos version when third-party flutter app depends on plugins

[0.2.1] - 2019.12.12

  • Code format.
  • Remove unused files.

[0.2.0] - 2019.12.12

  • Add support for macOS (channel dev).
  • Add support for Flutter Web (channel dev).
  • Add hasTorch support for Android (Camera2 API) and iOS.
  • Fix(PeerConnections) split dispose and close
  • Add microphone mute support for Android/iOS.
  • Add enable speakerphone support for Android/iOS.
  • Fix 'createIceServer' method Invalid value error (Android).
  • Store SignalingState/IceGatheringState/IceConnectionState in RTCPeerConnection.
  • Fixed rendering issues caused by remote MediaStream using the same msid/label when using multiple PeerConntions.

[0.1.7] - 2019.05.16

  • Add RTCDataChannelMessage for data channel and remove base64 type.
  • Add streaming API for datachannel messages and state changes.
  • Remove cloudwebrtc prefix in the plugin method/event channel name.
  • Other bug fixes.

[0.1.6] - 2019.03.31

  • Add getConfiguration/setConfiguration methods for Peerconnection.
  • Add object fit for RTCVideoView.

[0.1.5] - 2019.03.27

  • Remove unnecessary parameter for getLocalDescription method.

[0.1.4] - 2019.03.26

  • switchCamera method now returns future with isFrontCamera as result
  • Fix camera stuck in rare cases
  • Add getLocalDescription/getRemoteDescription methods

[0.1.3] - 2019.03.25

  • Add horizontal flip (mirror) function for RTCVideoView.
  • Fixed ScreenCapture preview aspect ratio for Android.

[0.1.2] - 2019.03.24

  • Fix compilation failure caused by invalid code.

[0.1.1] - 2019.03.24

  • Migrated to AndroidX using Refactoring from Andoid Studio
  • Fix mediaStreamTrackSetEnable not working.
  • Fix iOS can't render video when resolution changes.
  • Some code style changes.

[0.1.0] - 2019.01.21

  • Fix camera switch issues.
  • Support data channel, please use the latest demo to test.
  • Support screen sharing, but the work is not perfect, there is a problem with the local preview.

[0.0.3] - 2018.12.20

  • Update WebRTC to 1.0.25821.
  • Implemented MediaStreamTrack.setVolume().
  • Add public getter for texture id.
  • Fixed getUserMedia does not work for capturing audio only.

[0.0.2] - 2018.11.04

  • Add 'enabled' method for MediaStreamTrack.
  • Implement switch camera.
  • Add arm64-v8a and x86_64 architecture support for android.

[0.0.1] - 2018.05.30

  • Initial release.

example/lib/main.dart

import 'dart:core';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'
    show debugDefaultTargetPlatformOverride;
import 'package:flutter_webrtc/webrtc.dart';

import 'src/loopback_sample.dart';
import 'src/get_user_media_sample.dart'
    if (dart.library.js) 'src/get_user_media_sample_web.dart';
import 'src/get_display_media_sample.dart';
import 'src/data_channel_sample.dart';
import 'src/route_item.dart';

void main() {
  if (WebRTC.platformIsDesktop)
    debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
  runApp(new MyApp());
}

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

class _MyAppState extends State<MyApp> {
  List<RouteItem> items;

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

  _buildRow(context, item) {
    return ListBody(children: <Widget>[
      ListTile(
        title: Text(item.title),
        onTap: () => item.push(context),
        trailing: Icon(Icons.arrow_right),
      ),
      Divider()
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Flutter-WebRTC example'),
          ),
          body: new ListView.builder(
              shrinkWrap: true,
              padding: const EdgeInsets.all(0.0),
              itemCount: items.length,
              itemBuilder: (context, i) {
                return _buildRow(context, items[i]);
              })),
    );
  }

  _initItems() {
    items = <RouteItem>[
      RouteItem(
          title: 'GetUserMedia',
          push: (BuildContext context) {
            Navigator.push(
                context,
                new MaterialPageRoute(
                    builder: (BuildContext context) =>
                        new GetUserMediaSample()));
          }),
      RouteItem(
          title: 'GetDisplayMedia',
          push: (BuildContext context) {
            Navigator.push(
                context,
                new MaterialPageRoute(
                    builder: (BuildContext context) =>
                        new GetDisplayMediaSample()));
          }),
      RouteItem(
          title: 'LoopBack Sample',
          push: (BuildContext context) {
            Navigator.push(
                context,
                new MaterialPageRoute(
                    builder: (BuildContext context) => new LoopBackSample()));
          }),
      RouteItem(
          title: 'DataChannel',
          push: (BuildContext context) {
            Navigator.push(
                context,
                new MaterialPageRoute(
                    builder: (BuildContext context) =>
                        new DataChannelSample()));
          }),
    ];
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_webrtc: ^0.2.7

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_webrtc/enums.dart';
import 'package:flutter_webrtc/get_user_media.dart';
import 'package:flutter_webrtc/media_recorder.dart';
import 'package:flutter_webrtc/media_stream.dart';
import 'package:flutter_webrtc/media_stream_track.dart';
import 'package:flutter_webrtc/rtc_data_channel.dart';
import 'package:flutter_webrtc/rtc_dtmf_sender.dart';
import 'package:flutter_webrtc/rtc_ice_candidate.dart';
import 'package:flutter_webrtc/rtc_peerconnection.dart';
import 'package:flutter_webrtc/rtc_peerconnection_factory.dart';
import 'package:flutter_webrtc/rtc_session_description.dart';
import 'package:flutter_webrtc/rtc_stats_report.dart';
import 'package:flutter_webrtc/rtc_video_view.dart';
import 'package:flutter_webrtc/utils.dart';
import 'package:flutter_webrtc/web/get_user_media.dart';
import 'package:flutter_webrtc/web/media_recorder.dart';
import 'package:flutter_webrtc/web/media_stream.dart';
import 'package:flutter_webrtc/web/media_stream_track.dart';
import 'package:flutter_webrtc/web/rtc_data_channel.dart';
import 'package:flutter_webrtc/web/rtc_ice_candidate.dart';
import 'package:flutter_webrtc/web/rtc_peerconnection.dart';
import 'package:flutter_webrtc/web/rtc_peerconnection_factory.dart';
import 'package:flutter_webrtc/web/rtc_session_description.dart';
import 'package:flutter_webrtc/web/rtc_video_view.dart';
import 'package:flutter_webrtc/web/utils.dart';
import 'package:flutter_webrtc/webrtc.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
93
Health:
Code health derived from static analysis. [more]
94
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
93
Learn more about scoring.

We analyzed this package on Mar 31, 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/rtc_data_channel.dart. (-1 points)

Analysis of lib/rtc_data_channel.dart reported 2 hints:

line 12 col 7: The declaration '_messageTypeToTypeString' isn't referenced.

line 80 col 10: The value of the field '_label' isn't used.

Fix lib/rtc_peerconnection.dart. (-1 points)

Analysis of lib/rtc_peerconnection.dart reported 2 hints:

line 314 col 39: Don't explicitly initialize variables to null.

line 346 col 35: The value of the local variable 'response' isn't used.

Fix lib/web/rtc_data_channel.dart. (-1 points)

Analysis of lib/web/rtc_data_channel.dart reported 2 hints:

line 8 col 7: The declaration '_typeStringToMessageType' isn't referenced.

line 13 col 7: The declaration '_messageTypeToTypeString' isn't referenced.

Fix additional 5 files with analysis or formatting issues. (-3.50 points)

Additional issues in the following files:

  • lib/web/rtc_peerconnection.dart (2 hints)
  • lib/web/rtc_video_view.dart (2 hints)
  • lib/get_user_media.dart (1 hint)
  • lib/rtc_video_view.dart (1 hint)
  • lib/web/get_user_media.dart (1 hint)

Maintenance suggestions

The package description is too short. (-10 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.2.2 <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