You are on page 1of 9

import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:jitsi_meet/jitsi_meet.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';

class JoinMeeting extends StatefulWidget {


const JoinMeeting({super.key});

@override
State<JoinMeeting> createState() => _JoinMeetingState();
}

class _JoinMeetingState extends State<JoinMeeting> {


final serverText = TextEditingController();
final roomText = TextEditingController(text: "");
final nameText = TextEditingController(text: "");
final emailText = TextEditingController(text: "User Email");
final iosAppBarRGBAColor =
TextEditingController(text: "#0080FF80"); //transparent blue
bool isAudioOnly = false;
bool isAudioMuted = true;
bool isVideoMuted = true;
late DateTime _starttime;
late DateTime _endtime;

@override
void initState() {
super.initState();
JitsiMeet.addListener(JitsiMeetingListener(
onConferenceWillJoin: _onConferenceWillJoin,
onConferenceJoined: _onConferenceJoined,
onConferenceTerminated: _onConferenceTerminated,
onError: _onError));
}

@override
void dispose() {
super.dispose();
JitsiMeet.removeAllListeners();
}
Future addmeetingdetails(String title, DateTime startdate, DateTime enddate) async
{
await FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection('Past Meetings')
.add({
'MeetingID': title,
'Start Date/Time': startdate,
'End Date/Time': enddate,

});
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF0C1D36),
elevation: 0,
leading: IconButton(
onPressed: () => Get.back(),
icon: const Icon(
Icons.arrow_back_sharp,
color: Colors.white,
),
),
centerTitle: true,
title: Text(
'Join Meeting',
style: TextStyle(
color: Colors.white,
),
),
),
body: Container(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: kIsWeb
? Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: width * 0.30,
child: meetConfig(),
),
Container(
width: width * 0.60,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
color: Colors.white54,
child: SizedBox(
width: width * 0.60 * 0.70,
height: width * 0.60 * 0.70,
child: JitsiMeetConferencing(
extraJS: [
// extraJs setup example
'<script>function echo(){console.log("echo!!!")};</script>',
'<script src="https://code.jquery.com/jquery-3.5.1.slim.js"
integrity="sha256-DrT5NfxfbHvMHux31Lkhxg42LY6of8TaYyK50jnxRnM="
crossorigin="anonymous"></script>'
],
),
)),
))
],
)
: meetConfig(),
),
),
);
}

Widget meetConfig() {
return SingleChildScrollView(
child: Column(
children: <Widget>[
SizedBox(height: 40),
Row(
children: [
Icon(
Icons.add_box,
color: Colors.black,
),
SizedBox(width: 10),
Text(
'Join a New Meeting',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
],
),
Divider(height: 20, thickness: 1),
SizedBox(height: 20),
//Padding(
//padding: const EdgeInsets.only(right: 15),
Container(
//child
decoration: BoxDecoration(
color: Colors.grey[200],
border: Border.all(color: Colors.white),
//borderRadius: BorderRadius.circular(30),
),
child: Padding(
padding: const EdgeInsets.only(left: 15.0),
child: TextField(
controller: roomText,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Meeting ID",
contentPadding: const EdgeInsets.only(bottom: 8.0, top: 10.0),
),
),
),
),

SizedBox(height: 15),
Container(
//child
decoration: BoxDecoration(
color: Colors.grey[200],
border: Border.all(color: Colors.white),
//borderRadius: BorderRadius.circular(30),
),
child: Padding(
padding: const EdgeInsets.only(left: 15.0),
child: TextField(
controller: nameText,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Your Name",
contentPadding: const EdgeInsets.only(bottom: 8.0, top: 10.0),
),
),
),
),
//),
SizedBox(
height: 14.0,
),
Divider(height: 20, thickness: 1),
buildMeetingOption('Audio Only', isAudioOnly, _onAudioOnlyChanged),
buildMeetingOption('Audio Muted', isAudioMuted, _onAudioMutedChanged),
buildMeetingOption('Video Muted', isVideoMuted, _onVideoMutedChanged),
// CheckboxListTile(
// title: Text("Audio Only"),
// value: isAudioOnly,
// onChanged: _onAudioOnlyChanged,
// ),
// SizedBox(
// height: 14.0,
// ),
// CheckboxListTile(
// title: Text("Audio Muted"),
// value: isAudioMuted,
// onChanged: _onAudioMutedChanged,
// ),
// SizedBox(
// height: 14.0,
// ),
// CheckboxListTile(
// title: Text("Video Muted"),
// value: isVideoMuted,
// onChanged: _onVideoMutedChanged,
// ),
Divider(
height: 48.0,
thickness: 2.0,
),
SizedBox(
height: 50,
width: double.maxFinite,
child: ElevatedButton(
onPressed: () {
_joinMeeting();
},
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF0C1D36),
side: BorderSide.none,
shape: const StadiumBorder(),
),
child: const Text(
'Join Meeting',
style: TextStyle(
fontSize: 18,
color: Colors.white,
),
),
),
),
SizedBox(
height: 48.0,
),
],
),
);
}

