diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8afdcb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,454 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/CollabVMClient.Desktop/CollabVMClient.Desktop.csproj b/CollabVMClient.Desktop/CollabVMClient.Desktop.csproj new file mode 100644 index 0000000..f240f2f --- /dev/null +++ b/CollabVMClient.Desktop/CollabVMClient.Desktop.csproj @@ -0,0 +1,21 @@ + + + WinExe + + net7.0 + enable + true + app.manifest + + + + + + + + + + + + diff --git a/CollabVMClient.Desktop/Program.cs b/CollabVMClient.Desktop/Program.cs new file mode 100644 index 0000000..c2050d3 --- /dev/null +++ b/CollabVMClient.Desktop/Program.cs @@ -0,0 +1,30 @@ +using System; + +using Avalonia; +using Projektanker.Icons.Avalonia; +using Projektanker.Icons.Avalonia.MaterialDesign; + +namespace CollabVMClient.Desktop; + +class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + { + IconProvider.Current + .Register(); + return AppBuilder.Configure() + .UsePlatformDetect() + .WithInterFont() + .LogToTrace(); + } + + +} diff --git a/CollabVMClient.Desktop/app.manifest b/CollabVMClient.Desktop/app.manifest new file mode 100644 index 0000000..e0ce8d0 --- /dev/null +++ b/CollabVMClient.Desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/CollabVMClient.sln b/CollabVMClient.sln new file mode 100644 index 0000000..0f1f6e7 --- /dev/null +++ b/CollabVMClient.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34018.315 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CollabVMClient", "CollabVMClient\CollabVMClient.csproj", "{74F3DDE0-C0D2-473B-942E-78EDFB956937}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CollabVMClient.Desktop", "CollabVMClient.Desktop\CollabVMClient.Desktop.csproj", "{8A36CCA1-A1F9-47B4-BA88-4768B6BDC5B9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibVLCSharp.Avalonia", "LibVLCSharp.Avalonia\LibVLCSharp.Avalonia.csproj", "{E85E9F2A-5F72-40D1-88BC-21511717BD3E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {74F3DDE0-C0D2-473B-942E-78EDFB956937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {74F3DDE0-C0D2-473B-942E-78EDFB956937}.Debug|Any CPU.Build.0 = Debug|Any CPU + {74F3DDE0-C0D2-473B-942E-78EDFB956937}.Release|Any CPU.ActiveCfg = Release|Any CPU + {74F3DDE0-C0D2-473B-942E-78EDFB956937}.Release|Any CPU.Build.0 = Release|Any CPU + {8A36CCA1-A1F9-47B4-BA88-4768B6BDC5B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8A36CCA1-A1F9-47B4-BA88-4768B6BDC5B9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8A36CCA1-A1F9-47B4-BA88-4768B6BDC5B9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8A36CCA1-A1F9-47B4-BA88-4768B6BDC5B9}.Release|Any CPU.Build.0 = Release|Any CPU + {E85E9F2A-5F72-40D1-88BC-21511717BD3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E85E9F2A-5F72-40D1-88BC-21511717BD3E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E85E9F2A-5F72-40D1-88BC-21511717BD3E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E85E9F2A-5F72-40D1-88BC-21511717BD3E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1C71D0CF-BEED-41E1-94E1-03003C3E9199} + EndGlobalSection +EndGlobal diff --git a/CollabVMClient/App.axaml b/CollabVMClient/App.axaml new file mode 100644 index 0000000..484805f --- /dev/null +++ b/CollabVMClient/App.axaml @@ -0,0 +1,10 @@ + + + + + + + diff --git a/CollabVMClient/App.axaml.cs b/CollabVMClient/App.axaml.cs new file mode 100644 index 0000000..97b23ce --- /dev/null +++ b/CollabVMClient/App.axaml.cs @@ -0,0 +1,41 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core.Plugins; +using Avalonia.Markup.Xaml; + +using CollabVMClient.ViewModels; +using CollabVMClient.Views; + +namespace CollabVMClient; + +public partial class App : Application +{ + private IConfig _config; + public IConfig Config => _config; + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + // Line below is needed to remove Avalonia data validation. + // Without this line you will get duplicate validations from both Avalonia and CT + BindingPlugins.DataValidators.RemoveAt(0); + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + this._config = Utilities.LoadConfig(); + desktop.MainWindow = new MainWindow + { + DataContext = new ServerListViewModel(this.Config) + }; + } + else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + { + + } + + base.OnFrameworkInitializationCompleted(); + } +} diff --git a/CollabVMClient/Assets/avalonia-logo.ico b/CollabVMClient/Assets/avalonia-logo.ico new file mode 100644 index 0000000..da8d49f Binary files /dev/null and b/CollabVMClient/Assets/avalonia-logo.ico differ diff --git a/CollabVMClient/CollabVMClient.csproj b/CollabVMClient/CollabVMClient.csproj new file mode 100644 index 0000000..0d3c111 --- /dev/null +++ b/CollabVMClient/CollabVMClient.csproj @@ -0,0 +1,52 @@ + + + net7.0 + enable + latest + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + True + CollabVMResources.resx + + + + + + ResXFileCodeGenerator + CollabVMResources.Designer.cs + + + \ No newline at end of file diff --git a/CollabVMClient/CollabVMResources.Designer.cs b/CollabVMClient/CollabVMResources.Designer.cs new file mode 100644 index 0000000..eb3d20d --- /dev/null +++ b/CollabVMClient/CollabVMResources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CollabVMClient { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class CollabVMResources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal CollabVMResources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CollabVMClient.CollabVMResources", typeof(CollabVMResources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] notify { + get { + object obj = ResourceManager.GetObject("notify", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/CollabVMClient/CollabVMResources.resx b/CollabVMClient/CollabVMResources.resx new file mode 100644 index 0000000..c0ec8a6 --- /dev/null +++ b/CollabVMClient/CollabVMResources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Resources\notify.ogg;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CollabVMClient/CollabVMViewer.cs b/CollabVMClient/CollabVMViewer.cs new file mode 100644 index 0000000..64176c4 --- /dev/null +++ b/CollabVMClient/CollabVMViewer.cs @@ -0,0 +1,148 @@ +using Avalonia.Controls; +using CollabVMClient.ViewModels; +using CollabVMClient.Views; +using CollabVMSharp; +using LibVLCSharp.Shared; +using MsBox.Avalonia; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CollabVMClient +{ + public class CollabVMViewer + { + private CollabVMSharp.CollabVMClient cvm; + private CollabVMScreenViewModel screen_vm; + private CollabVMScreenView screen; + private CollabVMChatViewModel chat_vm; + private CollabVMChatView chat; + private UserListViewModel users_vm; + private UserList users; + private string url; + private string node; + + public CollabVMViewer(string url, string node) + { + this.url = url; + this.node = node; + cvm = new CollabVMSharp.CollabVMClient(url, null, node); + cvm.ScreenSize += Cvm_ScreenSize; + cvm.Rect += Cvm_Rect; + cvm.Chat += Cvm_Chat; + cvm.ChatHistory += Cvm_ChatHistory; + cvm.Renamed += Cvm_Renamed; + cvm.UserJoined += Cvm_UserJoined; + cvm.UserLeft += Cvm_UserLeft; + cvm.UserRenamed += Cvm_UserRenamed; + cvm.TurnUpdate += Cvm_TurnUpdate; + screen_vm = new CollabVMScreenViewModel(node); + screen = new CollabVMScreenView(); + screen.DataContext = screen_vm; + chat = new CollabVMChatView(); + chat_vm = new CollabVMChatViewModel(node); + chat.DataContext = chat_vm; + chat.ChatSend += (s, e) => cvm.SendChat(e); + users_vm = new UserListViewModel(node); + users = new UserList(); + users.DataContext = users_vm; + // Exit if any window is closed + screen.Closed += WindowClosed; + chat.Closed += WindowClosed; + users.Closed += WindowClosed; + } + + private void Cvm_TurnUpdate(object? sender, TurnUpdateEventArgs e) + { + users_vm.ParseTurnUpdate(e); + //users.ReloadUsers(); + } + + private void Cvm_UserRenamed(object? sender, UserRenamedEventArgs e) + { + users_vm.RenameUser(e.OldName, e.NewName); + } + + private void Cvm_UserLeft(object? sender, User e) + { + users_vm.RemoveUser(e.Username); + } + + private void Cvm_UserJoined(object? sender, User e) + { + users_vm.AddUser(e.Username, e.Rank); + } + + public async Task Open() + { + try { + await cvm.Connect(); + } catch (Exception e) + { + await MessageBoxManager.GetMessageBoxStandard("CollabVM Connection Error", $"Failed to connect to the CollabVM Server at {url}:\n{e.Message}", MsBox.Avalonia.Enums.ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Error).ShowAsync(); + return false; + } + cvm.ConnectedToNode += Cvm_ConnectedToNode; + cvm.NodeConnectFailed += Cvm_NodeConnectFailed; + + return true; + } + + private void Cvm_NodeConnectFailed(object? sender, EventArgs e) + { + MessageBoxManager.GetMessageBoxStandard("CollabVM Connection Error", $"Failed to connect to the CollabVM Server at {url}:\n{node} is not a valid node on this server.", MsBox.Avalonia.Enums.ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Error).ShowAsync(); + } + + private void Cvm_ConnectedToNode(object? sender, EventArgs e) + { + screen.Show(); + chat.Show(); + users.Show(); + } + + private void WindowClosed(object? sender, EventArgs e) + { + cvm.Disconnect(); + screen.Close(); + chat.Close(); + users.Close(); + } + + private void Cvm_Renamed(object? sender, string e) + { + chat_vm.SetUsername(e); + } + + private void Cvm_ChatHistory(object? sender, ChatMessage[] e) + { + foreach (var chat in e) + { + chat_vm.AddChatMessage(chat.Username, chat.Message); + } + } + + private void Cvm_Chat(object? sender, ChatMessage e) + { + chat_vm.AddChatMessage(e.Username, e.Message); + } + + private void Cvm_ScreenSize(object? sender, ScreenSizeEventArgs e) + { + screen_vm.SetSize(e.Width, e.Height); + } + + private void Cvm_Rect(object? sender, RectEventArgs e) + { + byte[] rect = new byte[e.Data.Width * e.Data.Height * 4]; + e.Data.CloneAs().CopyPixelDataTo(rect); + screen_vm.LoadRect(rect, e.Data.Width, e.Data.Height, e.X, e.Y); + screen.RefreshScreen(); + } + } +} diff --git a/CollabVMClient/Constants.cs b/CollabVMClient/Constants.cs new file mode 100644 index 0000000..4c82d3e --- /dev/null +++ b/CollabVMClient/Constants.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CollabVMClient +{ + public static class Constants + { + public static string UserVMNodeList => "https://computernewb.com/collab-vm/user-vm/nodelist.json"; + public static IConfig DefaultConfig => new IConfig + { + Nodes = new string[] { + "wss://computernewb.com/collab-vm/vm0", + "wss://computernewb.com/collab-vm/vm1", + "wss://computernewb.com/collab-vm/vm2", + "wss://computernewb.com/collab-vm/vm3", + "wss://computernewb.com/collab-vm/vm4", + "wss://computernewb.com/collab-vm/vm5", + "wss://computernewb.com/collab-vm/vm6", + "wss://computernewb.com/collab-vm/vm7", + "wss://computernewb.com/collab-vm/vm8", + } + }; + } +} diff --git a/CollabVMClient/IConfig.cs b/CollabVMClient/IConfig.cs new file mode 100644 index 0000000..0cbee85 --- /dev/null +++ b/CollabVMClient/IConfig.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. + + +namespace CollabVMClient +{ + public class IConfig + { + public string[] Nodes { get; set; } + } +} diff --git a/CollabVMClient/Resources/notify.ogg b/CollabVMClient/Resources/notify.ogg new file mode 100644 index 0000000..c6663d3 Binary files /dev/null and b/CollabVMClient/Resources/notify.ogg differ diff --git a/CollabVMClient/Utilities.cs b/CollabVMClient/Utilities.cs new file mode 100644 index 0000000..b58a230 --- /dev/null +++ b/CollabVMClient/Utilities.cs @@ -0,0 +1,59 @@ +using CollabVMClient.ViewModels; +using CollabVMSharp; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace CollabVMClient +{ + public static class Utilities + { + /// + /// Return view models for each node a cvm server offers + /// + public static async Task GetNodes(string url) + { + var cvm = new CollabVMSharp.CollabVMClient(url); + await cvm.Connect(); + var nodes = await cvm.ListVMs(); + await cvm.Disconnect(); + var nodelist = new List(); + foreach (var node in nodes) + { + using var ms = new MemoryStream(node.Thumbnail); + nodelist.Add(new CVMNodeViewModel(url, node.ID, node.Name, new Avalonia.Media.Imaging.Bitmap(ms))); + } + return nodelist.ToArray(); + } + + public static void WriteDefaultConfig() + { + var cj = JsonSerializer.Serialize(Constants.DefaultConfig); + File.WriteAllText("config.json", cj); + } + + public static IConfig LoadConfig() + { + try + { + var cr = File.ReadAllText("config.json"); + var c = JsonSerializer.Deserialize(cr); + if (c == null) + { + Utilities.WriteDefaultConfig(); + return Constants.DefaultConfig; + } + else return c; + } + catch (FileNotFoundException) + { + Utilities.WriteDefaultConfig(); + return Constants.DefaultConfig; + } + } + } +} diff --git a/CollabVMClient/ViewModels/CVMNodeViewModel.cs b/CollabVMClient/ViewModels/CVMNodeViewModel.cs new file mode 100644 index 0000000..5044e6d --- /dev/null +++ b/CollabVMClient/ViewModels/CVMNodeViewModel.cs @@ -0,0 +1,25 @@ +using Avalonia.Media.Imaging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CollabVMClient.ViewModels +{ + public class CVMNodeViewModel : ViewModelBase + { + public string URL { get; set; } + public string ID { get; set; } + public string Name { get; set; } + public Bitmap Thumbnail { get; set; } + + public CVMNodeViewModel(string url, string iD, string name, Bitmap thumbnail) + { + URL = url; + ID = iD; + Name = name; + Thumbnail = thumbnail; + } + } +} diff --git a/CollabVMClient/ViewModels/ChatMessageViewModel.cs b/CollabVMClient/ViewModels/ChatMessageViewModel.cs new file mode 100644 index 0000000..88f901a --- /dev/null +++ b/CollabVMClient/ViewModels/ChatMessageViewModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CollabVMClient.ViewModels +{ + internal class ChatMessageViewModel : ViewModelBase + { + private string _username; + private string _message; + + public string Username => _username; + public string Message => _message; + public string HTML => string.IsNullOrEmpty(_username) ? _message : $"{_username}> {_message}"; + public ChatMessageViewModel(string username, string message) + { + this._username = username; + this._message = message; + } + } +} \ No newline at end of file diff --git a/CollabVMClient/ViewModels/CollabVMChatViewModel.cs b/CollabVMClient/ViewModels/CollabVMChatViewModel.cs new file mode 100644 index 0000000..26d8816 --- /dev/null +++ b/CollabVMClient/ViewModels/CollabVMChatViewModel.cs @@ -0,0 +1,36 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using LibVLCSharp.Shared; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CollabVMClient.ViewModels +{ + internal partial class CollabVMChatViewModel : ViewModelBase + { + public ObservableCollection ChatMessages { get; } = new ObservableCollection(); + [ObservableProperty] private string username; + [ObservableProperty] private string id; + public string Title => $"CollabVM - Chat ({id})"; + + + public void AddChatMessage(string username, string message) + { + ChatMessages.Add(new ChatMessageViewModel(username, message)); + } + + public CollabVMChatViewModel(string id) + { + this.Username = "username"; + this.Id = id; + } + + public void SetUsername(string username) + { + this.Username = username; + } + } +} diff --git a/CollabVMClient/ViewModels/CollabVMScreenViewModel.cs b/CollabVMClient/ViewModels/CollabVMScreenViewModel.cs new file mode 100644 index 0000000..731d712 --- /dev/null +++ b/CollabVMClient/ViewModels/CollabVMScreenViewModel.cs @@ -0,0 +1,51 @@ +using Avalonia.Media.Imaging; +using Avalonia.Platform; +using SixLabors.ImageSharp.PixelFormats; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using SixLabors.ImageSharp; +using SixLabors.ImageSharp.Processing; +using Avalonia.Media; +using Avalonia.Controls; +using CommunityToolkit.Mvvm.ComponentModel; + +namespace CollabVMClient.ViewModels +{ + internal partial class CollabVMScreenViewModel : ViewModelBase + { + public WriteableBitmap Framebuffer { get; set; } + [ObservableProperty] private string id; + [ObservableProperty] private int width; + [ObservableProperty] private int height; + public string Title => $"CollabVM - Screen ({id})"; + public CollabVMScreenViewModel(string id) + { + this.Id = id; + Framebuffer = new WriteableBitmap(new Avalonia.PixelSize(1, 1), new Avalonia.Vector(1, 1)); + } + public void SetSize(int width, int height) + { + this.Width = width; + this.Height = height; + Framebuffer = new WriteableBitmap(new Avalonia.PixelSize(width, height), new Avalonia.Vector(96.0f, 96.0f), PixelFormat.Rgba8888); + } + public void LoadRect(byte[] rect, int width, int height, int x, int y) + { + // writing this method made me suicidal + var l = Framebuffer.Lock(); + var byteswritten = 0; + for (var i = 0; i < height; i++) + { + Marshal.Copy(rect, byteswritten, IntPtr.Add(l.Address, (int)(4 * ((y + i) * Framebuffer.Size.Width + x))), width * 4); + byteswritten += width * 4; + } + l.Dispose(); + + } + } +} diff --git a/CollabVMClient/ViewModels/ServerListViewModel.cs b/CollabVMClient/ViewModels/ServerListViewModel.cs new file mode 100644 index 0000000..830e5d5 --- /dev/null +++ b/CollabVMClient/ViewModels/ServerListViewModel.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Reactive; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Avalonia.Controls; +using Avalonia.Media.Imaging; +using CollabVMClient.Views; +using MsBox.Avalonia; + +namespace CollabVMClient.ViewModels +{ + internal class ServerListViewModel : ViewModelBase + { + private IConfig config; + private CancellationTokenSource populateListCt; + public string ServerListHeader => "Servers"; + public ObservableCollection Nodes { get; } = new ObservableCollection(); + + public ServerListViewModel(IConfig config) + { + this.config = config; + populateListCt = new(); + PopulateList(config.Nodes, populateListCt.Token); + } + + public async Task PopulateList(string[] urls, CancellationToken token) + { + foreach (var url in urls) + { + if (token.IsCancellationRequested) return; + await Multicollab(url, token); + } + } + + public async Task Multicollab(string url, CancellationToken token) + { + + CVMNodeViewModel[] nodes; + try + { + nodes = await Utilities.GetNodes(url); + } catch (Exception e) + { + await MessageBoxManager.GetMessageBoxStandard("CollabVM Connection Error", $"Failed to connect to the CollabVM Server at {url}:\n{e.Message}", MsBox.Avalonia.Enums.ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Error).ShowAsync(); + return; + } + foreach (var node in nodes) + { + if (token.IsCancellationRequested) return; + Nodes.Add(node); + var newNodes = Nodes.OrderBy(n => n.ID).ToArray(); + Nodes.Clear(); + foreach (CVMNodeViewModel m in newNodes) + { + Nodes.Add(m); + } + } + } + + public void RefreshList() + { + populateListCt.Cancel(); + populateListCt = new(); + Nodes.Clear(); + PopulateList(config.Nodes, populateListCt.Token); + } + + public bool CanRefreshList() => true; + + public async void AddServer(object parent) + { + var win = new AddServer(); + await win.ShowDialog((Window)parent); + if (win.URL != null) Multicollab(win.URL, populateListCt.Token); + } + + public bool CanAddServer() => true; + } +} diff --git a/CollabVMClient/ViewModels/UserListViewModel.cs b/CollabVMClient/ViewModels/UserListViewModel.cs new file mode 100644 index 0000000..251ff2b --- /dev/null +++ b/CollabVMClient/ViewModels/UserListViewModel.cs @@ -0,0 +1,77 @@ +using CollabVMSharp; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CollabVMClient.ViewModels +{ + internal class UserListViewModel : ViewModelBase + { + public ObservableCollection Users { get; } = new ObservableCollection(); + private string id; + public string Title => $"CollabVM - Users ({id})"; + + public UserListViewModel(string id) + { + this.id = id; + } + + public void AddUser(string username, Rank rank) + { + // Needed if a user ranks up + RemoveUser(username); + Users.Add(new UserViewModel(username, rank)); + } + + public void RenameUser(string username, string newName) + { + var user = Users.First(u => u.Username == username); + user.Rename(newName); + } + + public void RemoveUser(string username) + { + UserViewModel user; + try + { + user = Users.First(u => u.Username == username); + } catch (InvalidOperationException ex) + { + // just ignore it + return; + } + Users.Remove(user); + } + + public void ParseTurnUpdate(TurnUpdateEventArgs e) + { + foreach (var user in Users) + { + user.SetTurnStatus(TurnStatus.None); + } + if (e.Queue.Length == 0) return; + var currentTurningUser = Users.First(u => u.Username == e.Queue[0].Username); + currentTurningUser.SetTurnStatus(TurnStatus.HasTurn); + for (int i = 1; i < e.Queue.Length; i++) { + var user = Users.First(u => u.Username == e.Queue[i].Username); + user.SetTurnStatus(TurnStatus.Waiting); + } + var newUsers = Users.OrderByDescending(i => GetSortIndex(i, e.Queue)).ToArray(); + Users.Clear(); + foreach (UserViewModel u in newUsers) + { + Users.Add(u); + } + } + + public int GetSortIndex(UserViewModel u, User[] queue) + { + int i = Array.FindIndex(queue, x => x.Username == u.Username); + if (i == -1) return -1; + else return queue.Length - i; + } + } +} diff --git a/CollabVMClient/ViewModels/UserViewModel.cs b/CollabVMClient/ViewModels/UserViewModel.cs new file mode 100644 index 0000000..ed2bbbd --- /dev/null +++ b/CollabVMClient/ViewModels/UserViewModel.cs @@ -0,0 +1,51 @@ +using Avalonia.Media; +using CollabVMSharp; +using CommunityToolkit.Mvvm.ComponentModel; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CollabVMClient.ViewModels +{ + internal partial class UserViewModel : ViewModelBase + { + [ObservableProperty] private string username; + private Rank rank; + private TurnStatus turn; + + public IBrush Foreground => rank switch + { + Rank.Unregistered => Brush.Parse("Black"), + Rank.Moderator => Brush.Parse("Green"), + Rank.Admin => Brush.Parse("Red"), + }; + + [ObservableProperty] private IBrush background; + + public void Rename(string newName) + { + Username = newName; + } + + public UserViewModel(string username, Rank rank) + { + Username = username; + this.rank = rank; + } + + + public void SetTurnStatus(TurnStatus turn) + { + this.turn = turn; + Background = turn switch + { + TurnStatus.None => Brush.Parse("White"), + TurnStatus.Waiting => Brush.Parse("Yellow"), + TurnStatus.HasTurn => Brush.Parse("SkyBlue"), + }; + } + } +} diff --git a/CollabVMClient/ViewModels/ViewModelBase.cs b/CollabVMClient/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..152e12b --- /dev/null +++ b/CollabVMClient/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace CollabVMClient.ViewModels; + +public class ViewModelBase : ObservableObject +{ +} diff --git a/CollabVMClient/Views/AddServer.axaml b/CollabVMClient/Views/AddServer.axaml new file mode 100644 index 0000000..23175df --- /dev/null +++ b/CollabVMClient/Views/AddServer.axaml @@ -0,0 +1,17 @@ + + + + + + + + + + diff --git a/CollabVMClient/Views/AddServer.axaml.cs b/CollabVMClient/Views/AddServer.axaml.cs new file mode 100644 index 0000000..d434f07 --- /dev/null +++ b/CollabVMClient/Views/AddServer.axaml.cs @@ -0,0 +1,35 @@ +using Avalonia.Controls; +using MsBox.Avalonia; +using System; + +namespace CollabVMClient.Views +{ + public partial class AddServer : Window + { + private string? url = null; + public string? URL => url; + public AddServer() + { + InitializeComponent(); + cancel.Click += Cancel_Click; + confirm.Click += Confirm_Click; + } + + private void Confirm_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + Uri u; + if (!Uri.TryCreate(urlTextBox.Text, UriKind.Absolute, out u) || (u.Scheme != "ws" && u.Scheme != "wss")) + { + MessageBoxManager.GetMessageBoxStandard("Error", "URL must be a valid WebSocket url.", MsBox.Avalonia.Enums.ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Error).ShowWindowDialogAsync(this); + return; + } + url = urlTextBox.Text; + Close(); + } + + private void Cancel_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + Close(); + } + } +} diff --git a/CollabVMClient/Views/CVMNode.axaml b/CollabVMClient/Views/CVMNode.axaml new file mode 100644 index 0000000..60fffde --- /dev/null +++ b/CollabVMClient/Views/CVMNode.axaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + diff --git a/CollabVMClient/Views/CVMNode.axaml.cs b/CollabVMClient/Views/CVMNode.axaml.cs new file mode 100644 index 0000000..5985024 --- /dev/null +++ b/CollabVMClient/Views/CVMNode.axaml.cs @@ -0,0 +1,21 @@ +using Avalonia.Controls; +using CollabVMClient.ViewModels; + +namespace CollabVMClient.Views +{ + public partial class CVMNode : UserControl + { + CVMNodeViewModel VM => ((CVMNodeViewModel)DataContext); + public CVMNode() + { + InitializeComponent(); + ConnectButton.Click += ConnectButton_Click; + } + + private void ConnectButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + var v = new CollabVMViewer(VM.URL, VM.ID); + v.Open(); + } + } +} diff --git a/CollabVMClient/Views/CollabVMChatView.axaml b/CollabVMClient/Views/CollabVMChatView.axaml new file mode 100644 index 0000000..962fde3 --- /dev/null +++ b/CollabVMClient/Views/CollabVMChatView.axaml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/CollabVMClient/Views/CollabVMChatView.axaml.cs b/CollabVMClient/Views/CollabVMChatView.axaml.cs new file mode 100644 index 0000000..4ce1f51 --- /dev/null +++ b/CollabVMClient/Views/CollabVMChatView.axaml.cs @@ -0,0 +1,27 @@ +using Avalonia.Controls; +using System; +using System.Linq; + +namespace CollabVMClient.Views +{ + public partial class CollabVMChatView : Window + { + public event EventHandler ChatSend; + public CollabVMChatView() + { + InitializeComponent(); + chatInput.KeyDown += (s, e) => + { + if (e.Key == Avalonia.Input.Key.Return) SendChat(); + }; + sendBtn.Click += (s, e) => SendChat(); + } + + private void SendChat() + { + if (string.IsNullOrEmpty(chatInput.Text) || chatInput.Text.ToCharArray().All(c => c == ' ')) return; + ChatSend.Invoke(this, chatInput.Text); + chatInput.Text = ""; + } + } +} diff --git a/CollabVMClient/Views/CollabVMScreenView.axaml b/CollabVMClient/Views/CollabVMScreenView.axaml new file mode 100644 index 0000000..d613c2c --- /dev/null +++ b/CollabVMClient/Views/CollabVMScreenView.axaml @@ -0,0 +1,10 @@ + + + diff --git a/CollabVMClient/Views/CollabVMScreenView.axaml.cs b/CollabVMClient/Views/CollabVMScreenView.axaml.cs new file mode 100644 index 0000000..3db7acb --- /dev/null +++ b/CollabVMClient/Views/CollabVMScreenView.axaml.cs @@ -0,0 +1,19 @@ +using Avalonia.Controls; +using CollabVMClient.ViewModels; + +namespace CollabVMClient.Views +{ + public partial class CollabVMScreenView : Window + { + public CollabVMScreenView() + { + InitializeComponent(); + } + + public void RefreshScreen() + { + screen.Source = ((CollabVMScreenViewModel)DataContext).Framebuffer; + screen.InvalidateVisual(); + } + } +} diff --git a/CollabVMClient/Views/DirectConnect.axaml b/CollabVMClient/Views/DirectConnect.axaml new file mode 100644 index 0000000..fe230c6 --- /dev/null +++ b/CollabVMClient/Views/DirectConnect.axaml @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/CollabVMClient/Views/DirectConnect.axaml.cs b/CollabVMClient/Views/DirectConnect.axaml.cs new file mode 100644 index 0000000..c958b4b --- /dev/null +++ b/CollabVMClient/Views/DirectConnect.axaml.cs @@ -0,0 +1,39 @@ +using Avalonia.Controls; +using MsBox.Avalonia; +using System; + +namespace CollabVMClient.Views +{ + public partial class DirectConnect : Window + { + public DirectConnect() + { + InitializeComponent(); + connectBtn.Click += ConnectBtn_Click; + cancelBtn.Click += CancelBtn_Click; + } + + private void CancelBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + Close(); + } + + private void ConnectBtn_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + Uri u; + if (!Uri.TryCreate(url.Text, UriKind.Absolute, out u) || (u.Scheme != "ws" && u.Scheme != "wss")) + { + MessageBoxManager.GetMessageBoxStandard("Error", "URL must be a valid WebSocket url.", MsBox.Avalonia.Enums.ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Error).ShowWindowDialogAsync(this); + return; + } + if (string.IsNullOrEmpty(node.Text)) + { + MessageBoxManager.GetMessageBoxStandard("Error", "Node must not be empty", MsBox.Avalonia.Enums.ButtonEnum.Ok, MsBox.Avalonia.Enums.Icon.Error).ShowWindowDialogAsync(this); + return; + } + var cvm = new CollabVMViewer(url.Text, node.Text); + cvm.Open(); + Close(); + } + } +} diff --git a/CollabVMClient/Views/MainWindow.axaml b/CollabVMClient/Views/MainWindow.axaml new file mode 100644 index 0000000..b5bb866 --- /dev/null +++ b/CollabVMClient/Views/MainWindow.axaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CollabVMClient/Views/MainWindow.axaml.cs b/CollabVMClient/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..fbc0494 --- /dev/null +++ b/CollabVMClient/Views/MainWindow.axaml.cs @@ -0,0 +1,27 @@ +using Avalonia.Controls; +using System.IO; +using System.Text.Json; + +namespace CollabVMClient.Views; + +public partial class MainWindow : Window +{ + + public MainWindow() + { + InitializeComponent(); + directConnect.Click += DirectConnect_Click; + exit.Click += Exit_Click; + addServer.CommandParameter = this; + } + + private void Exit_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + Close(); + } + + private void DirectConnect_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + { + new DirectConnect().ShowDialog(this); + } +} diff --git a/CollabVMClient/Views/UserList.axaml b/CollabVMClient/Views/UserList.axaml new file mode 100644 index 0000000..422fe77 --- /dev/null +++ b/CollabVMClient/Views/UserList.axaml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + diff --git a/CollabVMClient/Views/UserList.axaml.cs b/CollabVMClient/Views/UserList.axaml.cs new file mode 100644 index 0000000..6a2277b --- /dev/null +++ b/CollabVMClient/Views/UserList.axaml.cs @@ -0,0 +1,14 @@ +using Avalonia.Controls; + +namespace CollabVMClient.Views +{ + public partial class UserList : Window + { + public UserList() + { + InitializeComponent(); + } + + public void ReloadUsers() => userList.InvalidateArrange(); + } +} diff --git a/Directory.Build.props b/Directory.Build.props new file mode 100644 index 0000000..5d8722e --- /dev/null +++ b/Directory.Build.props @@ -0,0 +1,6 @@ + + + enable + 11.0.2 + + diff --git a/LibVLCSharp.Avalonia/LibVLCSharp.Avalonia.csproj b/LibVLCSharp.Avalonia/LibVLCSharp.Avalonia.csproj new file mode 100644 index 0000000..f001765 --- /dev/null +++ b/LibVLCSharp.Avalonia/LibVLCSharp.Avalonia.csproj @@ -0,0 +1,25 @@ + + + LibVLCSharp.Avalonia + Avalonia integration for LibVLCSharp + LibVLCSharp is a cross-platform audio and video API for .NET platforms based on VideoLAN's LibVLC Library. It provides a comprehensive multimedia API that can be used across mobile, server and desktop to render video and output audio. Mono, .NET Framework and .NET Core runtimes are supported. + +LibVLCSharp.Avalonia contains the integration with Avalonia. +This package contains the views that allows to display a video played with LibVLCSharp +in a Avalonia app. + +This package depends on LibVLCSharp as well as Avalonia. + +LibVLC needs to be installed separately, see VideoLAN.LibVLC.* packages. + + net6.0 + LibVLCSharp.Avalonia + LibVLCSharp.Avalonia + $(PackageTags);avalonia + + + + + + + diff --git a/LibVLCSharp.Avalonia/README.md b/LibVLCSharp.Avalonia/README.md new file mode 100644 index 0000000..f57824e --- /dev/null +++ b/LibVLCSharp.Avalonia/README.md @@ -0,0 +1,18 @@ +# LibVLCSharp.Avalonia + +The official [Avalonia](https://github.com/AvaloniaUI/Avalonia) views for [LibVLCSharp](../LibVLCSharp/README.md). + +This package contains the views that allows to display a video played with [LibVLCSharp](../LibVLCSharp/README.md) +in an Avalonia app. + +This package depends on [LibVLCSharp](../LibVLCSharp/README.md) as well as [Avalonia](https://github.com/AvaloniaUI/Avalonia). + +Supported frameworks: + +- netstandard2.0 + +Supported platforms: + +- Windows +- MacOS +- Linux diff --git a/LibVLCSharp.Avalonia/VideoView.cs b/LibVLCSharp.Avalonia/VideoView.cs new file mode 100644 index 0000000..541523d --- /dev/null +++ b/LibVLCSharp.Avalonia/VideoView.cs @@ -0,0 +1,115 @@ +using System; +using System.Runtime.InteropServices; +using Avalonia; +using Avalonia.Controls; +using Avalonia.Data; +using Avalonia.Platform; +using LibVLCSharp.Shared; + +namespace LibVLCSharp.Avalonia +{ + /// + /// Avalonia VideoView for Windows, Linux and Mac. + /// + public class VideoView : NativeControlHost + { + private IPlatformHandle? _platformHandle = null; + private MediaPlayer? _mediaPlayer = null; + + /// + /// MediaPlayer Data Bound property + /// + /// + /// Defines the property. + /// + public static readonly DirectProperty MediaPlayerProperty = + AvaloniaProperty.RegisterDirect( + nameof(MediaPlayer), + o => o.MediaPlayer, + (o, v) => o.MediaPlayer = v, + defaultBindingMode: BindingMode.TwoWay); + + /// + /// Gets or sets the MediaPlayer that will be displayed. + /// + public MediaPlayer? MediaPlayer + { + get { return _mediaPlayer; } + set + { + if (ReferenceEquals(_mediaPlayer, value)) + { + return; + } + + Detach(); + _mediaPlayer = value; + Attach(); + } + } + + private void Attach() + { + if(_mediaPlayer == null || _platformHandle == null || !IsInitialized) + return; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + _mediaPlayer.Hwnd = _platformHandle.Handle; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + _mediaPlayer.XWindow = (uint)_platformHandle.Handle; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + _mediaPlayer.NsObject = _platformHandle.Handle; + } + } + + private void Detach() + { + if (_mediaPlayer == null) + return; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + _mediaPlayer.Hwnd = IntPtr.Zero; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + _mediaPlayer.XWindow = 0; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + _mediaPlayer.NsObject = IntPtr.Zero; + } + } + + /// + protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent) + { + _platformHandle = base.CreateNativeControlCore(parent); + + if (_mediaPlayer == null) + return _platformHandle; + + Attach(); + + return _platformHandle; + } + + /// + protected override void DestroyNativeControlCore(IPlatformHandle control) + { + Detach(); + + base.DestroyNativeControlCore(control); + + if (_platformHandle != null) + { + _platformHandle = null; + } + } + } +} diff --git a/LibVLCSharp.Avalonia/nuget.config b/LibVLCSharp.Avalonia/nuget.config new file mode 100644 index 0000000..2215f14 --- /dev/null +++ b/LibVLCSharp.Avalonia/nuget.config @@ -0,0 +1,6 @@ + + + + + +