feat(postit): separate call interfaces from text chat

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Schneider 2026-11-12 16:49:48 +00:00
commit 972b1a5cce
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
17 changed files with 379 additions and 130 deletions

View file

@ -6,6 +6,8 @@
### Added
* [PostIt/Calls] Move WebRTC and direct SRTP controls out of the text chat into a dedicated call page, opened for a selected room member or an incoming invitation. Include resolved room-member names in chat snapshots for call targeting, without replacing internal connection identifiers. Preserve the call when leaving the chat for that page and hang up when leaving the call page.
* [PostIt/Contacts] Add a Contacts page listing circle members and their associated circles, with duplicate members merged. Presence and calling contacts outside a shared chat room are not yet implemented.
* [PostIt/Calls] Restore the direct IPv4/IPv6 VLC/SRTP call panel alongside WebRTC on supported platforms, route invitations to the matching transport, and retain explicit IP disclosure consent and server privacy policy. Add transport routing and lifecycle regressions.

View file

@ -5,12 +5,18 @@
Ce document décrit l'architecture cible, l'implementation native actuelle et
l'historique du transport direct.
La préférence de confidentialité est persistée et éditable dans le profil.
La signalisation est intégrée au chat, désactivée par défaut. La page du chat
propose **WebRTC natif** et le transport direct VLC/SRTP sur Android et
La signalisation est intégrée au chat, désactivée par défaut. Une page d'appel
separee propose **WebRTC natif** et le transport direct VLC/SRTP sur Android et
Desktop Linux. WebRTC utilise ICE/STUN/TURN et le masquage IP impose par la
politique serveur. Le mode SRTP direct ne masque pas les adresses IP et exige
que cette preference soit desactivee pour les deux participants. Les groupes
et les clients navigateur ne sont pas implementes.
Depuis le chat textuel, selectionner un membre present puis « Ouvrir l'appel »
prepare le pair sans demarrer les medias. Les invitations entrantes disposent
d'un bouton pour ouvrir cette meme page sans selection de membre. Passer du
chat a la page d'appel ne raccroche pas ; quitter la page d'appel termine les
medias. Un salon commun reste requis ; les capacites distantes et les appels
depuis Contacts ne sont pas encore raccordes.
Il complète la [topologie de PostIt](postit.md) et les
[mécanismes de notification existants](notifications.md).
La cible couvre :
@ -123,7 +129,7 @@ TURN/TLS et les reseaux Internet distincts restent a verifier.
## Implementation SRTP direct IPv4/IPv6
Les paragraphes suivants decrivent le transport direct historique, de nouveau
propose a cote de WebRTC dans la page du chat.
propose a cote de WebRTC dans la page d'appel.
Les adresses IPv4 publiques directement assignees a une interface locale active
sont egalement disponibles, avec la meme validation unicast cote client,
@ -193,10 +199,12 @@ de fichier média temporaire ou de moteur WebRTC Android ajouté.
H.264/AAC. La version Debian 13 a été utilisée pour les essais Linux.
Les deux comptes doivent être présents dans
la même salle existante et ne pas se bloquer mutuellement.
3. Dans « Appel direct IPv4/IPv6 (LAN/VPN ou IP publique) », actualiser les périphériques,
sélectionner la caméra, le microphone et une IPv4 privée locale
accessible depuis le pair. Les adresses RFC1918 et de bouclage sont
acceptées ; pas de DNS, IPv6 ou adresse publique. Le bouclage sert aux
3. Selectionner le destinataire dans les membres presents du chat puis
« Ouvrir l'appel ». Dans la section « Appel direct IPv4/IPv6 SRTP »,
actualiser les périphériques, sélectionner la caméra, le microphone et
une adresse locale accessible depuis le pair. Les adresses IPv4 privées
ou publiques assignées et les IPv6 globales ou ULA sont acceptées, pas
les noms DNS ni les adresses link-local. Le bouclage sert aux
essais sur un même hôte, pas à joindre un second poste.
4. Choisir un port UDP **pair entre 1024 et 65534**, par défaut 5004.
Autoriser l'entrée UDP sur ce port **et le suivant** depuis le pair dans
@ -204,7 +212,7 @@ de fichier média temporaire ou de moteur WebRTC Android ajouté.
Les deux ports doivent être disponibles. Deux clients sur la même
adresse doivent utiliser des paires distinctes.
Aucun pare-feu n'est modifié automatiquement.
5. Saisir le pseudo exact du destinataire, confirmer la divulgation de
5. Verifier le pseudo du destinataire selectionne, confirmer la divulgation de
l'adresse IP locale (LAN/VPN ou publique), puis appeler. Le destinataire choisit ses propres
périphériques et son adresse, confirme et accepte explicitement.
Aucun accès à la caméra/microphone ne commence avant l'acceptation ;

