Flutter SDK for building a realtime broadcaster using the Millicast platform

Overview

Millicast SDK for Flutter

Flutter SDK for building a realtime broadcaster using the Millicast platform. This Software Development Kit (SDK) for Flutter allows developers to simplify Millicast services integration into their own Android and iOS apps.

Table of Contents

Installation

To add the Millicast Flutter SDK to your dependencies, run:

flutter pub add millicast_flutter_sdk

Then run the following command to download the dependencies:

flutter pub get

With this you will have then access to all the features provided by the SDK to use in your project.

When creating your own app, follow these steps: Add flutter_webrtc as a dependency in your pubspec.yaml file.

You will need a Millicast account and a valid publishing token that you can find it in your dashboard (link here).

iOS

Add the following entry to your Info.plist file, located in /ios/Runner/Info.plist:

<key>NSCameraUsageDescriptionkey>
<string>$(PRODUCT_NAME) Camera Usage!string>
<key>NSMicrophoneUsageDescriptionkey>
<string>$(PRODUCT_NAME) Microphone Usage!string>

This entry allows your app to access the camera and microphone.

Android

Ensure the following permission is present in your Android Manifest file, located in /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" />

If you need to use a Bluetooth device, add:

">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

The Flutter project template adds it, so it may already be there. You will also need to set your build settings to Java 8, because the 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
    }
}

If necessary, in the same build.gradle you will need to increase minSdkVersion of defaultConfig up to 21 (currently default Flutter generator set it to 16).

Basic Usage

This is a simple Minimum V P of our project to show the publish or subscribing features. You will need to put the following three code snippets in the respective main.dart, publisher.dart and viewer.dart files, and set your Millicast streaming credentials where needed in order to test it.

Main app

import 'publisher.dart';
import 'viewer.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:flutter/material.dart';

const type = String.fromEnvironment('type');
void main() async {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Millicast SDK Demo',
      theme: ThemeData(
        primarySwatch: Colors.purple,
      ),
      home: const MyHomePage(title: 'Millicast SDK Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final RTCVideoRenderer _localRenderer = RTCVideoRenderer();
  @override
  void dispose() {
    _localRenderer.dispose();
    super.dispose();
  }

  @override
  void initState() {
    initRenderers();
    // Run application with --dart-define type flag like:
    // flutter run --dart-define=type="subscribe||publish"
    // To choose wether you want to publishe or subscribe.
    switch (type) {
      case 'subscribe':
        subscribeExample();
        break;
      case 'publish':
        publishExample();
        break;
      default:
        publishExample();
    }
    super.initState();
  }

  void publishExample() async {
    await publishConnect(_localRenderer);
    setState(() {});
  }

  void subscribeExample() async {
    await viewConnect(_localRenderer);
    setState(() {});
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: OrientationBuilder(
        builder: (context, orientation) {
          return RotatedBox(
              quarterTurns: 1,
              child: Center(
                child: Container(
                  margin: const 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, mirror: true),
                  decoration: const BoxDecoration(color: Colors.black54),
                ),
              ));
        },
      ),
    );
  }
}

Publisher app

import 'dart:io';
import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:millicast_flutter_sdk/millicast_flutter_sdk.dart';

Future publishConnect(RTCVideoRenderer localRenderer) async {
  // Setting subscriber options
  DirectorPublisherOptions directorPublisherOptions = DirectorPublisherOptions(
      token: 'my-publishing-token', streamName: 'my-stream-name');

  /// Define callback for generate new token
  tokenGenerator() => Director.getPublisher(directorPublisherOptions);

  /// Create a new instance
  Publish publish =
      Publish(streamName: 'my-streamname', tokenGenerator: tokenGenerator);

  final Map<String, dynamic> constraints = <String, bool>{
    'audio': true,
    'video': true
  };

  MediaStream stream = await navigator.mediaDevices.getUserMedia(constraints);
  localRenderer.srcObject = stream;

  //Publishing Options
  Map<String, dynamic> broadcastOptions = {'mediaStream': stream};
  //Some Android devices do not support h264 codec for publishing
  if (Platform.isAndroid) {
    broadcastOptions['codec'] = 'vp8';
  }

  /// Start connection to publisher
  try {
    await publish.connect(options: broadcastOptions);
    return publish.webRTCPeer;
  } catch (e) {
    throw Exception(e);
  }
}

Viewer app

import 'package:flutter_webrtc/flutter_webrtc.dart';
import 'package:millicast_flutter_sdk/millicast_flutter_sdk.dart';

