flutter_webrtc 0.1.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

Flutter-WebRTC #

pub package [![Join the chat at https://gitter.im/flutter-webrtc/Lobby](https://badges.gitter.im/flutter-webrtc/Lobby.svg)](https://gitter.im/flutter-webrtc/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Flutter WebRTC plugin for iOS/Android

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 `

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

Functionality #

We intend to implement support the following features:

Example #

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

/**
 * getUserMedia sample
 */
class GetUserMediaSample extends StatefulWidget {
  static String tag = 'get_usermedia_sample';

  @override
  _GetUserMediaSampleState createState() => new _GetUserMediaSampleState();
}

class _GetUserMediaSampleState extends State<GetUserMediaSample> {
  MediaStream _localStream;
  final _localRenderer = new RTCVideoRenderer();
  bool _inCalling = false;

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

  @override
  deactivate() {
    super.deactivate();
    if (_inCalling) {
      _hangUp();
    }
  }

  initRenderers() async {
    await _localRenderer.initialize();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  _makeCall() async {
    final Map<String, dynamic> mediaConstraints = {
      "audio": true,
      "video": {
        "mandatory": {
          "minWidth":'640', // Provide your own width, height and frame rate here
          "minHeight": '480',
          "minFrameRate": '30',
        },
        "facingMode": "user",
        "optional": [],
      }
    };

    try {
      var stream = await navigator.getUserMedia(mediaConstraints);
      _localStream = stream;
      _localRenderer.srcObject = _localStream;
    } catch (e) {
      print(e.toString());
    }
    if (!mounted) return;

    setState(() {
      _inCalling = true;
    });
  }

  _hangUp() async {
    try {
      await _localStream.dispose();
      _localRenderer.srcObject = null;
    } catch (e) {
      print(e.toString());
    }
    setState(() {
      _inCalling = false;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('GetUserMedia API Test'),
      ),
      body: new OrientationBuilder(
        builder: (context, orientation) {
          return new Center(
            child: new Container(
              margin: new EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height,
              child: RTCVideoView(_localRenderer),
              decoration: new BoxDecoration(color: Colors.black54),
            ),
          );
        },
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _inCalling ? _hangUp : _makeCall,
        tooltip: _inCalling ? 'Hangup' : 'Call',
        child: new Icon(_inCalling ? Icons.call_end : Icons.phone),
      ),
    );
  }
}

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

Changelog #


[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/README.md

webrtc_example #

Demonstrates how to use the webrtc plugin.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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


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

We analyzed this package on Oct 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/rtc_data_channel.dart. (-1.99 points)

Analysis of lib/rtc_data_channel.dart reported 4 hints:

line 2 col 8: Unused import: 'dart:convert'.

line 6 col 8: Unused import: 'dart:io'.

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

line 93 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 324 col 38: Don't explicitly initialize variables to null.

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

Fix lib/get_user_media.dart. (-0.50 points)

Analysis of lib/get_user_media.dart reported 1 hint:

line 6 col 7: Name types using UpperCamelCase.

Fix additional 9 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/media_recorder.dart (Run flutter format to format lib/media_recorder.dart.)
  • lib/media_stream.dart (Run flutter format to format lib/media_stream.dart.)
  • lib/media_stream_track.dart (Run flutter format to format lib/media_stream_track.dart.)
  • lib/rtc_dtmf_sender.dart (Run flutter format to format lib/rtc_dtmf_sender.dart.)
  • lib/rtc_ice_candidate.dart (Run flutter format to format lib/rtc_ice_candidate.dart.)
  • lib/rtc_peerconnection_factory.dart (Run flutter format to format lib/rtc_peerconnection_factory.dart.)
  • lib/rtc_session_description.dart (Run flutter format to format lib/rtc_session_description.dart.)
  • lib/rtc_stats_report.dart (Run flutter format to format lib/rtc_stats_report.dart.)
  • lib/utils.dart (Run flutter format to format lib/utils.dart.)

Maintenance suggestions

The package description is too short. (-20 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.35.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8