View file

@ -1,4 +1,6 @@
using Avalonia.Headless.XUnit;
using Avalonia.Controls;
using PostIt.Views.Chat;
using PostIt.Services;
using PostIt.ViewModels;
using PostIt.ViewModels.Chat;
@ -89,6 +91,71 @@ public sealed class CallTransportRoutingTests
while (!condition()) await Task.Delay(10, timeout.Token);
}
[AvaloniaFact]
public async Task Selecting_a_room_member_prepares_both_transports_without_inviting()
{
var signaling = new Signaling();
await using var lan = new LanCallViewModel(signaling);
await using var webRtc = new WebRtcCallViewModel(signaling);
var chat = new ChatViewModel(settings: new Settings())
{
LanCall = lan, VideoCall = webRtc, IsConnected = true, SelectedRoom = "General",
FocusedUsers = new()
};
chat.FocusedUsers.Add("bob");
Assert.False(chat.OpenCallCommand.CanExecute(null));
chat.SelectedUser = "bob";
Assert.True(chat.OpenCallCommand.CanExecute(null));
var page = chat.PrepareCallPage();
Assert.Same(chat, page.Chat);
Assert.Equal("bob", lan.Target);
Assert.Equal("bob", webRtc.Target);
Assert.False(lan.Busy);
Assert.False(webRtc.Busy);
chat.FocusedUsers.Remove("bob");
Assert.Null(chat.SelectedUser);
Assert.False(chat.OpenCallCommand.CanExecute(null));
chat.FocusedUsers.Add("bob");
chat.SelectedUser = "bob";
chat.SelectedRoom = "Other";
Assert.Null(chat.SelectedUser);
Assert.False(chat.OpenCallCommand.CanExecute(null));
}
[AvaloniaTheory]
[InlineData(CallTransports.LanSrtp)]
[InlineData(CallTransports.WebRtc)]
public async Task Leaving_text_chat_preserves_invitation_and_leaving_call_page_ends_it(string transport)
{
var signaling = new Signaling();
await using var lan = new LanCallViewModel(signaling);
await using var webRtc = new WebRtcCallViewModel(signaling);
var chat = new ChatViewModel(settings: new Settings())
{
LanCall = lan, VideoCall = webRtc, IsConnected = true, SelectedRoom = "General",
FocusedUsers = new()
};
var call = new CallSession(Guid.NewGuid(), "General", "alice", "bob", false,
DateTimeOffset.UtcNow.AddMinutes(1), transport);
signaling.Invite(call);
await WaitAsync(() => lan.Incoming || webRtc.Incoming);
Assert.True(chat.ShowCallCommand.CanExecute(null));
var window = new Window { Content = new ChatPage { DataContext = chat } };
try
{
window.Show();
window.Content = new CallPage { DataContext = new CallPageViewModel(chat) };
Assert.Empty(signaling.EndedCalls);
Assert.True(lan.Incoming || webRtc.Incoming);
window.Content = null;
await WaitAsync(() => signaling.EndedCalls.Count != 0);
Assert.Equal([call.Id], signaling.EndedCalls);
Assert.False(lan.Busy);
Assert.False(webRtc.Busy);
}
finally { window.Close(); }
}
private sealed class Signaling : IWebRtcCallSignaling
{
public event Action<CallSession>? Invitation;

View file

@ -85,6 +85,7 @@ public static class ServiceCollectionHelpers
AddReusablePage<ActivitiesPage>();
services.AddTransient<CommandFormsPage>();
services.AddTransient<ChatPage>();
services.AddTransient<CallPage>();
services.AddTransient<RdvPage>();
services.AddTransient<BrushPage>();
services.AddTransient<BillingQueriesPage>();

View file

@ -7,5 +7,6 @@ namespace PostIt.ViewModels.Chat
{
public string? Name { get; set; }
public List<string> Users { get; set; } = new();
public List<string>? UserNames { get; set; }
}
}

View file

@ -70,6 +70,7 @@ public class ViewLocator : IDataTemplate
AdministrationPageViewModel => services.GetRequiredService<AdministrationPage>(),
ResourceUsageReliefPageViewModel => services.GetRequiredService<ResourceUsageReliefPage>(),
ChatViewModel => services.GetRequiredService<ChatPage>(),
CallPageViewModel => services.GetRequiredService<CallPage>(),
null => new TextBlock { Text = "No view for <null>" },
_ => new TextBlock { Text = $"No view for {data.GetType().Name}" }
};

