Subscription permission API (#68)
* signal * request * implement * rename event * ref * adjustments based on review * override subscribed * move events emit * fix subscription state * minor change * update example for permissions demo * format & subscriptionState as computed property * prepare macos build * unsubscribed event when subscription not allowed
This commit is contained in:
@@ -135,4 +135,23 @@ extension LKExampleExt on BuildContext {
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Future<bool?> showSubscribePermissionDialog() => showDialog<bool>(
|
||||
context: this,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Allow subscription'),
|
||||
content: const Text(
|
||||
'Allow all participants to subscribe tracks published by local participant?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
child: const Text('NO'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('YES'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -136,6 +136,19 @@ class _ControlsWidgetState extends State<ControlsWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onTapUpdateSubscribePermission() async {
|
||||
final result = await context.showSubscribePermissionDialog();
|
||||
if (result != null) {
|
||||
try {
|
||||
widget.room.localParticipant?.setTrackSubscriptionPermissions(
|
||||
allParticipantsAllowed: result,
|
||||
);
|
||||
} catch (error) {
|
||||
await context.showErrorDialog(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _onTapSendData() async {
|
||||
final result = await context.showSendDataDialog();
|
||||
if (result == true) {
|
||||
@@ -220,6 +233,11 @@ class _ControlsWidgetState extends State<ControlsWidget> {
|
||||
icon: const Icon(EvaIcons.refresh),
|
||||
tooltip: 're-connect',
|
||||
),
|
||||
IconButton(
|
||||
onPressed: _onTapUpdateSubscribePermission,
|
||||
icon: const Icon(EvaIcons.settings2),
|
||||
tooltip: 'Subscribe permission',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -192,13 +192,13 @@ class _RemoteParticipantWidgetState
|
||||
if (firstVideoPublication != null)
|
||||
RemoteTrackPublicationMenuWidget(
|
||||
pub: firstVideoPublication!,
|
||||
icon: EvaIcons.videoOutline,
|
||||
icon: EvaIcons.video,
|
||||
),
|
||||
// Menu for RemoteTrackPublication<RemoteAudioTrack>
|
||||
if (firstAudioPublication != null)
|
||||
RemoteTrackPublicationMenuWidget(
|
||||
pub: firstAudioPublication!,
|
||||
icon: EvaIcons.volumeUpOutline,
|
||||
icon: EvaIcons.volumeUp,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -218,23 +218,27 @@ class RemoteTrackPublicationMenuWidget extends StatelessWidget {
|
||||
Widget build(BuildContext context) => Material(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
child: PopupMenuButton<Function>(
|
||||
icon: Icon(icon),
|
||||
tooltip: 'Subscribe menu',
|
||||
icon: Icon(icon,
|
||||
color: {
|
||||
TrackSubscriptionState.notAllowed: Colors.red,
|
||||
TrackSubscriptionState.unsubscribed: Colors.grey,
|
||||
TrackSubscriptionState.subscribed: Colors.green,
|
||||
}[pub.subscriptionState]),
|
||||
onSelected: (value) => value(),
|
||||
itemBuilder: (BuildContext context) {
|
||||
return <PopupMenuEntry<Function>>[
|
||||
// Subscribe/Unsubscribe
|
||||
if (pub.subscribed == false)
|
||||
PopupMenuItem(
|
||||
child: const Text('Subscribe'),
|
||||
value: () => pub.subscribed = true,
|
||||
)
|
||||
else if (pub.subscribed == true)
|
||||
PopupMenuItem(
|
||||
child: const Text('Un-subscribe'),
|
||||
value: () => pub.subscribed = false,
|
||||
),
|
||||
];
|
||||
},
|
||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<Function>>[
|
||||
// Subscribe/Unsubscribe
|
||||
if (pub.subscribed == false)
|
||||
PopupMenuItem(
|
||||
child: const Text('Subscribe'),
|
||||
value: () => pub.subscribe(),
|
||||
)
|
||||
else if (pub.subscribed == true)
|
||||
PopupMenuItem(
|
||||
child: const Text('Un-subscribe'),
|
||||
value: () => pub.unsubscribe(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user