8000 fixup! Fixes [Issue #409](https://github.com/flutter-webrtc/flutter-w… · admarwick/flutter-webrtc@cd471c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd471c0

Browse files
author
Alan Marwick
committed
fixup! Fixes [Issue flutter-webrtc#409](flutter-webrtc#409), and updates the example to run on Android 10.
1 parent 8feecf9 commit cd471c0

File tree

1 file changed

+128
-0
lines changed

1 file changed

+128
-0
lines changed

example/lib/main.dart

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import 'dart:core';
2+
import 'dart:io';
3+
4+
import 'package:flutter/foundation.dart'
5+
show debugDefaultTargetPlatformOverride;
6+
import 'package:flutter/material.dart';
7+
import 'package:flutter_foreground_plugin/flutter_foreground_plugin.dart';
8+
import 'package:flutter_webrtc/flutter_webrtc.dart';
9+
10+
import 'src/data_channel_sample.dart';
11+
import 'src/get_display_media_sample.dart';
12+
import 'src/get_user_media_sample.dart'
13+
if (dart.library.html) 'src/get_user_media_sample_web.dart';
14+
import 'src/loopback_sample.dart';
15+
import 'src/route_item.dart';
16+
17+
void main() {
18+
if (WebRTC.platformIsDesktop) {
19+
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
20+
} else if(Platform.isAndroid) {
21+
WidgetsFlutterBinding.ensureInitialized();
22+
startForegroundService();
23+
}
24+
runApp(MyApp());
25+
}
26+
27+
startForegroundService() async {
28+
await FlutterForegroundPlugin.setServiceMethodInterval(seconds: 5);
29+
await FlutterForegroundPlugin.setServiceMethod(globalForegroundService);
30+
await FlutterForegroundPlugin.startForegroundService(
31+
holdWakeLock: false,
32+
onStarted: () {
33+
print("Foreground on Started");
34+
},
35+
onStopped: () {
36+
print("Foreground on Stopped");
37+
},
38+
title: "Tcamera",
39+
content: "Tcamera sharing your screen.",
40+
iconName: "ic_stat_mobile_screen_share",
41+
);
42+
return true;
43+
}
44+
45+
void globalForegroundService() {
46+
debugPrint("current datetime is ${DateTime.now()}");
47+
}
48+
49+
class MyApp extends StatefulWidget {
50+
@override
51+
_MyAppState createState() => _MyAppState();
52+
}
53+
54+
class _MyAppState extends State<MyApp> {
55+
List<RouteItem> items;
56+
57+
@override
58+
void initState() {
59+
super.initState();
60+
_initItems();
61+
}
62+
63+
ListBody _buildRow(context, item) {
64+
return ListBody(children: <Widget>[
65+
ListTile(
66+
title: Text(item.title),
67+
onTap: () => item.push(context),
68+
trailing: Icon(Icons.arrow_right),
69+
),
70+
Divider()
71+
]);
72+
}
73+
74+
@override
75+
Widget build(BuildContext context) {
76+
return MaterialApp(
77+
home: Scaffold(
78+
appBar: AppBar(
79+
title: Text('Flutter-WebRTC example'),
80+
),
81+
body: ListView.builder(
82+
shrinkWrap: true,
83+
padding: const EdgeInsets.all(0.0),
84+
itemCount: items.length,
85+
itemBuilder: (context, i) {
86+
return _buildRow(context, items[i]);
87+
})),
88+
);
89+
}
90+
91+
void _initItems() {
92+
items = <RouteItem>[
93+
RouteItem(
94+
title: 'GetUserMedia',
95+
push: (BuildContext context) {
96+
Navigator.push(
97+
context,
98+
MaterialPageRoute(
99+
builder: (BuildContext context) => GetUserMediaSample()));
100+
}),
101+
RouteItem(
102+
title: 'GetDisplayMedia',
103+
push: (BuildContext context) {
104+
Navigator.push(
105+
context,
106+
MaterialPageRoute(
107+
builder: (BuildContext context) =>
108+
GetDisplayMediaSample()));
109+
}),
110+
RouteItem(
111+
title: 'LoopBack Sample',
112+
push: (BuildContext context) {
113+
Navigator.push(
114+
context,
115+
MaterialPageRoute(
116+
builder: (BuildContext context) => LoopBackSample()));
117+
}),
118+
RouteItem(
119+
title: 'DataChannel 64A8 ',
120+
push: (BuildContext context) {
121+
Navigator.push(
122+
context,
123+
MaterialPageRoute(
124+
builder: (BuildContext context) => DataChannelSample()));
125+
}),
126+
];
127+
}
128+
}

0 commit comments

Comments
 (0)
0