View file

@ -0,0 +1,12 @@
using System.Threading.Tasks;
namespace PostIt.ViewModels.Chat;
public sealed class CallPageViewModel(ChatViewModel chat) : ViewModelBase
{
public ChatViewModel Chat { get; } = chat;
public override bool CanNavigateNext { get; protected set; } = false;
public override bool CanNavigatePrevious { get; protected set; } = true;
public Task HangupAsync() => Chat.HangupCallsAsync();
}

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Threading.Tasks;
using System.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
@ -63,11 +64,17 @@ namespace PostIt.ViewModels.Chat
(OperatingSystem.IsLinux() && !OperatingSystem.IsAndroid());
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(OpenCallCommand), nameof(ShowCallCommand))]
public partial WebRtcCallViewModel? VideoCall { get; set; }
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(OpenCallCommand), nameof(ShowCallCommand))]
public partial LanCallViewModel? LanCall { get; set; }
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(OpenCallCommand))]
public partial string? SelectedUser { get; set; }
[ObservableProperty]
public partial string CurrentRoom { get; set; } = "General";
@ -79,6 +86,7 @@ namespace PostIt.ViewModels.Chat
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(SendMessageCommand))]
[NotifyCanExecuteChangedFor(nameof(OpenCallCommand), nameof(ShowCallCommand))]
public partial bool IsConnected { get; set; } = false;
[ObservableProperty]
@ -92,6 +100,7 @@ namespace PostIt.ViewModels.Chat
// alors les notifications système.
[ObservableProperty]
[NotifyCanExecuteChangedFor(nameof(SendMessageCommand))]
[NotifyCanExecuteChangedFor(nameof(OpenCallCommand))]
public partial string? SelectedRoom { get; set; }
// Notifications globales (connexion, erreurs de join, ...)
@ -110,8 +119,39 @@ namespace PostIt.ViewModels.Chat
[ObservableProperty]
public partial ObservableCollection<string> FocusedUsers { get; set; } = _noUsers;
partial void OnFocusedUsersChanging(ObservableCollection<string> value) =>
FocusedUsers.CollectionChanged -= OnFocusedUsersCollectionChanged;
partial void OnFocusedUsersChanged(ObservableCollection<string> value)
{
value.CollectionChanged += OnFocusedUsersCollectionChanged;
OpenCallCommand.NotifyCanExecuteChanged();
}
private void OnFocusedUsersCollectionChanged(object? sender, NotifyCollectionChangedEventArgs args)
{
if (SelectedUser != null && !FocusedUsers.Contains(SelectedUser)) SelectedUser = null;
OpenCallCommand.NotifyCanExecuteChanged();
}
private void UpdateRoomUsers(string type, string room, string user)
{
if (!_usersByRoom.TryGetValue(room, out var users)) return;
if (string.Equals(type, NotificationTypes.UserJoin, StringComparison.OrdinalIgnoreCase))
{
if (!users.Contains(user)) users.Add(user);
}
else if (string.Equals(type, NotificationTypes.UserPart, StringComparison.OrdinalIgnoreCase) ||
string.Equals(type, NotificationTypes.Kick, StringComparison.OrdinalIgnoreCase))
{
var separator = user.IndexOf(':');
users.Remove(separator < 0 ? user : user[..separator]);
}
}
partial void OnSelectedRoomChanged(string? value)
{
SelectedUser = null;
if (VideoCall != null) VideoCall.Room = value ?? "";
if (LanCall != null) LanCall.Room = value ?? "";
FocusedMessages = value != null && _messagesByRoom.TryGetValue(value, out var msgs)
@ -120,6 +160,46 @@ namespace PostIt.ViewModels.Chat
? users : _noUsers;
}
private bool CanShowCall() => IsConnected && (VideoCall != null || LanCall != null);
private bool CanOpenCall() => CanShowCall() && SelectedRoom != null &&
!string.IsNullOrWhiteSpace(SelectedUser) && FocusedUsers.Contains(SelectedUser);
internal CallPageViewModel PrepareCallPage()
{
if (!CanOpenCall())
throw new InvalidOperationException("Selectionnez un utilisateur present dans le salon et connectez le chat.");
if (VideoCall?.Busy != true && LanCall?.Busy != true)
{
if (VideoCall != null) VideoCall.Target = SelectedUser!;
if (LanCall != null) LanCall.Target = SelectedUser!;
}
return new CallPageViewModel(this);
}
[RelayCommand(CanExecute = nameof(CanOpenCall))]
private Task OpenCallAsync() => NavigateToCallAsync(configureTarget: true);
[RelayCommand(CanExecute = nameof(CanShowCall))]
private Task ShowCallAsync() => NavigateToCallAsync(configureTarget: false);
private async Task NavigateToCallAsync(bool configureTarget)
{
try
{
var app = App.Current as App ?? throw new InvalidOperationException("Application indisponible.");
var page = configureTarget ? PrepareCallPage() : new CallPageViewModel(this);
await app.PushPageAsync(page);
}
catch (Exception error) { Log($"Impossible d'ouvrir l'appel : {error.Message}"); }
}
public async Task HangupCallsAsync()
{
if (VideoCall != null) await VideoCall.HangupAsync();
if (LanCall != null) await LanCall.HangupAsync();
}
// Trace une notification système dans la vue courante
// (et dans le journal global pour consultation ultérieure).
private void Log(string line)
@ -167,8 +247,7 @@ namespace PostIt.ViewModels.Chat
if (_transport == null || room == null) return;
try
{
if (VideoCall != null) await VideoCall.HangupAsync();
if (LanCall != null) await LanCall.HangupAsync();
await HangupCallsAsync();
await _transport.LeaveAsync(room);
JoinedRooms.Remove(room);
_messagesByRoom.Remove(room);
@ -351,9 +430,7 @@ namespace PostIt.ViewModels.Chat
roomLog.Add($"*{user} a interagi avec le salon {room} (Action: {type})");
else
Log($"*{user} a interagi avec le salon {room} (Action: {type})");
if (type == "UserJoin" && _usersByRoom.TryGetValue(room, out var users)
&& !users.Contains(user))
users.Add(user);
UpdateRoomUsers(type, room, user);
});
});
@ -422,7 +499,7 @@ namespace PostIt.ViewModels.Chat
roomLog = _messagesByRoom[roomName] = new();
roomLog.Add($"Salon rejoint avec succès : {roomName}");
var users = _usersByRoom[roomName] = new();
foreach (var u in roomInfo.Users) users.Add(u);
foreach (var u in roomInfo.UserNames ?? roomInfo.Users) users.Add(u);
if (!JoinedRooms.Contains(roomName))
JoinedRooms.Add(roomName);
SelectedRoom = roomName;