Future viewConnect(RTCVideoRenderer localRenderer) async {
  // Setting subscriber options
  DirectorSubscriberOptions directorSubscriberOptions =
      DirectorSubscriberOptions(
          streamAccountId: 'my-account-id', streamName: 'my-stream-name');

  /// Define callback for generate new token
  tokenGenerator() => Director.getSubscriber(directorSubscriberOptions);

  /// Create a new instance
  View view = View(
      streamName: 'my-stream-name',
      tokenGenerator: tokenGenerator,
      mediaElement: localRenderer);

  /// Start connection to publisher
  try {
    await view.connect();
    return view.webRTCPeer;
  } catch (e) {
    rethrow;
  }
}

Run the application

Set type environment variable publish or subscribe to decide wether you want to run the publisher or viewer app.

flutter run --dart-define=type='publish'

Important reminder

When you compile the release apk, you need to add the following operations: Setup Proguard Rules

API Reference

You can find the latest, most up to date SDK documentation at our API Reference page. There are more examples with every module available.

Sample

Example can be found in example folder.

SDK developer information

To develop and contribute to this project, there are some instructions on how to set up your environment to start contributing. Follow this link.

License

Please refer to LICENSE file.

Comments
  • Importing Flutter SDK Error: Expected identifier.

    Importing Flutter SDK Error: Expected identifier.

    I've been tinkering around with the flutter SDK for Millicast and I'm running into an expected identifier issue when I try to import the millicastFlutterSDK: image download

    which seems to be an issue in the peer_connection.dart line 303: download

    I'm developing on Windows w/Vs Code, Flutter: 3.0.1. Let me know if this is a local issue or related to the SDK.

    Thanks, Braden.

    opened by Briggs599 2
  • Support for Linux

    Support for Linux

    Hello,

    Any plans (or target date) on when this library would support Flutter Desktop and Linux specifically? That would be tremendous for the work we are doing.

    Regards, Ziad Proto

    opened by zafana1 2
  • Cannot add milicast-flutter-sdk

    Cannot add milicast-flutter-sdk

    After i used command -flutter pub add millicast-flutter-sdk

    I got an error which is -Because kandack depends on millicast-flutter-sdk any which doesn't exist (could not find package millicast-flutter-sdk at https://pub.dartlang.org), version solving failed.

    Screenshot at Apr 13 14-54-11

    @goddino @Jerricho93 @ftejeria @fcancela

    opened by aiman97adzhar 1
  • Pub dev warning fixes for 1.1.0

    Pub dev warning fixes for 1.1.0

    Type of change

    Please delete options that are not relevant.

    • [x] Bug fix (non-breaking change which fixes an issue)

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by fcancela 0
  • Release 1.1.0

    Release 1.1.0

    Type of change

    Please delete options that are not relevant.

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by fcancela 0
  • Upgrade dependencies.

    Upgrade dependencies.

    Fix deprecated methods. Format code. Run analyzer. Remove uni_links dependency. Now App won't be opened with a viewer link.

    Type of change

    • [x] Update dependencies
    • [x] Remove unused dependency

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by fcancela 0
  • addRemoteTrack: Remove complete pendingTransceivers.

    addRemoteTrack: Remove complete pendingTransceivers.

    Fix MediaStreamTrack when adding both remote audio/video tracks to the same stream.

    Type of change

    Please delete options that are not relevant.

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by fcancela 0
  • Feature/testing

    Feature/testing

    Type of change

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by Santiago-Souto 0
  • Feature/tests GitHub action

    Feature/tests GitHub action

    Type of change

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by fcancela 0
  • Create tests.yml

    Create tests.yml

    Type of change

    Please delete options that are not relevant.

    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by fcancela 0
  • Release 1.0.0

    Release 1.0.0

    Type of change

    Please delete options that are not relevant.

    • [x] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)

    New Feature Submissions:

    • [x] Does your submission pass tests?
    • [x] Have you lint your code locally prior to submission?

    Checklist:

    • [x] I have performed a self-review of my own code
    • [x] I have commented my code, particularly in hard-to-understand areas
    • [x] I have made corresponding changes to the documentation
    • [x] I have added tests that prove my fix is effective or that my feature works
    • [x] New and existing tests pass locally with my changes
    • [x] I have verified the pub score with my changes
    opened by fcancela 0
  • fix: Update millicast_flutter_sdk.podspec

    fix: Update millicast_flutter_sdk.podspec

    Updates the WebRTC SDK version to match with the latest flutter_webrtc package.

    Please delete options that are not relevant.

    • [X] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)

    New Feature Submissions:

    • [X] Does your submission pass tests?
    • [X] Have you lint your code locally prior to submission?

    Checklist:

    • [X] I have performed a self-review of my own code
    • [X] I have commented my code, particularly in hard-to-understand areas
    • [X] I have made corresponding changes to the documentation
    • [X] I have added tests that prove my fix is effective or that my feature works
    • [X] New and existing tests pass locally with my changes
    • [X] I have verified the pub score with my changes
    opened by Akshar-Patel 0
