peer5 1.0.0+1

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

Pub Version

Peer5 Flutter #

Flutter plugin to integrate with the Peer5 native SDKs on Android and iOS.

Getting Started #

You will need some steps to install and configure this plugin properly.

Step 1: Obtain an API KEY #

Register at https://app.peer5.com/register and retrieve the CustomerID (aka API KEY) in the Account page.

Step 2: Install the plugin #

In your pubspec.yaml file, add the peer5 dependency. Read this page for more information and version number.

Don't forget to run pod install inside the ios/ directory.

Step 3: Configure iOS and Android #

On iOS #

Add your CustomerID and, in order to allow the loading of distributed content via the Peer5 proxy, enable loading data from HTTP in your app by opening your Info.plist file as source code and adding the following values below the </dict> tag:

<key>Peer5ApiKey</key>
<string>Your-CustomerID-Goes-Here</string>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

On Android

Add this metadata tag to your android/app/src/main/AndroidManifest.xml inside the <application> tag after all activities:

<meta-data
    android:name="com.peer5.ApiKey"
    android:value="__YOUR_PEER5_TOKEN__" />

Starting Android 9 HTTP traffic is disabled by default. read more about this change here.

Without allowing HTTP for 127.0.0.1 this error might show up when trying to play: "Cleartext HTTP traffic to 127.0.0.1 not permitted."

Create file in android/app/src/main/res/xml/network_security_config.xml with content:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">127.0.0.1</domain>
    </domain-config>
</network-security-config>

In android/app/src/main/AndroidManifest.xml add the android:networkSecurityConfig="@xml/network_security_config" attribute to the <application> tag:

<?xml version="1.0" encoding="utf-8"?>
<manifest>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:networkSecurityConfig="@xml/network_security_config">

    </application>
</manifest>

Step 4: Usage #

On iOS, you will need to initialize the local server by calling Peer5.init();. The instance should be bound to the application's lifetime and be initialized just once.

You can initialize anytime, but I recommend doing it at an early stage of the app initialization. In the initState() of the first widget, or even on the main() function (Just remember to add the WidgetsFlutterBinding.ensureInitialized(); in this case).

On Android, the Peer5 native SDK already starts the server for you. Calling Peer5.init(); on Android is safe and won't have any effect, so you don't need to add any conditional for it.

When initializing the VideoPlayerController instance, you will pass the proxied url that Peer5 will provide by calling Peer5.getStreamUrl(url) first.

final originalVideoUrl = 'http://cbsnewshd-lh.akamaihd.net/i/CBSNHD_7@199302/master.m3u8';
final proxiedUrl = await Peer5.getStreamUrl(originalVideoUrl);

// use the url passing through Peer5's local server
final videoController = VideoPlayerController.network(proxiedUrl);

Full example:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:peer5/peer5.dart';

void main() => runApp(MyApp());

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

class _MyAppState extends State<MyApp> {
  String _streamUrl;

  @override
  void initState() {
    super.initState();
    Peer5.init();
  }

  @override
  void dispose() {
    super.dispose();
  }

  Future<void> _getStreamUrl() async {
    _streamUrl = await Peer5.getStreamUrl(
        'http://cbsnewshd-lh.akamaihd.net/i/CBSNHD_7@199302/master.m3u8',
    );
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Video Player')),
        body: Container(
          padding: const EdgeInsets.all(10.0),
          height: 300.0,
          child: Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              RaisedButton(
                onPressed: _getStreamUrl,
                child: const Text('GET STREAM URL'),
                color: Theme.of(context).primaryColor,
                textColor: Colors.white,
                elevation: 30.0,
              ),
              Divider(),
              if (_streamUrl != null) Text(_streamUrl),
            ],
          ),
        ),
      ),
    );
  }
}

That’s all that’s needed for you to get started!

For more information, read the official documentation:

(iOS) https://docs.peer5.com/platforms/ios/

(Android) https://docs.peer5.com/platforms/android/

Contributing #

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License #

This project is licensed under the MIT License - see the LICENSE file for details

1.0.0+1 #

  • Improved pubspec.yaml parameters.

1.0.0 #

  • Implemented the Peer5.init() and Peer5.getStreamUrl() methods on both iOS and Android.

example/lib/main.dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:peer5/peer5.dart';
import 'package:peer5_example/video_player.dart';

void main() => runApp(MyApp());

/// Main example widget
class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _controller = TextEditingController(text: '');
  String _streamUrl;

  @override
  void initState() {
    super.initState();
    _initPeer5();
    _controller.addListener(_onTextChange);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.removeListener(_onTextChange);
    _controller.dispose();
  }

  void _onTextChange() {
    setState(() {});
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> _initPeer5() async {
    await Peer5.init();
    print('Peer5 initialized: ${Peer5.initialized}');
  }

  Future<void> _getStreamUrl() async {
    if (_controller.text.isNotEmpty) {
      _streamUrl = await Peer5.getStreamUrl(_controller.text);
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('Video Player')),
        body: Container(
          padding: const EdgeInsets.all(10.0),
          child: Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              Row(
                mainAxisSize: MainAxisSize.max,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: <Widget>[
                  Expanded(
                    child: TextField(
                      maxLines: 1,
                      autocorrect: false,
                      cursorWidth: 10.0,
                      keyboardType: TextInputType.url,
                      controller: _controller,
                      textInputAction: TextInputAction.go,
                      decoration: InputDecoration(labelText: 'Video URL'),
                    ),
                  ),
                  InkWell(
                    onTap: _controller.clear,
                    child: Ink(
                      padding: const EdgeInsets.all(6.0),
                      child: Icon(
                        Icons.delete_forever,
                        size: 25.0,
                        color: Theme.of(context).primaryColor,
                      ),
                    ),
                  ),
                ],
              ),
              RaisedButton(
                onPressed: _controller.text.isEmpty ? null : _getStreamUrl,
                child: const Text('PLAY VIDEO'),
                color: Theme.of(context).primaryColor,
                textColor: Colors.white,
                elevation: 30.0,
              ),
              Divider(),
              if (_streamUrl != null)
                Expanded(child: VideoPlayerDemo(url: _streamUrl)),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  peer5: ^1.0.0+1

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:peer5/peer5.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
45
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]
72
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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <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