View file

@ -251,6 +251,8 @@ public partial class LanCallViewModel : ObservableObject, IAsyncDisposable
if (_call != null) throw new InvalidOperationException("Invitation concurrente inattendue.");
if (call.RelayOnly) throw new InvalidOperationException("Le mode LAN ne peut pas masquer les adresses IP.");
_call = call;
Room = call.RoomName;
Target = call.Caller;
Busy = true;
Incoming = true;
Status = $"{call.Caller} propose un appel SRTP dans {call.RoomName}. Acceptez ou refusez.";

View file

@ -168,6 +168,8 @@ public partial class WebRtcCallViewModel : ObservableObject, IAsyncDisposable
return;
}
_call = call;
Room = call.RoomName;
Target = call.Caller;
_caller = false;
_callLifetime = CancellationTokenSource.CreateLinkedTokenSource(_lifetime.Token);
Busy = Incoming = true;

View file

@ -0,0 +1,101 @@
<ContentPage
x:Class="PostIt.Views.Chat.CallPage"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:PostIt.ViewModels.Chat"
xmlns:services="using:PostIt.Services"
x:DataType="vm:CallPageViewModel"
Header="Appel audio-video">
<ScrollViewer HorizontalScrollBarVisibility="Disabled">
<StackPanel Margin="16" Spacing="16">
<TextBlock Text="Choisissez WebRTC ou SRTP direct. Les deux participants doivent etre presents dans le meme salon. Quitter cette page termine l'appel."
TextWrapping="Wrap" />
<StackPanel IsVisible="{Binding Chat.SupportsVideoCalls}">
<TextBlock Text="Appel video WebRTC" FontSize="20" FontWeight="SemiBold" Margin="0,0,0,8" />
<StackPanel DataContext="{Binding Chat.VideoCall}" x:DataType="vm:WebRtcCallViewModel"
IsEnabled="{Binding $parent[ContentPage].((vm:CallPageViewModel)DataContext).Chat.IsConnected}" Spacing="8">
<TextBlock Text="Android et Linux : medias chiffres par WebRTC (DTLS-SRTP), ICE/STUN/TURN. Activez le masquage IP dans votre profil pour imposer un relais TURN aux deux participants, sans repli direct. La camera et le microphone ne demarrent qu'apres acceptation."
TextWrapping="Wrap" />
<WrapPanel IsEnabled="{Binding CanConfigure}" IsVisible="{Binding !RemoteVideo}">
<Button Content="Actualiser les peripheriques" Command="{Binding RefreshDevicesCommand}" Margin="0,0,8,4" />
<ComboBox Width="190" ItemsSource="{Binding Cameras}" SelectedItem="{Binding Camera}"
PlaceholderText="Camera" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Width="190" ItemsSource="{Binding Microphones}" SelectedItem="{Binding Microphone}"
PlaceholderText="Microphone" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock Text="{Binding Target}" VerticalAlignment="Center" Margin="0,0,8,4" />
</WrapPanel>
<CheckBox Content="Si le masquage IP est desactive, je consens a partager mon adresse IP avec le pair."
IsChecked="{Binding AllowAddressDisclosure}" IsEnabled="{Binding CanConfigure}"
IsVisible="{Binding !RemoteVideo}" />
<WrapPanel>
<Button Content="Appeler dans la salle active" Command="{Binding InviteCommand}" IsEnabled="{Binding !Busy}" Margin="0,0,8,4" />
<Button Content="Accepter" Command="{Binding AcceptCommand}" IsEnabled="{Binding Incoming}" Margin="0,0,8,4" />
<Button Content="Refuser / Raccrocher" Command="{Binding HangupCommand}" IsEnabled="{Binding Busy}" Margin="0,0,8,4" />
</WrapPanel>
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" />
<Grid ColumnDefinitions="*,2*" Height="280" IsVisible="{Binding !!RemoteVideo}">
<ContentControl Content="{Binding LocalVideo}" Margin="0,0,8,0" />
<ContentControl Grid.Column="1" Content="{Binding RemoteVideo}" />
</Grid>
</StackPanel>
</StackPanel>
<StackPanel IsVisible="{Binding Chat.SupportsLanCalls}">
<TextBlock Text="Appel direct IPv4/IPv6 SRTP (LAN/VPN ou IP publique)"
FontSize="20" FontWeight="SemiBold" TextWrapping="Wrap" Margin="0,0,0,8" />
<StackPanel DataContext="{Binding Chat.LanCall}" x:DataType="vm:LanCallViewModel"
IsEnabled="{Binding $parent[ContentPage].((vm:CallPageViewModel)DataContext).Chat.IsConnected}" Spacing="8">
<TextBlock Text="Connexion directe sans TURN ni traversee NAT : le pair connait votre IP. Le masquage IP doit etre desactive dans les profils des deux participants. Les medias sont chiffres par SRTP. Ouvrez le port UDP pair choisi et le suivant ; HTTPS est requis pour la signalisation. Casque recommande."
TextWrapping="Wrap" />
<WrapPanel IsEnabled="{Binding CanConfigure}" IsVisible="{Binding !RemoteVideo}">
<Button Content="Actualiser les peripheriques" Command="{Binding RefreshDevicesCommand}" Margin="0,0,8,4" />
<ComboBox Width="160" ItemsSource="{Binding Addresses}" SelectedItem="{Binding Address}"
PlaceholderText="Adresse IPv4/IPv6 de cette machine" Margin="0,0,8,4" />
<TextBox Width="80" Text="{Binding Port}" PlaceholderText="Port pair" Margin="0,0,8,4" />
<ComboBox Width="190" ItemsSource="{Binding Cameras}" SelectedItem="{Binding Camera}"
PlaceholderText="Camera" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Width="190" ItemsSource="{Binding Microphones}" SelectedItem="{Binding Microphone}"
PlaceholderText="Microphone" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock Text="{Binding Target}" VerticalAlignment="Center" Margin="0,0,8,4" />
</WrapPanel>
<CheckBox Content="Je consens a partager mon adresse IP avec le pair."
IsChecked="{Binding AllowAddressDisclosure}" IsEnabled="{Binding CanConfigure}"
IsVisible="{Binding !RemoteVideo}" />
<WrapPanel>
<Button Content="Appeler dans la salle active" Command="{Binding InviteCommand}" IsEnabled="{Binding !Busy}" Margin="0,0,8,4" />
<Button Content="Accepter" Command="{Binding AcceptCommand}" IsEnabled="{Binding Incoming}" Margin="0,0,8,4" />
<Button Content="Refuser / Raccrocher" Command="{Binding HangupCommand}" IsEnabled="{Binding Busy}" Margin="0,0,8,4" />
</WrapPanel>
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" />
<Grid ColumnDefinitions="*,2*" Height="280" IsVisible="{Binding !!RemoteVideo}">
<ContentControl Content="{Binding LocalVideo}" Margin="0,0,8,0" />
<ContentControl Grid.Column="1" Content="{Binding RemoteVideo}" />
</Grid>
</StackPanel>
</StackPanel>
</StackPanel>
</ScrollViewer>
</ContentPage>