Releases(1.1.0)
  • 1.1.0(Sep 21, 2022)

    1.1.0

    Added

    • flutter_webrtc version upgraded to 0.9.7 (Uses WebRTC release m104).

    Changed

    • Now example app asks for all the permission required during startup.
    • Updated all dependencies to latest versions.
    • Updated min iOS min version 10 to 11.

    Removed

    • Removed uni_links dependency from example app.
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jun 20, 2022)

    What's Changed

    • Flutter version3.x.x && version2.x.x support by @ftejeria in https://github.com/millicast/flutter-sdk/pull/22
    • Fixed misrepresentation of viewer count. by @olbapbetan in https://github.com/millicast/flutter-sdk/pull/23
    • Feature/fix add remote track by @ftejeria in https://github.com/millicast/flutter-sdk/pull/25
    • Pre release by @fcancela in https://github.com/millicast/flutter-sdk/pull/26
    • Create tests.yml by @fcancela in https://github.com/millicast/flutter-sdk/pull/28
    • Feature/tests GitHub action by @fcancela in https://github.com/millicast/flutter-sdk/pull/29
    • Feature/testing by @Santiago-Souto in https://github.com/millicast/flutter-sdk/pull/30
    • addRemoteTrack: Remove complete pendingTransceivers. by @fcancela in https://github.com/millicast/flutter-sdk/pull/31
    • Release 1.0.0 by @fcancela in https://github.com/millicast/flutter-sdk/pull/27

    New Contributors

    • @olbapbetan made their first contribution in https://github.com/millicast/flutter-sdk/pull/23
    • @Santiago-Souto made their first contribution in https://github.com/millicast/flutter-sdk/pull/30

    Full Changelog: https://github.com/millicast/flutter-sdk/compare/0.2.2...1.0.0

    Source code(tar.gz)
    Source code(zip)
  • 0.2.2(May 9, 2022)

    What's Changed

    • Hotfix/remove unused dependencies by @fcancela in https://github.com/millicast/flutter-sdk/pull/19
    • Hotfix/remove unused dependencies (#19) by @fcancela in https://github.com/millicast/flutter-sdk/pull/20

    Full Changelog: https://github.com/millicast/flutter-sdk/compare/0.2.1...0.2.2

    Source code(tar.gz)
    Source code(zip)
  • 0.2.1(May 9, 2022)

    First official release of the Millicast Flutter SDK!

    What's Changed

    • SDK package can now be downloaded directly from pub.dev package repository.
    • EA-Mirror-iOS-Camera: invert mirrored flag for iOS by @fcancela in https://github.com/millicast/flutter-sdk/pull/15
    • Bugfix/h264 support by @fcancela in https://github.com/millicast/flutter-sdk/pull/16
    • h264-support: solved codec fallback codec issue. by @fcancela in https://github.com/millicast/flutter-sdk/pull/17

    Full Changelog: https://github.com/millicast/flutter-sdk/compare/0.2.0...0.2.1

    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Apr 22, 2022)

    Changelog

    Added

    • Added support for latest version of viewercount.

    Changed

    • Removed support for legacy version of viewercount.
    • Updated README API Reference hyperlink to the proper url.

    Fixed

    • Fixed viewercount issues for EA.
    • Fixed EA iOS bug where audio could not be heard on the subscriber side.
    • Fixed bug where websockets were not being properly closed both for publisher/viewer.
    • Fixed reenabling unlimited bitrate for the SDK.
    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Apr 11, 2022)

    This is the first beta test release of the Millicast Flutter SDK.

    For SDK usage instructions, please refer to the SDK README.md. An Example App (EA) at flutter-sdk/example has been provided to illustrate the basic usage of the SDK. Usage of the EA is documented at its own readme at flutter-sdk/example/README.md.

    There are some known issues as indicated below that are currently being worked on.

    Known issues:

    • H264 publish on Android is device dependent.
      • Possible workaround includes publishing with other codecs, such as VP8, VP9.
    • The EA has some minor issues:
      • On iOS, the first publish might be missing audio.
        • Possible workaround is to exit, reenter Publisher view, and publish again.
      • Viewer count might not work correctly in some scenarios.
      • Subscription occasionally does not terminate after leaving Subscriber view.
        • Possible workaround is to restart EA.

    Full Changelog: https://github.com/millicast/flutter-sdk/commits/0.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
