flutter_opentok 0.0.6

  • Readme
  • Changelog
  • Example
  • Installing
  • 81

flutter_opentok #

pub package

Flutter library for OpenTok iOS and Android SDKs.

Note: This plugin is still under development! Feedback and Pull Requests are most welcome!

Usage #

To use this plugin, add flutter_opentok as a dependency in your pubspec.yaml file.

Getting Started #

Check out the example directory for a sample app using OpenTok.

Development #

Generate the models and the factories: flutter packages pub run build_runner build --delete-conflicting-outputs

0.0.6 #

  • Fix app crash.

0.0.5 #

  • Add system logging.

0.0.4 #

  • Add debugging support.

0.0.3 #

  • Upgrade to Swift 4.2.

0.0.2 #

  • Fixes, fixes, fixes.

0.0.1 #

  • Initial Release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_opentok/flutter_opentok.dart';
import 'package:flutter_opentok_example/video_session.dart';
import 'package:flutter_opentok_example/settings.dart';

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

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

class _MyAppState extends State<MyApp> {
  static final _sessions = List<VideoSession>();
  final _infoStrings = <String>[];
  bool muted = false;
  bool publishVideo = true;
  OTFlutter controller;
  OpenTokConfiguration openTokConfiguration;

  @override
  void initState() {
    super.initState();
    initialize();
  }

  @override
  void dispose() {
    _sessions.clear();

    super.dispose();
  }

  void initialize() {
    if (API_KEY.isEmpty) {
      setState(() {
        _infoStrings.add(
            "APP_ID missing, please provide your API_KEY in settings.dart");
        _infoStrings.add("OpenTok is not starting");
      });
      return;
    }

    if (SESSION_ID.isEmpty) {
      setState(() {
        _infoStrings.add(
            "SESSION_ID missing, please provide your SESSION_ID in settings.dart");
        _infoStrings.add("OpenTok is not starting");
      });
      return;
    }

    if (TOKEN.isEmpty) {
      setState(() {
        _infoStrings
            .add("TOKEN missing, please provide your TOKEN in settings.dart");
        _infoStrings.add("OpenTok is not starting");
      });
      return;
    }

    openTokConfiguration = OpenTokConfiguration(
        token: TOKEN, apiKey: API_KEY, sessionId: SESSION_ID);

    _addRenderView(0, (viewId) {
      print(viewId);
    });
  }