View file

@ -0,0 +1,16 @@
using Avalonia;
using Avalonia.Controls;
using PostIt.ViewModels.Chat;
namespace PostIt.Views.Chat;
public partial class CallPage : ContentPage
{
public CallPage() => InitializeComponent();
protected override async void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
if (DataContext is CallPageViewModel call) await call.HangupAsync();
}
}

View file

@ -2,15 +2,8 @@
x:Class="PostIt.Views.Chat.ChatPage"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:AvaloniaEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:md="using:MarkdownViewer.Core.Controls"
xmlns:models="using:Yavsc.Blogspot"
xmlns:postitControls="using:PostIt.Controls"
xmlns:views="using:PostIt.Views.Chat"
xmlns:vm="using:PostIt.ViewModels.Chat"
xmlns:services="using:PostIt.Services"
x:DataType="vm:ChatViewModel"
>
<Design.DataContext>
@ -66,7 +59,7 @@
Margin="10,0,0,0"
BorderBrush="#E0E0E0"
BorderThickness="1">
<Grid RowDefinitions="Auto, *">
<Grid RowDefinitions="Auto, *, Auto">
<TextBlock
Grid.Row="0"
Margin="5"
@ -76,7 +69,10 @@
<ListBox
Grid.Row="1"
BorderThickness="0"
ItemsSource="{Binding FocusedUsers}" />
ItemsSource="{Binding FocusedUsers}"
SelectedItem="{Binding SelectedUser}" />
<Button Grid.Row="2" Margin="5" Content="Ouvrir l'appel"
Command="{Binding OpenCallCommand}" />
</Grid>
</Border>
</Grid>
@ -104,99 +100,12 @@
Content="Envoyer" />
</Grid>
<ScrollViewer Grid.Row="3" MaxHeight="520" Margin="0,0,0,8">
<StackPanel>
<TextBlock Text="Invitation WebRTC recue : ouvrez le panneau WebRTC pour repondre."
IsVisible="{Binding VideoCall.Incoming}" TextWrapping="Wrap" />
<TextBlock Text="Invitation SRTP directe recue : ouvrez le panneau d'appel direct pour repondre."
IsVisible="{Binding LanCall.Incoming}" TextWrapping="Wrap" />
<Expander Header="Appel video WebRTC" IsVisible="{Binding SupportsVideoCalls}" IsExpanded="True"
IsEnabled="{Binding IsConnected}" Margin="0,0,0,8">
<StackPanel DataContext="{Binding VideoCall}" x:DataType="vm:WebRtcCallViewModel" Spacing="8">
<TextBlock Text="Android et Linux : medias chiffres par WebRTC (DTLS-SRTP), ICE/STUN/TURN. Activez le masquage IP dans votre profil pour imposer un relais TURN aux deux participants, sans repli direct. La camera et le microphone ne demarrent qu'apres acceptation."
TextWrapping="Wrap" />
<WrapPanel IsEnabled="{Binding CanConfigure}" IsVisible="{Binding !RemoteVideo}">
<Button Content="Actualiser les peripheriques" Command="{Binding RefreshDevicesCommand}" Margin="0,0,8,4" />
<ComboBox Width="190" ItemsSource="{Binding Cameras}" SelectedItem="{Binding Camera}"
PlaceholderText="Camera" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Width="190" ItemsSource="{Binding Microphones}" SelectedItem="{Binding Microphone}"
PlaceholderText="Microphone" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBox Width="170" Text="{Binding Target}" PlaceholderText="Pseudo du pair" Margin="0,0,8,4" />
</WrapPanel>
<CheckBox Content="Si le masquage IP est desactive, je consens a partager mon adresse IP avec le pair."
IsChecked="{Binding AllowAddressDisclosure}" IsEnabled="{Binding CanConfigure}"
IsVisible="{Binding !RemoteVideo}" />
<WrapPanel>
<Button Content="Appeler dans la salle active" Command="{Binding InviteCommand}" IsEnabled="{Binding !Busy}" Margin="0,0,8,4" />
<Button Content="Accepter" Command="{Binding AcceptCommand}" IsEnabled="{Binding Incoming}" Margin="0,0,8,4" />
<Button Content="Refuser / Raccrocher" Command="{Binding HangupCommand}" IsEnabled="{Binding Busy}" Margin="0,0,8,4" />
</WrapPanel>
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" />
<Grid ColumnDefinitions="*,2*" Height="280" IsVisible="{Binding !!RemoteVideo}">
<ContentControl Content="{Binding LocalVideo}" Margin="0,0,8,0" />
<ContentControl Grid.Column="1" Content="{Binding RemoteVideo}" />
</Grid>
</StackPanel>
</Expander>
<Expander Header="Appel direct IPv4/IPv6 SRTP (LAN/VPN ou IP publique)"
IsVisible="{Binding SupportsLanCalls}" IsExpanded="True"
IsEnabled="{Binding IsConnected}">
<StackPanel DataContext="{Binding LanCall}" x:DataType="vm:LanCallViewModel" Spacing="8">
<TextBlock Text="Connexion directe sans TURN ni traversee NAT : le pair connait votre IP. Le masquage IP doit etre desactive dans les profils des deux participants. Les medias sont chiffres par SRTP. Ouvrez le port UDP pair choisi et le suivant ; HTTPS est requis pour la signalisation. Casque recommande."
TextWrapping="Wrap" />
<WrapPanel IsEnabled="{Binding CanConfigure}" IsVisible="{Binding !RemoteVideo}">
<Button Content="Actualiser les peripheriques" Command="{Binding RefreshDevicesCommand}" Margin="0,0,8,4" />
<ComboBox Width="160" ItemsSource="{Binding Addresses}" SelectedItem="{Binding Address}"
PlaceholderText="Adresse IPv4/IPv6 de cette machine" Margin="0,0,8,4" />
<TextBox Width="80" Text="{Binding Port}" PlaceholderText="Port pair" Margin="0,0,8,4" />
<ComboBox Width="190" ItemsSource="{Binding Cameras}" SelectedItem="{Binding Camera}"
PlaceholderText="Camera" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox Width="190" ItemsSource="{Binding Microphones}" SelectedItem="{Binding Microphone}"
PlaceholderText="Microphone" Margin="0,0,8,4">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="services:CaptureDevice">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBox Width="170" Text="{Binding Target}" PlaceholderText="Pseudo du pair" Margin="0,0,8,4" />
</WrapPanel>
<CheckBox Content="Je consens a partager mon adresse IP avec le pair."
IsChecked="{Binding AllowAddressDisclosure}" IsEnabled="{Binding CanConfigure}"
IsVisible="{Binding !RemoteVideo}" />
<WrapPanel>
<Button Content="Appeler dans la salle active" Command="{Binding InviteCommand}" IsEnabled="{Binding !Busy}" Margin="0,0,8,4" />
<Button Content="Accepter" Command="{Binding AcceptCommand}" IsEnabled="{Binding Incoming}" Margin="0,0,8,4" />
<Button Content="Refuser / Raccrocher" Command="{Binding HangupCommand}" IsEnabled="{Binding Busy}" Margin="0,0,8,4" />
</WrapPanel>
<TextBlock Text="{Binding Status}" TextWrapping="Wrap" />
<Grid ColumnDefinitions="*,2*" Height="280" IsVisible="{Binding !!RemoteVideo}">
<ContentControl Content="{Binding LocalVideo}" Margin="0,0,8,0" />
<ContentControl Grid.Column="1" Content="{Binding RemoteVideo}" />
</Grid>
</StackPanel>
</Expander>
<StackPanel Grid.Row="3" Margin="0,0,0,8" Spacing="4">
<Button Content="Repondre a l'invitation WebRTC" Command="{Binding ShowCallCommand}"
IsVisible="{Binding VideoCall.Incoming}" />
<Button Content="Repondre a l'invitation SRTP directe" Command="{Binding ShowCallCommand}"
IsVisible="{Binding LanCall.Incoming}" />
</StackPanel>
</ScrollViewer>
<postitControls:StatusBar
x:Name="StatusBar"

