webrtc_data_channel 0.1.0

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

Flutter WebRTC DataChannel plugin

This plugin allows Flutter apps to use WebRTC DataChannel to establish P2P connection and exchange text messages.

Install

Plugin dependency:

webrtc_data_channel: "^0.1.0"

WebRTC Android dependency:

rootProject.allprojects {
    repositories {
        maven {
            url  "https://google.bintray.com/webrtc"
        }
    }
}

dependencies {
    api 'org.webrtc:google-webrtc:1.0.22672'
}

WebRTC iOS dependency:

pod 'GoogleWebRTC', '1.1.22642'

Usage

import 'package:webrtc_data_channel/webrtc_data_channel.dart';

// create DataChannel and connect to room
WebRTCDataChannel _dataChannel = new WebRTCDataChannel();
_dataChannel.connect(_roomUrl, _roomId);

// listen for messages
_receivedMessages = _dataChannel.listenMessages()
        .listen((String message) {
            // handle message
        });

// send message
_dataChannel.sendMessage(message);

// disconnect from room
_dataChannel.disconnect();

Server setup

This plugin use webrtc/apprtc as room server and signal server, you can use https://appr.tc/ or deploy it yourself, I've a Docker image for it, piasy/apprtc-server.

Development setup

  • git clone https://github.com/Piasy/webrtc_data_channel
  • flutter create -t plugin webrtc_data_channel
  • cd webrtc_data_channel/example/ios && pod install

[0.1.0] - 2018.04.15

  • Initial release.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'chat_room.dart';

void main() {
  runApp(new MaterialApp(
    home: new HomePage(),
  ));
}

class HomePage extends StatefulWidget {
  @override
  HomePageState createState() {
    return new HomePageState();
  }
}

class HomePageState extends State<HomePage> {
  // https://appr.tc
  final TextEditingController _roomUrlController = new TextEditingController();
  final TextEditingController _roomIdController = new TextEditingController();

  BuildContext _scaffoldContext;

  _startChat(BuildContext context) {
    if (_roomUrlController.text.isNotEmpty &&
        _roomIdController.text.isNotEmpty) {
      Navigator.push(
          context,
          new MaterialPageRoute(
              builder: (context) => new ChatRoom(
                  _roomUrlController.text, _roomIdController.text)));
    } else {
      Scaffold.of(_scaffoldContext).showSnackBar(
          new SnackBar(content: new Text('Please set room url and id')));
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('WebRTC DataChannel Chat'),
      ),
      body: new Builder(builder: (BuildContext context) {
        _scaffoldContext = context;
        return new Column(
          children: [
            new Container(
              padding: new EdgeInsets.fromLTRB(30.0, 30.0, 30.0, 0.0),
              child: new TextField(
                autofocus: true,
                controller: _roomUrlController,
                decoration: new InputDecoration(hintText: 'Type room url'),
              ),
            ),
            new Container(
              padding: new EdgeInsets.all(30.0),
              child: new TextField(
                controller: _roomIdController,
                decoration: new InputDecoration(hintText: 'Type room id'),
              ),
            ),
            new RaisedButton(
              child: new Text('CHAT'),
              onPressed: () => _startChat(context),
            ),
          ],
        );
      }),
    );
  }
}

1. Depend on it

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


dependencies:
  webrtc_data_channel: "^0.1.0"

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:webrtc_data_channel/webrtc_data_channel.dart';
        
Version Uploaded Documentation Archive
0.1.0 Apr 16, 2018 Go to the documentation of webrtc_data_channel 0.1.0 Download webrtc_data_channel 0.1.0 archive

Analysis

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

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6
  • Flutter: 0.3.2

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
0 / 100
Health:
Code health derived from static analysis. [more]
98 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
49
Learn more about scoring.

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Suggestions

  • Package is pre-v1 release.

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

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run flutter format to format lib/webrtc_data_channel.dart.

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.6 1.14.9
meta 1.1.2
sky_engine 0.0.99
typed_data 1.1.5
vector_math 2.0.6