  // Toolbar layout
  Widget _toolbar() {
    return Container(
        alignment: Alignment.bottomCenter,
        padding: const EdgeInsets.symmetric(vertical: 48.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RawMaterialButton(
              onPressed: () => _togglePublisherVideo(),
              child: Icon(
                publishVideo ? Icons.videocam : Icons.videocam_off,
                color: publishVideo ? Colors.white : Colors.blueAccent,
                size: 20.0,
              ),
              shape: CircleBorder(),
              elevation: 2.0,
              fillColor: muted ? Colors.blueAccent : Colors.white,
              padding: const EdgeInsets.all(12.0),
            ),
            RawMaterialButton(
              onPressed: () => _onToggleMute(),
              child: Icon(
                muted ? Icons.mic : Icons.mic_off,
                color: muted ? Colors.white : Colors.blueAccent,
                size: 20.0,
              ),
              shape: CircleBorder(),
              elevation: 2.0,
              fillColor: muted ? Colors.blueAccent : Colors.white,
              padding: const EdgeInsets.all(12.0),
            ),
            RawMaterialButton(
              onPressed: () => _onSwitchCamera(),
              child: Icon(
                Icons.switch_camera,
                color: Colors.blueAccent,
                size: 20.0,
              ),
              shape: CircleBorder(),
              elevation: 2.0,
              fillColor: Colors.white,
              padding: const EdgeInsets.all(12.0),
            )
          ],
        ));
  }

  /// Helper function to get list of native views
  List<Widget> _getRenderViews() {
    return _sessions.map((session) => session.view).toList();
  }

  /// Video view wrapper
  Widget _videoView(view) {
    return Expanded(child: Container(child: view));
  }

  Widget _viewRows() {
    List<Widget> views = _getRenderViews();
    switch (views.length) {
      case 1:
        return Container(
            child: Column(
          children: <Widget>[_videoView(views[0])],
        ));
      default:
    }

    return Container();
  }

  /// Info panel to show logs
  Widget _panel() {
    return Container(
        padding: EdgeInsets.symmetric(vertical: 48),
        alignment: Alignment.bottomCenter,
        child: FractionallySizedBox(
          heightFactor: 0.5,
          child: Container(
              padding: EdgeInsets.symmetric(vertical: 48),
              child: ListView.builder(
                  reverse: true,
                  itemCount: _infoStrings.length,
                  itemBuilder: (BuildContext context, int index) {
                    if (_infoStrings.length == 0) {
                      return null;
                    }
                    return Padding(
                        padding:
                            EdgeInsets.symmetric(vertical: 3, horizontal: 10),
                        child: Row(mainAxisSize: MainAxisSize.min, children: [
                          Flexible(
                              child: Container(
                                  padding: EdgeInsets.symmetric(
                                      vertical: 2, horizontal: 5),
                                  decoration: BoxDecoration(
                                      color: Colors.yellowAccent,
                                      borderRadius: BorderRadius.circular(5)),
                                  child: Text(_infoStrings[index],
                                      style:
                                          TextStyle(color: Colors.blueGrey))))
                        ]));
                  })),
        ));
  }

  /// Create a native view and add a new video session object
  void _addRenderView(int uid, Function(int viewId) finished) {
    OTFlutter.onSessionConnect = () {
      print("onSessionConnect");
    };

    OTFlutter.onSessionDisconnect = () {
      print("onSessionDisconnect");
    };

    var publisherSettings = OTPublisherKitSettings(
      name: "Mr. John Doe",
      audioTrack: true,
      videoTrack: publishVideo,
    );
    Widget view = OTFlutter.createNativeView(uid,
        publisherSettings: publisherSettings, created: (viewId) async {
      controller = await OTFlutter.init(viewId);

      await controller.create(openTokConfiguration);
    });

    VideoSession session = VideoSession(uid, view);
    _sessions.add(session);
  }

  void _togglePublisherVideo() async {
    if (publishVideo) {
      await controller?.disablePublisherVideo();
    } else {
      await controller?.enablePublisherVideo();
    }

    setState(() {
      publishVideo = !publishVideo;
    });
  }

  void _onToggleMute() async {
    if (muted) {
      await controller?.unmutePublisherAudio();
    } else {
      await controller?.mutePublisherAudio();
    }

    setState(() {
      muted = !muted;
    });
  }

  void _onSwitchCamera() async {
    await controller?.switchCamera();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('OpenTok SDK'),
          ),
          backgroundColor: Colors.black,
          body: Center(
              child: Stack(
            children: <Widget>[_viewRows(), _panel(), _toolbar()],
          ))),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_opentok: ^0.0.6

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

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because of import path [package:flutter_opentok/flutter_opentok.dart] that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because of import path [package:flutter_opentok/flutter_opentok.dart] that declares support for platforms: android, ios

Package does not support Flutter platform web

Because of import path [package:flutter_opentok/flutter_opentok.dart] that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because of import path [package:flutter_opentok/flutter_opentok.dart] that declares support for platforms: android, ios

Package not compatible with SDK dart

because of import path [flutter_opentok] that is in a package requiring null.

Health suggestions

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

Analysis of lib/flutter_opentok.dart reported 1 hint:

line 206 col 9: The value of the local variable 'values' isn't used.

Maintenance suggestions

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

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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
flutter 0.0.0
json_annotation ^3.0.0 3.0.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8
Dev dependencies
build_runner ^1.5.2
flutter_test
json_serializable ^3.2.0