_onAudioOnlyChanged(bool value) {
setState(() {
isAudioOnly = value;
});
}

_onAudioMutedChanged(bool value) {
setState(() {
isAudioMuted = value;
});
}

_onVideoMutedChanged(bool value) {
setState(() {
isVideoMuted = value;
});
}

_joinMeeting() async {
String? serverUrl = 'https://meet.dpmeet.xyz';

// Enable or disable any feature flag here


// If feature flag are not provided, default values will be used
// Full list of feature flags (and defaults) available in the README
Map<FeatureFlagEnum, bool> featureFlags = {
FeatureFlagEnum.WELCOME_PAGE_ENABLED: false,
FeatureFlagEnum.INVITE_ENABLED:false,
FeatureFlagEnum.CHAT_ENABLED:true,
FeatureFlagEnum.CALL_INTEGRATION_ENABLED:false,
FeatureFlagEnum.INVITE_ENABLED:false,
FeatureFlagEnum.MEETING_NAME_ENABLED:true,
FeatureFlagEnum.LIVE_STREAMING_ENABLED:false,
FeatureFlagEnum.RECORDING_ENABLED:false,
};
if (!kIsWeb) {
// Here is an example, disabling features for each platform
if (Platform.isAndroid) {
// Disable ConnectionService usage on Android to avoid issues (see README)
featureFlags[FeatureFlagEnum.CALL_INTEGRATION_ENABLED] = false;
featureFlags[FeatureFlagEnum.PIP_ENABLED]= false;
featureFlags[FeatureFlagEnum.TILE_VIEW_ENABLED]= false;
} else if (Platform.isIOS) {
// Disable PIP on iOS as it looks weird
featureFlags[FeatureFlagEnum.PIP_ENABLED] = false;
}
}
// Define meetings options here
var options = JitsiMeetingOptions(room: roomText.text)
..serverURL = serverUrl
..subject = 'Meeting' //Need to change it
..userDisplayName = nameText.text
..userEmail = emailText.text
..iosAppBarRGBAColor = iosAppBarRGBAColor.text
..audioOnly = isAudioOnly
..audioMuted = isAudioMuted
..videoMuted = isVideoMuted
..featureFlags.addAll(featureFlags)
..webOptions = {
"roomName": roomText.text,
"width": "100%",
"height": "100%",
"enableWelcomePage": false,
"chromeExtensionBanner": null,
"userInfo": {"displayName": nameText.text}
};

debugPrint("JitsiMeetingOptions: $options");
await JitsiMeet.joinMeeting(
options,
listener: JitsiMeetingListener(
onConferenceWillJoin: (message) {
debugPrint("${options.room} will join with message: $message");
},
onConferenceJoined: (message) {

debugPrint("${options.room} joined with message: $message");


},
onConferenceTerminated: (message) {
debugPrint("${options.room} terminated with message: $message");
},
genericListeners: [
JitsiGenericListener(
eventName: 'readyToClose',
callback: (dynamic message) {
debugPrint("readyToClose callback");
}),
]),
);
}

void _onConferenceWillJoin(message) {
debugPrint("_onConferenceWillJoin broadcasted with message: $message");
}

void _onConferenceJoined(message) {
_starttime = DateTime.now();

debugPrint("_onConferenceJoined broadcasted with message: $message");


}

void _onConferenceTerminated(message) {
_endtime = DateTime.now();

addmeetingdetails(roomText.text.toString(), _starttime, _endtime);


debugPrint("_onConferenceTerminated broadcasted with message: $message");
}

_onError(error) {
debugPrint("_onError broadcasted: $error");
}

Padding buildMeetingOption(
String title, bool value, Function onChangeMethod) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
title,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w400,
color: Colors.grey[600]),
),
Transform.scale(
scale: 0.85,
child: CupertinoSwitch(
activeColor: Color(0xFF0C1D36),
trackColor: Colors.grey,
value: value,
onChanged: (bool newValue) {
onChangeMethod(newValue);
},
),
)
],
),
);
}
}

You might also like