View file

@ -1,6 +1,4 @@
using Avalonia;
using Avalonia.Controls;
using PostIt.ViewModels.Chat;
namespace PostIt.Views.Chat;
public partial class ChatPage : ContentPage
{
@ -9,14 +7,4 @@ public partial class ChatPage : ContentPage
{
InitializeComponent();
}
protected override async void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
if (DataContext is ChatViewModel chat)
{
if (chat.VideoCall is { } video) await video.HangupAsync();
if (chat.LanCall is { } lan) await lan.HangupAsync();
}
}
}

View file

@ -163,8 +163,19 @@ namespace Yavsc.Server.Hubs
}
_logger.LogInformation($"returning channel info");
await Clients.Caller.SendAsync("joint", channelInfo);
return channelInfo;
var snapshot = new ChatRoomInfo
{
Name = channelInfo.Name,
Topic = channelInfo.Topic,
Users = [.. channelInfo.Users],
Ops = [.. channelInfo.Ops],
Hops = [.. channelInfo.Hops],
UserNames = channelInfo.Users.Concat(channelInfo.Ops).Concat(channelInfo.Hops)
.Select(id => _cxManager.GetUserName(id))
.Where(name => !string.IsNullOrWhiteSpace(name)).Distinct().ToList()
};
await Clients.Caller.SendAsync("joint", snapshot);
return snapshot;
}
public void Register(string room)

