meta_rtc_engine 2.4.2 meta_rtc_engine: ^2.4.2 copied to clipboard
Meta sdk update v2.4.0.2.
import 'dart:async';
import 'package:meta_rtc_engine/rtc_engine.dart';
import 'package:meta_rtc_engine/rtc_local_view.dart' as RtcLocalView;
import 'package:meta_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('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(null, 'meta_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,
);
}
}
}