Millicast, Inc.
Realtime CDN
Millicast, Inc.
News App created in Flutter using News API for fetching realtime data and Firebase as the backend and authenticator.

News Buzz News App created in Flutter using News API for fetching realtime data and Firebase as the backend and authenticator. Features Custom news fe

Ankur Kedia 545 Dec 30, 2022
Fully functional Twitter clone built in flutter framework using Firebase realtime database and storage

Fwitter - Twitter clone in flutter A working Twitter clone written in Flutter using Firebase auth,realtime,firestore database and storage. Download Ap

Sonu Sharma 2.4k Jan 8, 2023
:rocket: This application using flutter for develop a realtime chat app

Flutter Chat Socket Description: ?? This application using Flutter for develop a realtime chat app How I can run it? ?? Clone this repository ?? Run b

Dao Hong Vinh 17 Dec 31, 2022
A Flutter plugin for Yandex AppMetrica SDK, a marketing platform for app install attribution, app analytics, and push campaigns.

appmetrica_sdk A Flutter plugin for Yandex AppMetrica SDK. Plugin implementation status Implemented Events Profiles Not implemented yet Revenue. Comin

EM ALL iT Studio 15 Oct 21, 2021
Realtime Chat with Flutter

What is Konnect? Konnect is a messaging app for simple private communication with friends. Say "hello" to a different messaging experience. An unexpec

Yunus Emre Alpu 7 Dec 13, 2022
Realtime Fleet Management

FLEET Realtime Fleet Management Warning These apps were built for demo purposes only. Features Mobile app that sends live location via websockets. Mob

Morteza 3 Nov 30, 2022
A dart client for Supabase Realtime server.

realtime-dart Listens to changes in a PostgreSQL Database and via websockets. A dart client for Supabase Realtime server. Usage Creating a Socket conn

Supabase Community 76 Dec 14, 2022
Weather-App-Api- - Simple Realtime Weather App With Api

music_app A new Flutter Weather App project. Getting Started // اول حاجه تعمل en

Youssif El Sayed 5 Nov 11, 2022
Ready for Building Production-Ready Healthcare/ Doctor Consult Android and iOS app UI using Flutter.

Production-Ready Doctor Consultant App - Flutter UI Packages we are using: flutter_svg: link In this full series, we will show you how to Building Pro

Anurag Jain 26 Nov 28, 2022
building a timer application using the bloc library

flutter_timer A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if

Simon Wambua 0 Nov 4, 2021
Stream Feed official Flutter SDK. Build your own feed experience using Dart and Flutter.

Official Flutter packages for Stream Activity Feeds The official Dart client for Stream Activity Feeds, a service for building activity feed applicati

Stream 67 Sep 26, 2022
Pensil Community official Flutter SDK. Build your own community experience using Dart and Flutter.

Official flutter package for Pensil The official Dart client for Pensil communities, a service for building communites applications. This library can

Pensil Inc 6 Oct 6, 2022
P2P payment solution using Stream's Flutter SDK and Rapyd's Wallet API

Peer-to-peer payment integration to a messaging app using Flutter ?? This project shows how to integrate a peer-to-peer payment solution to your Strea

Souvik Biswas 15 Dec 8, 2022
Official plugin for using Thepeer SDK with flutter https://thepeer.co

Flutter Thepeer This package makes it easy to use the Thepeer in a flutter project. ?? Screen Shots ?? How to Use plugin ThePeer Send Launch ThepeerSe

The Peer 23 Dec 27, 2022
A simple chat app UI using flutter SDK project.

Chatty App A simple chat app UI using flutter SDK project. Screenshot Getting Started This project is a starting point for a Flutter application. A fe

Tengku Belmiro 5 Jul 15, 2022
A Social App Built Using FLutter SDK.

Hi ?? , I'm Faheem ??‍?? A Social App Built Using FLutter SDK. The main objective of this application is to provide a single platform for the Students

Faheem Ahmad 26 Nov 10, 2022
Sample app to demonstrate the integration and working of Dyte SDK for mobile, using Flutter.

Flutter Sample App by dyte Sample App to demonstrate Dyte SDK in flutter Explore the docs » View Demo · Report Bug · Request Feature Table of Contents

Dyte 12 Jan 1, 2023
Official plugin for using Thepeer SDK with flutter https://thepeer.co

Flutter Thepeer This package makes it easy to use the Thepeer in a flutter project. ?? Screen Shots ?? How to Use plugin Adding MaterialSupport Add th

Thepeer 23 Dec 27, 2022
A guideline for building scalable Flutter applications.

Scalable flutter app You probably need to read this article before inspecting the repo's code. Building scalable Flutter apps (Architecture, Styling,

Nour El-Din Shobier 36 Nov 23, 2022