View file

@ -25,6 +25,7 @@ namespace Yavsc
{
public string Name;
public List<string> Users = new List<string>();
public List<string>? UserNames { get; set; }
public List<string> Ops = new List<string>();
public List<string> Hops = new List<string>();
public string Topic;

View file

@ -88,6 +88,51 @@ public sealed class CallHubTests
public HttpContext? HttpContext { get; set; } = context;
}
[Fact]
public async Task Room_snapshot_resolves_all_members_without_changing_internal_connection_ids()
{
using var f = new Fixture();
f.Connections.OnConnected("alice-2", "alice", false);
f.Connections.RoomInfo.Users.AddRange(["bob-1", "alice-2"]);
f.Connections.RoomInfo.Ops.Add("alice-1");
using var hub = f.Hub("alice", "alice-1");
hub.Groups = new Groups();
hub.Clients = new RoomClients(f.Delivery);
var snapshot = await hub.Join("General");
Assert.Equal(["bob", "alice"], snapshot.UserNames);
Assert.Equal(["bob-1", "alice-2"], snapshot.Users);
Assert.Equal(["alice-1"], snapshot.Ops);
Assert.Null(f.Connections.RoomInfo.UserNames);
Assert.NotSame(f.Connections.RoomInfo.Users, snapshot.Users);
Assert.Same(snapshot, Assert.Single(f.Delivery.Messages).Arguments[0]);
}
private sealed class Groups : IGroupManager
{
public Task AddToGroupAsync(string connectionId, string groupName, CancellationToken ct = default) =>
Task.CompletedTask;
public Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken ct = default) =>
throw new NotSupportedException();
}
private sealed class RoomClients(RecordingCallHub delivery) : IHubCallerClients
{
public IClientProxy Caller => delivery.Client("alice-1");
public IClientProxy All => throw new NotSupportedException();
public IClientProxy Others => throw new NotSupportedException();
public IClientProxy AllExcept(IReadOnlyList<string> ids) => throw new NotSupportedException();
public IClientProxy Client(string id) => throw new NotSupportedException();
public IClientProxy Clients(IReadOnlyList<string> ids) => throw new NotSupportedException();
public IClientProxy Group(string name) => throw new NotSupportedException();
public IClientProxy GroupExcept(string name, IReadOnlyList<string> ids) => throw new NotSupportedException();
public IClientProxy Groups(IReadOnlyList<string> names) => throw new NotSupportedException();
public IClientProxy OthersInGroup(string name) => throw new NotSupportedException();
public IClientProxy User(string id) => throw new NotSupportedException();
public IClientProxy Users(IReadOnlyList<string> ids) => throw new NotSupportedException();
}
[Fact]
public async Task Invitation_requires_existing_accounts_presence_and_the_authenticated_connection()
{
@ -174,6 +219,7 @@ public sealed class CallHubTests
private sealed class Connections : IConnexionManager
{
public HashSet<string> Present { get; } = ["alice", "bob"];
public ChatRoomInfo RoomInfo { get; } = new() { Name = "General" };
private readonly Dictionary<string, string> _names = [];
public string GetUserName(string cxId) => _names.GetValueOrDefault(cxId)!;
public bool IsConnected(string user) => _names.ContainsValue(user);
@ -189,7 +235,11 @@ public sealed class CallHubTests
public bool DeOp(string room, string user) => throw new NotSupportedException();
public bool Hop(string room, string user) => throw new NotSupportedException();
public bool DeHop(string room, string user) => throw new NotSupportedException();
public bool TryGetChanInfo(string room, out ChatRoomInfo info) => throw new NotSupportedException();
public bool TryGetChanInfo(string room, out ChatRoomInfo info)
{
info = RoomInfo;
return room == RoomInfo.Name;
}
public IEnumerable<ChannelShortInfo> ListChannels(string pattern) => throw new NotSupportedException();
}
}