webrtc 0.0.1 webrtc: ^0.0.1 copied to clipboard
p2p vedio
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:webrtc/webrtc.dart';
import 'webrtc_call.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
enum DialogDemoAction {
cancel,
connect,
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
String _serverAddress;
void showDemoDialog<T>({BuildContext context, Widget child}) {
showDialog<T>(
context: context,
builder: (BuildContext context) => child,
).then<void>((T value) {
// The value passed to Navigator.pop() or null.
if (value != null) {
if (value == DialogDemoAction.connect) {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
CallSample(ip: _serverAddress)));
}
}
});
}
_showAddressDialog(context) {
showDemoDialog<DialogDemoAction>(
context: context,
child: new AlertDialog(
title: const Text('Enter server address:'),
content: TextField(
onChanged: (String text) {
setState(() {
_serverAddress = text;
});
},
decoration: InputDecoration(
hintText: _serverAddress,
),
textAlign: TextAlign.center,
),
actions: <Widget>[
new FlatButton(
child: const Text('CANCEL'),
onPressed: () {
Navigator.pop(context, DialogDemoAction.cancel);
}),
new FlatButton(
child: const Text('CONNECT'),
onPressed: () {
Navigator.pop(context, DialogDemoAction.connect);
})
]));
}
@override
void initState() {
super.initState();
initPlatformState();
printLogs();
}
void printLogs() async {
print(await Webrtc.printLog(tag: "Karthik", msg: "This is Test Log")); // default logType
print(await Webrtc.printLog(tag: "Karthik", msg: "This is Test Log", logType: Log.WARNING)); // logType = warning
print(await Webrtc.printLog(tag: "Karthik", msg: "This is Test Log", logType: Log.ERROR)); // logType = error
print(await Webrtc.printLog(tag: "Karthik", msg: "This is Test Log", logType: Log.DEBUG)); // logType = debug
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await Webrtc.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: CallSample(ip: "demo.cloudwebrtc.com")
),
);
}
}