pano_rtc 0.9.2-dev.3 copy "pano_rtc: ^0.9.2-dev.3" to clipboard
pano_rtc: ^0.9.2-dev.3 copied to clipboard

outdated

Flutter plugin for PanoRtc SDK.

example/lib/main.dart

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

import 'package:pano_rtc/pano_rtc.dart';
import 'package:permission_handler/permission_handler.dart';

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

///Please refer to Glossary to understand the meaning of App ID, Channel ID, Token, User ID, and User Name:
///请参考 名词解释 了解 App ID、Channel ID、Token、User ID、User Name 的含义:
///https://developer.pano.video/getting-started/terms/
///You can use temporary token for temporary testing:
///可以使用 临时token 来进行临时测试:https://developer.pano.video/getting-started/firstapp/#14-%E7%94%9F%E6%88%90%E4%B8%B4%E6%97%B6token
var appId = "";
var token = "";
var rtcServer = "api.pano.video";
var channelId = "RoomId";
var userId = 12345;

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

class _MyAppState extends State<MyApp> {
  RtcEngineKit _engine;
  RtcSurfaceViewModel _largeViewModel;
  RtcSurfaceViewModel _smallViewModel;
  bool _loading = false;
  String _text = "Join Channel";

  @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();
    assert(appId.isNotEmpty, 'appId should not be empty');
    assert(token.isNotEmpty, 'token should not be empty');
    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.startAudio();
            _engine.startVideo(_smallViewModel);
          });
        }
      },
      onChannelLeaveIndication: (ResultCode result) {
        print('onChannelLeaveIndication result $result');
      },
      onUserAudioStart: (int userId) {
        print('onUserAudioStart userId $userId');
        _engine.subscribeAudio(userId);
      },
      onUserVideoStart: (int userId, VideoProfileType maxProfile) {
        print('onUserVideoStart userId $userId');
        print('onUserVideoStart maxProfile $maxProfile');
        RtcRenderConfig config = RtcRenderConfig(profileType: maxProfile);
        _engine.subscribeVideo(userId, _largeViewModel, config: config);
      },
      onActiveSpeakerListUpdated: (List<dynamic> userIds) {
        print('onActiveSpeakerListUpdated userIds $userIds');
      },
      onFirstVideoFrameRendered: (int userId) {
        print('onFirstVideoFrameRendered userIds $userId');
      },
      onFirstVideoDataReceived: (int userId) {
        print('onFirstVideoDataReceived userIds $userId');
      },
      onVideoCaptureStateChanged: (String deviceId, VideoCaptureState state) {
        print('onVideoCaptureStateChanged deviceId $deviceId');
        print('onVideoCaptureStateChanged state $state');
      },
      onWhiteboardAvailable: () {
        print('onWhiteboardAvailable');
      },
      onWhiteboardUnavailable: () {
        print('onWhiteboardUnavailable');
      },
      onUserJoinIndication: (int userId, String userName) {
        print('onUserJoinIndication userId $userId');
        print('onUserJoinIndication userName $userName');
      },
      onUserVideoUnmute: (int userId) {
        print('onUserVideoUnmute userId $userId');
      },
      onChannelCountDown: (int remain) {
        print('onChannelCountDown remain $remain');
      },
      onAudioStartResult: (ResultCode result) {
        print('onAudioStartResult result $result');
      },
      onVideoStartResult: (ResultCode result) {
        print('onVideoStartResult result $result');
      },
      onUserLeaveIndication: (int userId, UserLeaveReason reason) {
        print('onUserLeaveIndication userId $userId');
        print('onUserLeaveIndication reason $reason');
      },
      onUserAudioStop: (int userId) {
        print('onUserAudioStop userId $userId');
      },
      onUserAudioSubscribe: (int userId, SubscribeResult result) {
        print('onUserAudioSubscribe userId $userId');
        print('onUserAudioSubscribe result $result');
      },
      onUserVideoStop: (int userId) {
        print('onUserVideoStop userId $userId');
      },
      onUserVideoSubscribe: (int userId, SubscribeResult result) {
        print('onUserVideoSubscribe userId $userId');
        print('onUserVideoSubscribe result $result');
      },
      onUserAudioMute: (int userId) {
        print('onUserVideoSubscribe userId $userId');
      },
      onUserAudioUnmute: (int userId) {
        print('onUserAudioUnmute userId $userId');
      },
      onUserVideoMute: (int userId) {
        print('onUserVideoMute userId $userId');
      },
      onUserScreenStart: (int userId) {
        print('onUserScreenStart userId $userId');
      },
      onUserScreenStop: (int userId) {
        print('onUserScreenStop userId $userId');
      },
      onUserScreenSubscribe: (int userId, SubscribeResult result) {
        print('onUserScreenSubscribe userId $userId');
        print('onUserScreenSubscribe result $result');
      },
      onUserScreenMute: (int userId) {
        print('onUserScreenMute userId $userId');
      },
      onUserScreenUnmute: (int userId) {
        print('onUserScreenUnmute userId $userId');
      },
      onWhiteboardStart: () {
        print('onWhiteboardStart');
      },
      onWhiteboardStop: () {
        print('onWhiteboardStop');
      },
      onWhiteboardStartWithId: (String whiteboardId) {
        print('onWhiteboardStartWithId whiteboardId$whiteboardId');
      },
      onWhiteboardStopWithId: (String whiteboardId) {
        print('onWhiteboardStartWithId whiteboardId$whiteboardId');
      },
      onFirstAudioDataReceived: (int userId) {
        print('onFirstAudioDataReceived userId $userId');
      },
      onFirstScreenDataReceived: (int userId) {
        print('onFirstScreenDataReceived userId $userId');
      },
      onFirstScreenFrameRendered: (int userId) {
        print('onFirstScreenFrameRendered userId $userId');
      },
      onAudioDeviceStateChanged: (String deviceId, AudioDeviceType deviceType,
          AudioDeviceState deviceState) {
        print('onAudioDeviceStateChanged deviceId $deviceId');
        print('onAudioDeviceStateChanged deviceType $deviceType');
        print('onAudioDeviceStateChanged deviceState$deviceState');
      },
      onAudioDefaultDeviceChanged:
          (String deviceId, AudioDeviceType deviceType) {
        print('onAudioDefaultDeviceChanged deviceId $deviceId');
        print('onAudioDefaultDeviceChanged deviceType $deviceType');
      },
      onVideoDeviceStateChanged: (String deviceId, VideoDeviceType deviceType,
          VideoDeviceState deviceState) {
        print('onVideoDeviceStateChanged deviceId $deviceId');
        print('onVideoDeviceStateChanged deviceType $deviceType');
        print('onVideoDeviceStateChanged deviceState$deviceState');
      },
      onChannelFailover: (FailoverState state) {
        print('onChannelFailover state $state');
      },
      onAudioMixingStateChanged: (int taskId, AudioMixingState state) {
        print('onAudioMixingStateChanged taskId $taskId');
        print('onAudioMixingStateChanged state $state');
      },
      onVideoSnapshotCompleted: (bool succeed, int userId, String fileName) {
        print('onVideoSnapshotCompleted succeed $succeed');
        print('onVideoSnapshotCompleted userId $userId');
        print('onVideoSnapshotCompleted fileName $fileName');
      },
      onNetworkQuality: (int userIds, QualityRating quality) {
        print('onNetworkQuality userIds $userIds');
        print('onNetworkQuality quality $quality');
      },
      onScreenStartResult: (ResultCode result) {
        print('onScreenStartResult result $result');
      },
      onUserAudioLevel: (RtcAudioLevel level) {
        print('onUserAudioLevel level $level');
      },
      onVideoSendStats: (RtcVideoSendStats stats) {
        print('onVideoSendStats stats $stats');
      },
      onVideoRecvStats: (RtcVideoRecvStats stats) {
        print('onVideoRecvStats stats $stats');
      },
      onAudioSendStats: (RtcAudioSendStats stats) {
        print('onAudioSendStats stats $stats');
      },
      onAudioRecvStats: (RtcAudioRecvStats stats) {
        print('onAudioRecvStats stats $stats');
      },
      onScreenSendStats: (RtcVideoSendStats stats) {
        print('onScreenSendStats stats $stats');
      },
      onScreenRecvStats: (RtcVideoRecvStats stats) {
        print('onScreenRecvStats stats $stats');
      },
      onVideoSendBweStats: (RtcVideoSendBweStats stats) {
        print('onVideoSendBweStats stats $stats');
      },
      onVideoRecvBweStats: (RtcVideoRecvBweStats stats) {
        print('onVideoRecvBweStats stats $stats');
      },
      onSystemStats: (RtcSystemStats stats) {
        print('onSystemStats stats $stats');
      },
    ));

  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Stack(
          children: [
            Center(
              child: RtcSurfaceView(onViewCreated: ((viewModel) {
                setState(() {
                  _largeViewModel = viewModel;
                });
              })),
            ),
            Positioned(
              top: 0,
              child: RtcSurfaceView(onViewCreated: ((viewModel) {
                setState(() {
                  _smallViewModel = viewModel;
                });
              })),
              width: 100,
              height: 150,
            ),
            Align(
              alignment: Alignment.center,
              child: RaisedButton(
                  child: Text(_text),
                  onPressed: _loading
                      ? null
                      : () async {
                          setState(() {
                            _loading = true;
                            _text = "正在加入...";
                          });
                          _engine.joinChannel(token, channelId, userId);
                          setState(() {
                            _loading = false;
                          });
                        }),
            ),
          ],
        ),
      ),
    );
  }
}
1
likes
0
points
73
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