diff --git a/CHANGELOG.md b/CHANGELOG.md index 84641b65d..754ca0a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/doc/architecture/audio-video-calls.md b/doc/architecture/audio-video-calls.md index 38936102d..540c9da0d 100644 --- a/doc/architecture/audio-video-calls.md +++ b/doc/architecture/audio-video-calls.md @@ -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 ; diff --git a/src/PostIt/PostIt.Tests/CallTransportRoutingTests.cs b/src/PostIt/PostIt.Tests/CallTransportRoutingTests.cs index 370ddc2c1..2df357c97 100644 --- a/src/PostIt/PostIt.Tests/CallTransportRoutingTests.cs +++ b/src/PostIt/PostIt.Tests/CallTransportRoutingTests.cs @@ -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? Invitation; diff --git a/src/PostIt/PostIt/Helpers/ServiceCollectionHelpers.cs b/src/PostIt/PostIt/Helpers/ServiceCollectionHelpers.cs index 2c2323d44..a139971f6 100644 --- a/src/PostIt/PostIt/Helpers/ServiceCollectionHelpers.cs +++ b/src/PostIt/PostIt/Helpers/ServiceCollectionHelpers.cs @@ -85,6 +85,7 @@ public static class ServiceCollectionHelpers AddReusablePage(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/PostIt/PostIt/Models/ChatRoomInfo.cs b/src/PostIt/PostIt/Models/ChatRoomInfo.cs index 548371157..6e270bfbd 100644 --- a/src/PostIt/PostIt/Models/ChatRoomInfo.cs +++ b/src/PostIt/PostIt/Models/ChatRoomInfo.cs @@ -7,5 +7,6 @@ namespace PostIt.ViewModels.Chat { public string? Name { get; set; } public List Users { get; set; } = new(); + public List? UserNames { get; set; } } } diff --git a/src/PostIt/PostIt/ViewLocator.cs b/src/PostIt/PostIt/ViewLocator.cs index a4e026cb4..dd498ce6d 100644 --- a/src/PostIt/PostIt/ViewLocator.cs +++ b/src/PostIt/PostIt/ViewLocator.cs @@ -70,6 +70,7 @@ public class ViewLocator : IDataTemplate AdministrationPageViewModel => services.GetRequiredService(), ResourceUsageReliefPageViewModel => services.GetRequiredService(), ChatViewModel => services.GetRequiredService(), + CallPageViewModel => services.GetRequiredService(), null => new TextBlock { Text = "No view for " }, _ => new TextBlock { Text = $"No view for {data.GetType().Name}" } }; diff --git a/src/PostIt/PostIt/ViewModels/Chat/CallPageViewModel.cs b/src/PostIt/PostIt/ViewModels/Chat/CallPageViewModel.cs new file mode 100644 index 000000000..7d4a8d69d --- /dev/null +++ b/src/PostIt/PostIt/ViewModels/Chat/CallPageViewModel.cs @@ -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(); +} diff --git a/src/PostIt/PostIt/ViewModels/Chat/ChatViewModel.cs b/src/PostIt/PostIt/ViewModels/Chat/ChatViewModel.cs index 7553c16a4..c9ee665d4 100644 --- a/src/PostIt/PostIt/ViewModels/Chat/ChatViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Chat/ChatViewModel.cs @@ -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 FocusedUsers { get; set; } = _noUsers; + partial void OnFocusedUsersChanging(ObservableCollection value) => + FocusedUsers.CollectionChanged -= OnFocusedUsersCollectionChanged; + + partial void OnFocusedUsersChanged(ObservableCollection 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; diff --git a/src/PostIt/PostIt/ViewModels/Chat/LanCallViewModel.cs b/src/PostIt/PostIt/ViewModels/Chat/LanCallViewModel.cs index 545faa0b6..45175a697 100644 --- a/src/PostIt/PostIt/ViewModels/Chat/LanCallViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Chat/LanCallViewModel.cs @@ -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."; diff --git a/src/PostIt/PostIt/ViewModels/Chat/WebRtcCallViewModel.cs b/src/PostIt/PostIt/ViewModels/Chat/WebRtcCallViewModel.cs index 72dbf8ab8..f45851337 100644 --- a/src/PostIt/PostIt/ViewModels/Chat/WebRtcCallViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Chat/WebRtcCallViewModel.cs @@ -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; diff --git a/src/PostIt/PostIt/Views/Chat/CallPage.axaml b/src/PostIt/PostIt/Views/Chat/CallPage.axaml new file mode 100644 index 000000000..aae892004 --- /dev/null +++ b/src/PostIt/PostIt/Views/Chat/CallPage.axaml @@ -0,0 +1,101 @@ + + + + + + + + + +