flutter_vonage_opentok 1.1.1 copy "flutter_vonage_opentok: ^1.1.1" to clipboard
flutter_vonage_opentok: ^1.1.1 copied to clipboard

outdated

Flutter plugin for Vonage OpenTok SDK

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_vonage_opentok/flutter_vonage_opentok.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Publisher? publisher;
  List<IoDevice> _devices = [];
  final _vonageOpentokPlugin = VonageOpentok();

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

    WidgetsBinding.instance.addPostFrameCallback((_) async {
      final session = _vonageOpentokPlugin.initSession(
        '',
        '',
      );

      await startSession(session);

      await initPublisher(session);
    });
  }

  Future<void> initPublisher(VideoSession session) async {
    try {
      final publisher = await _vonageOpentokPlugin.initPublisher();

      setState(() {
        this.publisher = publisher;
      });

      await session.publish(publisher);

      await _getDevices(publisher);
    } catch (e) {
      debugPrint(e.toString());
    }
  }

  Future<void> startSession(VideoSession session) async {
    await Future.delayed(const Duration(seconds: 2));

    const token = '';

    try {
      debugPrint('starting');
      await session.connect(token);
    } catch (e) {
      debugPrint(e.toString());
      session.connect(token);
    }
  }

  Future<void> _getDevices(Publisher publisher) async {
    final devices = await publisher.getIoDevices();

    setState(() {
      _devices = devices;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Stack(
          children: [
            PlatformDivElement(
              elementKey: VonageOpentok.subscriberVideoElement,
              afterCreate: () {},
            ),
            Positioned(
              bottom: 16,
              right: 16,
              child: Container(
                height: 200,
                width: 200,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(8),
                  border: Border.all(
                    color: Colors.grey,
                  ),
                ),
                child: PlatformDivElement(
                  elementKey: VonageOpentok.publisherVideoElement,
                  afterCreate: () {},
                ),
              ),
            ),
            if (_devices.isNotEmpty)
              Positioned(
                bottom: 16,
                left: 16 + 200,
                child: Card(
                  child: Column(
                    children: [
                      DropdownButton<IoDevice>(
                        items: _devices
                            .map(
                              (e) => DropdownMenuItem(
                                value: e,
                                child: Text(e.label),
                              ),
                            )
                            .toList(),
                        onChanged: (device) async {
                          if (device == null) {
                            return;
                          }

                          return switch (device.type) {
                            (IoDeviceType.audioInput) => publisher!.setAudioInputDevice(device.id),
                            (IoDeviceType.audioOutput) => publisher!.setAudioOutputDevice(device.id),
                            (IoDeviceType.videoInput) => publisher!.setVideoInputDevice(device.id),
                          };
                        },
                      ),
                    ],
                  ),
                ),
              ),
          ],
        ),
      ),
    );
  }
}
1
likes
0
points
152
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin for Vonage OpenTok SDK

License

unknown (license)

Dependencies

collection, flutter, flutter_web_plugins, js, plugin_platform_interface

More

Packages that depend on flutter_vonage_opentok

Packages that implement flutter_vonage_opentok