enx_flutter_plugin 2.2.5 enx_flutter_plugin: ^2.2.5 copied to clipboard
EnableX Flutter Plugin allows developers to implement real-time communication channels such as audio, video, and text chat in their applications on iOS and Android Platforms.
import 'dart:convert';
import 'package:enx_flutter_plugin/enx_flutter_plugin.dart';
import 'package:enx_flutter_plugin_example/video_call.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'package:fluttertoast/fluttertoast.dart';
import 'VideoConferenceScreen.dart';
void main() {
runApp(MaterialApp(
title: "Sample App",
debugShowCheckedModeBanner: false,
theme: ThemeData(
brightness: Brightness.light,
primaryColor: Colors.deepPurple,
accentColor: Colors.pinkAccent),
home: MyApp(),
routes: <String, WidgetBuilder>{
'/Conference': (context) => MyConfApp(
token: _State.token,
)
},
));
}
class MyApp extends StatefulWidget {
@override
_State createState() => _State();
}
class _State extends State<MyApp> {
//Your webservice host URL, Keet the defined host when kTry = true
static final String kBaseURL = "https://meeting-demo-qa.enablex.io/";
// To try the app with Enablex hosted service you need to set the kTry = true
static bool kTry = false;
//Use enablec portal to create your app and get these following credentials
//Use enablec portal to create your app and get these following credentials
static final String kAppId = "App-ID";
static final String kAppkey = "App-Key";
var header = (kTry)
? {
"x-app-id": kAppId,
"x-app-key": kAppkey,
"Content-Type": "application/json"
}
: {"Content-Type": "application/json"};
TextEditingController nameController = TextEditingController();
TextEditingController roomIdController = TextEditingController();
static String token = "";
String role = '', roomID = '';
Future<void> createRoomvalidations() async {
if (nameController.text.isEmpty) {
isValidated = false;
Fluttertoast.showToast(
msg: "Please Enter your name",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
} else {
isValidated = true;
}
}
Future<void> joinRoomValidations() async {
// await _handleCameraAndMic();
if (nameController.text.isEmpty) {
Fluttertoast.showToast(
msg: "Please Enter your name",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
isValidated = false;
} else if (roomIdController.text.isEmpty) {
Fluttertoast.showToast(
msg: "Please Enter your roomId",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0);
isValidated = false;
} else {
isValidated = true;
}
}
Future<String> createRoom() async {
var response = await http.post(
Uri.parse(
kBaseURL + "createRoom"), // replace FQDN with Your Server API URL
headers: header);
print('sckasas');
print(response);
if (response.statusCode == 200) {
Map<String, dynamic> user = jsonDecode(response.body);
Map<String, dynamic> room = user['room'];
setState(() => roomIdController.text = room['room_id'].toString());
print(response.body);
return response.body;
} else {
throw Exception('Failed to load post');
}
}
Future<String> getPin() async {
var response = await http.post(
Uri.parse(
kBaseURL + 'getRoomByPin'), // replace FQDN with Your Server API URL
headers: {"Content-Type": "application/json"},
body: jsonEncode({"pin": roomIdController.text}));
print('sckasas');
print(response.body);
if (response.statusCode == 200) {
Map<String, dynamic> user = jsonDecode(response.body);
// Map<String, dynamic> room = user['room'];
setState(() {
roomID = user['room_id'].toString();
role = user['role'].toString();
createToken();
});
print(response.body);
return response.body;
} else {
throw Exception('Failed to load post');
}
}
Future<String> createToken() async {
var value = {
'user_ref': "2236",
"roomId": roomID,
"role": "audience",
"name": nameController.text
};
print(jsonEncode(value));
var response = await http.post(
Uri.parse(
kBaseURL + "createToken"), // replace FQDN with Your Server API URL
headers: header,
body: jsonEncode(value));
print(kBaseURL);
if (response.statusCode == 200) {
print(response.body);
Map<String, dynamic> user = jsonDecode(response.body);
setState(() => token = user['token'].toString());
print('apptoken${token}');
if (token != 'null' && token.isNotEmpty) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoConferenceScreen(
token: token,
)),
);
// Navigator.pushNamed(context, '/Conference');
return response.body;
}
} else {
throw Exception('Failed to load post');
}
}
TextStyle style = TextStyle(fontFamily: 'Montserrat', fontSize: 16.0);
bool isValidated = false;
bool isPrecallTest = true;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
final usernameField = TextField(
obscureText: false,
style: style,
controller: nameController,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Username",
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
);
final roomIdField = TextField(
obscureText: false,
controller: roomIdController,
style: style,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
hintText: "Enter pin",
border:
OutlineInputBorder(borderRadius: BorderRadius.circular(32.0))),
);
final createRoomButon = Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Colors.deepPurple,
child: MaterialButton(
// minWidth: MediaQuery.of(context).size.width / 2,
minWidth: 100,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
createRoomvalidations();
if (isValidated) {
createRoom();
}
},
child: Text("Create Room",
textAlign: TextAlign.center,
style: style.copyWith(
color: Colors.white, fontWeight: FontWeight.normal)),
),
);
final joinButon = Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Colors.deepPurple,
child: MaterialButton(
minWidth: 100,
// minWidth: MediaQuery.of(context).size.width / 2,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
print('sdckjcs');
joinRoomValidations();
if (isValidated) {
print('ityroriyori');
getPin();
// createRoom();
}
},
child: Text("Join",
textAlign: TextAlign.center,
style: style.copyWith(
color: Colors.white, fontWeight: FontWeight.normal)),
),
);
final precallTestButon = Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(30.0),
color: Colors.deepPurple,
child: MaterialButton(
minWidth: 100,
// minWidth: MediaQuery.of(context).size.width / 2,
padding: EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
onPressed: () {
if (isPrecallTest)
isPrecallTest = false;
else
isPrecallTest = true;
Map<String, dynamic> map = {
'testDurationDataThroughput': 2,
'testDurationVideoBandwidth': 30,
'testDurationAudioBandwidth': 30,
'stop': isPrecallTest,
'regionId': ['IN'],
'testNames': ['microphone'],
};
print(map);
EnxRtc.clientDiagnostics(map);
// _addEnxrtcEventHandlers();
},
child: Text("Precall Test",
textAlign: TextAlign.center,
style: style.copyWith(
color: Colors.white, fontWeight: FontWeight.normal)),
),
);
return Scaffold(
appBar: AppBar(
title: Text('Sample App'),
),
body: Padding(
padding: EdgeInsets.all(10),
child: ListView(
children: <Widget>[
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(10),
child: Text(
'Enablex',
style: TextStyle(
color: Colors.redAccent,
fontWeight: FontWeight.w500,
fontSize: 30),
)),
Container(
alignment: Alignment.center,
padding: EdgeInsets.all(10),
child: Text(
'Welcome !',
style: TextStyle(fontSize: 20),
)),
Container(
padding: EdgeInsets.all(10),
child: usernameField,
),
Container(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: roomIdField),
Container(
alignment: Alignment.center,
height: 100,
width: 100,
child: Row(
children: <Widget>[
Expanded(
flex: 1,
child: Padding(
padding: EdgeInsets.all(10),
child: createRoomButon)),
Expanded(
flex: 1,
child: Padding(
padding: EdgeInsets.all(10), child: joinButon)),
Expanded(
flex: 1,
child: Padding(
padding: EdgeInsets.all(10),
child: precallTestButon)),
],
))
],
)));
}
void initEnxRtc() {
// EnxRtc.enxRtc();
}
}
/*void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
// initPlatformState();
// initZappingPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
static Future<void> initPlatformState({@required int isVivo}) async {
const uRL_VIDEO = "";
final Video video = Video();
video.titulo = "titulo";
video.descripcion = "descripcion";
video.imagenPath =
"https://170.79.102.232:8443/img/channels/logo_1587071125.png?w=500&h=500";
video.numeroCanal = 1;
video.vivo = isVivo;
video.studio = 1381;
video.linkReproductor = uRL_VIDEO;
try {
await HlsPlayer.initializeZapping(
canales: [video],
playVideoAtIndex: 0,
isSearchingItem: true,
urlEPG:
r"http://170.79.102.232:18080/30h_c51b182583a9d4a8_$5da43c0fb7fbd7b0c7d3/STUDIO.json")
.then((onValue) {
print(onValue);
Timer.periodic(Duration(seconds: 5), (Timer t) => initGetVideoLink());
}).catchError((onError) {
print(onError);
});
} on PlatformException {}
}
static Future<void> initZappingPlatformState() async {
const uRL_VIDEO =
"https://meeting-demo-qa.enablex.io/join/YXVkaWVuY2UtNjI4MjI3ODc0NzEyMDA1ZjMwNmNjN2ExLTU0MzIx";
const uRL_VIDEO2 = "http://mdstrm.com/video/5a29c07e5522e40a45beb669.m3u8";
const uRL_VIDEO3 =
"http://unlimited1-cl.dps.live/campustv/campustv.smil/playlist.m3u8";
final Video video = Video();
video.titulo = "titulo";
video.descripcion = "descripcion";
video.imagenPath =
"https://170.79.102.232:8443/img/channels/logo_1587071125.png?w=500&h=500";
video.numeroCanal = 1;
video.vivo = 0;
video.studio = 1381;
video.linkReproductor = uRL_VIDEO;
final Video video2 = Video();
video2.titulo = "titulo";
video2.descripcion = "descripcion";
video2.imagenPath =
"https://170.79.102.232:8443/img/channels/logo_1567784648.png?w=500&h=500";
video2.numeroCanal = 2;
video2.vivo = 1;
video2.studio = 1382;
video2.linkReproductor = uRL_VIDEO2;
final Video video3 = Video();
video3.titulo = "titulo";
video3.descripcion = "descripcion";
video3.imagenPath =
"https://170.79.102.232:8443/img/channels/logo_1565631656.png?w=500&h=500";
video3.numeroCanal = 3;
video3.vivo = 1;
video3.studio = 1383;
video3.linkReproductor = uRL_VIDEO3;
final canales = [video];
try {
await HlsPlayer.initializeZapping(
canales: canales,
playVideoAtIndex: 2,
isSearchingItem: false,
urlEPG:
r"http://170.79.102.232:18080/30h_c51b182583a9d4a8_$5da43c0fb7fbd7b0c7d3/STUDIO.json")
.then((onValue) {
print(onValue);
Timer.periodic(Duration(seconds: 5), (Timer t) => initGetVideoLink());
}).catchError((onError) {
print(onError);
});
} on PlatformException {}
}
static Future<void> initGetVideoLink() async {
try {
await HlsPlayer.getVideoLink().then((onValue) {
print(onValue);
}).catchError((onError) {
print(onError);
});
} on PlatformException {}
}
Widget testWidget = new MediaQuery(
data: new MediaQueryData(),
child: new MaterialApp(
home: Scaffold(
body: Column(
children: <Widget>[
ElevatedButton(
child: Text(
'Buscar video',
style: TextStyle(fontSize: 18.0),
),
onPressed: () {
initPlatformState(isVivo: 0);
},
),
ElevatedButton(
child: Text(
'Buscar Streaming',
style: TextStyle(fontSize: 18.0),
),
onPressed: () {
initPlatformState(isVivo: 1);
},
),
ElevatedButton(
child: Text(
'play zapping',
style: TextStyle(fontSize: 18.0),
),
onPressed: () {
initZappingPlatformState();
},
),
],
)),
),
);
@override
Widget build(BuildContext context) {
return testWidget;
}
}*/