flutter_webrtc 0.0.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 83

Flutter-WebRTC

pub package 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 `<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.

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 {
      navigator.getUserMedia(mediaConstraints).then((stream){
        _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.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.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages 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_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';
  
Version Uploaded Documentation Archive
0.0.2 Nov 4, 2018 Go to the documentation of flutter_webrtc 0.0.2 Download flutter_webrtc 0.0.2 archive
0.0.1 Sep 11, 2018 Go to the documentation of flutter_webrtc 0.0.1 Download flutter_webrtc 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
80
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Nov 4, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0-dev.7.1.flutter-b99bcfd309
  • pana: 0.12.5
  • Flutter: 0.10.1

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

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

Analysis of lib/rtc_video_view.dart reported 3 hints:

line 22 col 8: The value of the field '_mirror' isn't used.

line 24 col 25: The value of the field '_objectFit' isn't used.

line 26 col 31: The value of the field '_eventSubscription' isn't used.

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

Analysis of lib/rtc_data_channel.dart reported 2 hints:

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

line 64 col 16: The value of the local variable 'type' 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 8 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/rtc_peerconnection.dart (1 hint)
  • lib/media_stream.dart (Run flutter format to format lib/media_stream.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 description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

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
meta 1.1.6
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8