Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embed Jitsi as a PlatformView #92

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions jitsi_meet_wrapper/example/lib/jitsi_meet_view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:flutter/material.dart';
import 'package:jitsi_meet_wrapper/jitsi_meet_wrapper.dart';

class JitsiMeetView extends StatefulWidget {
const JitsiMeetView({
Key? key,
required this.options,
required this.listener,
}) : super(key: key);

final JitsiMeetingOptions options;
final JitsiMeetingListener listener;

@override
State<JitsiMeetView> createState() => _JitsiMeetViewState();
}

class _JitsiMeetViewState extends State<JitsiMeetView> {
JitsiMeetViewController? _controller;

@override
void initState() {
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Jitsi meet widget'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton(
onPressed: () {
_controller?.join();
},
child: const Text('Join'),
),
ElevatedButton(
onPressed: () {
_controller?.hangUp();
},
child: const Text('hangup'),
),
SizedBox(
height: 500,
width: 400,
child: JitsiMeetNativeView(
options: widget.options,
onViewCreated: (controller) {
_controller = controller;
_controller?.attachListener(widget.listener);
},
),
),
],
),
),
);
}
}
138 changes: 94 additions & 44 deletions jitsi_meet_wrapper/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:jitsi_meet_wrapper/jitsi_meet_wrapper.dart';

import 'jitsi_meet_view.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
Expand All @@ -23,7 +25,7 @@ class Meeting extends StatefulWidget {
}

class _MeetingState extends State<Meeting> {
final serverText = TextEditingController();
final serverText = TextEditingController(text: "https://meet.jit.si");
final roomText = TextEditingController(text: "jitsi-meet-wrapper-test-room");
final subjectText = TextEditingController(text: "My Plugin Test Meeting");
final tokenText = TextEditingController();
Expand All @@ -35,6 +37,54 @@ class _MeetingState extends State<Meeting> {
bool isAudioOnly = false;
bool isVideoMuted = true;

final listener = JitsiMeetingListener(
onOpened: () => debugPrint("onOpened"),
onConferenceWillJoin: (url) {
debugPrint("onConferenceWillJoin: url: $url");
},
onConferenceJoined: (url) {
debugPrint("onConferenceJoined: url: $url");
},
onConferenceTerminated: (url, error) {
debugPrint("onConferenceTerminated: url: $url, error: $error");
},
onAudioMutedChanged: (isMuted) {
debugPrint("onAudioMutedChanged: isMuted: $isMuted");
},
onVideoMutedChanged: (isMuted) {
debugPrint("onVideoMutedChanged: isMuted: $isMuted");
},
onScreenShareToggled: (participantId, isSharing) {
debugPrint(
"onScreenShareToggled: participantId: $participantId, "
"isSharing: $isSharing",
);
},
onParticipantJoined: (email, name, role, participantId) {
debugPrint(
"onParticipantJoined: email: $email, name: $name, role: $role, "
"participantId: $participantId",
);
},
onParticipantLeft: (participantId) {
debugPrint("onParticipantLeft: participantId: $participantId");
},
onParticipantsInfoRetrieved: (participantsInfo, requestId) {
debugPrint(
"onParticipantsInfoRetrieved: participantsInfo: $participantsInfo, "
"requestId: $requestId",
);
},
onChatMessageReceived: (senderId, message, isPrivate) {
debugPrint(
"onChatMessageReceived: senderId: $senderId, message: $message, "
"isPrivate: $isPrivate",
);
},
onChatToggled: (isOpen) => debugPrint("onChatToggled: isOpen: $isOpen"),
onClosed: () => debugPrint("onClosed"),
);

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down Expand Up @@ -113,6 +163,21 @@ class _MeetingState extends State<Meeting> {
),
),
),
SizedBox(
height: 64.0,
width: double.maxFinite,
child: ElevatedButton(
onPressed: () => _openJitsiMeetAsAWidget(context),
child: const Text(
"Use jitsi as a widget",
style: TextStyle(color: Colors.white),
),
style: ButtonStyle(
backgroundColor:
MaterialStateColor.resolveWith((states) => Colors.blue),
),
),
),
const SizedBox(height: 48.0),
],
),
Expand Down Expand Up @@ -159,52 +224,37 @@ class _MeetingState extends State<Meeting> {
debugPrint("JitsiMeetingOptions: $options");
await JitsiMeetWrapper.joinMeeting(
options: options,
listener: JitsiMeetingListener(
onOpened: () => debugPrint("onOpened"),
onConferenceWillJoin: (url) {
debugPrint("onConferenceWillJoin: url: $url");
},
onConferenceJoined: (url) {
debugPrint("onConferenceJoined: url: $url");
},
onConferenceTerminated: (url, error) {
debugPrint("onConferenceTerminated: url: $url, error: $error");
},
onAudioMutedChanged: (isMuted) {
debugPrint("onAudioMutedChanged: isMuted: $isMuted");
},
onVideoMutedChanged: (isMuted) {
debugPrint("onVideoMutedChanged: isMuted: $isMuted");
},
onScreenShareToggled: (participantId, isSharing) {
debugPrint(
"onScreenShareToggled: participantId: $participantId, "
"isSharing: $isSharing",
);
},
onParticipantJoined: (email, name, role, participantId) {
debugPrint(
"onParticipantJoined: email: $email, name: $name, role: $role, "
"participantId: $participantId",
);
},
onParticipantLeft: (participantId) {
debugPrint("onParticipantLeft: participantId: $participantId");
},
onParticipantsInfoRetrieved: (participantsInfo, requestId) {
debugPrint(
"onParticipantsInfoRetrieved: participantsInfo: $participantsInfo, "
"requestId: $requestId",
listener: listener,
);
}

_openJitsiMeetAsAWidget(BuildContext context) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
String? serverUrl =
serverText.text.trim().isEmpty ? null : serverText.text;

Map<FeatureFlag, Object> featureFlags = {};

// Define meetings options here
var options = JitsiMeetingOptions(
roomNameOrUrl: roomText.text,
serverUrl: serverUrl,
subject: subjectText.text,
token: tokenText.text,
isAudioMuted: isAudioMuted,
isAudioOnly: isAudioOnly,
isVideoMuted: isVideoMuted,
userDisplayName: userDisplayNameText.text,
userEmail: userEmailText.text,
featureFlags: featureFlags,
);
},
onChatMessageReceived: (senderId, message, isPrivate) {
debugPrint(
"onChatMessageReceived: senderId: $senderId, message: $message, "
"isPrivate: $isPrivate",
return JitsiMeetView(
options: options,
listener: listener,
);
},
onChatToggled: (isOpen) => debugPrint("onChatToggled: isOpen: $isOpen"),
onClosed: () => debugPrint("onClosed"),
),
);
}
Expand Down
Loading