wuji_rtc_engine 1.6.11 copy "wuji_rtc_engine: ^1.6.11" to clipboard
wuji_rtc_engine: ^1.6.11 copied to clipboard

A new flutter plugin project.

example/lib/main.dart

import 'dart:async';

import 'package:wuji_rtc_engine/rtc_engine.dart';
import 'package:wuji_rtc_engine/rtc_local_view.dart' as RtcLocalView;
import 'package:wuji_rtc_engine/rtc_remote_view.dart' as RtcRemoteView;
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

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

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

class _MyAppState extends State<MyApp> {
  bool _joined = false;
  int _remoteUid = null;
  bool _switch = false;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    await [Permission.camera, Permission.microphone, Permission.storage]
        .request();

    // var engine = await RtcEngine.create('d193f2093417435cbcfc41720269bad0');
    var engine = await RtcEngine.create('123');
    // engine.setParameters("{\"server_url_type\": 1000}");
    engine.setEventHandler(RtcEngineEventHandler(
        joinChannelSuccess: (String channel, int uid, int elapsed) {
          print('joinChannelSuccess ${channel} ${uid}');
          setState(() {
            _joined = true;
          });
        }, userJoined: (int uid, int elapsed) {
      print('userJoined ${uid}');
      setState(() {
        _remoteUid = uid;
      });
    }, userOffline: (int uid, UserOfflineReason reason) {
      print('userOffline ${uid}');
      setState(() {
        _remoteUid = null;
      });
    },
        error: (ErrorCode errorCode){
          print('error ${errorCode}');
        }));
    await engine.enableVideo();
    // await engine.joinChannel('006d193f2093417435cbcfc41720269bad0IADVGhWETcjAdojvYUFPFlVE+hQmhItEuY4EMRkwLNY13dJjSIgAAAAAEAAWal0mnjTHXwEAAQCfNMdf', '123', null, 0);
    await engine.joinChannel(null, 'wuji_test', null, 0);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Stack(
          children: [
            Center(
              child: _switch ? _renderRemoteVideo() : _renderLocalPreview(),
            ),
            Align(
              alignment: Alignment.topLeft,
              child: Container(
                width: 100,
                height: 100,
                color: Colors.blue,
                child: GestureDetector(
                  onTap: () {
                    setState(() {
                      _switch = !_switch;
                    });
                  },
                  child: Center(
                    child:
                    _switch ? _renderLocalPreview() : _renderRemoteVideo(),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _renderLocalPreview() {
    if (_joined) {
      return RtcLocalView.SurfaceView();
    } else {
      return Text(
        'Please join channel first',
        textAlign: TextAlign.center,
      );
    }
  }

  Widget _renderRemoteVideo() {
    if (_remoteUid != null) {
      return RtcRemoteView.SurfaceView(uid: _remoteUid);
    } else {
      return Text(
        'Please wait remote user join',
        textAlign: TextAlign.center,
      );
    }
  }
}
0
likes
25
pub points
0%
popularity

Publisher

unverified uploader

A new flutter plugin project.

Homepage
Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

flutter, json_annotation

More

Packages that depend on wuji_rtc_engine