pano_rtc 0.9.0-dev.1 copy "pano_rtc: ^0.9.0-dev.1" to clipboard
pano_rtc: ^0.9.0-dev.1 copied to clipboard

outdated

Flutter plugin for PanoRtc SDK.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';
import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:pano_rtc/pano_rtc.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:json_annotation/json_annotation.dart';

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

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

class _MyAppState extends State<MyApp> {
  RtcEngineKit _engine;
  RtcSurfaceViewModel _playViewModel;
  bool _loading = false;
  String _text = "";

  @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 appId = "";
    var rtcServer = "";
    var config = RtcEngineConfig(appId, rtcServer);
    config.videoCodecHwAcceleration = true;
    _engine = await RtcEngineKit.engine(config);
    _engine.setEventHandler(
        RtcEngineEventHandler(onChannelJoinConfirm: (ResultCode result) {
      print('onChannelJoinConfirm ${result}');
      if (result == ResultCode.OK) {
        setState(() {
          _engine.startVideo(_playViewModel);
        });
      }
    }));

    // engine.joinChannel(token, channelId, userId)
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Stack(
          children: [
            Center(
              child: RtcSurfaceView(onViewCreated: onViewCreate),
            ),
            Align(
              alignment: Alignment.center,
              child: RaisedButton(
                  child: Text(_text),
                  onPressed: _loading
                      ? null
                      : () async {
                          setState(() {
                            _loading = true;
                            _text = "正在加入...";
                          });
                          try {
                            var appId = "";
                            //创建一个HttpClient
                            HttpClient httpClient = new HttpClient();
                            //打开Http连接
                            HttpClientRequest request =
                                await httpClient.postUrl(Uri.parse(""));

                            request.headers.contentType = ContentType.json;
                            request.headers.add("Cache-Control", "no-cache");

                            var channelId = "123456789000101010";
                            var userId = 233333;
                            var body = {
                              "appId": appId,
                              "channelId": channelId,
                              "userId": userId,
                            };
                            String payload = jsonEncode(body);
                            print(payload);
                            request.add(utf8.encode(payload));

                            //等待连接服务器(会将请求信息发送给服务器)
                            HttpClientResponse response = await request.close();
                            //读取响应内容
                            var token =
                                await response.transform(utf8.decoder).join();
                            //输出响应头
                            print(token);

                            //关闭client后,通过该client发起的所有请求都会中止。
                            httpClient.close();

                            _engine.joinChannel(token, channelId, userId);
                          } catch (e) {
                            _text = "加入失败:$e";
                          } finally {
                            setState(() {
                              _loading = false;
                            });
                          }
                        }),
            ),
          ],
        ),
      ),
    );
  }

  void onViewCreate(RtcSurfaceViewModel viewModel) async {
    setState(() {
      _playViewModel = viewModel;
    });
  }
}
1
likes
0
points
39
downloads

Publisher

verified publisherpano.video

Weekly Downloads

Flutter plugin for PanoRtc SDK.

Homepage

License

unknown (license)

Dependencies

flutter, json_annotation

More

Packages that depend on pano_rtc

Packages that implement pano_rtc