Skip to content

Commit

Permalink
Merge pull request #344 from xibosignage/develop
Browse files Browse the repository at this point in the history
v4 R406
  • Loading branch information
dasgarner authored Dec 17, 2024
2 parents d528a2f + 5327009 commit 9509081
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 76 deletions.
6 changes: 4 additions & 2 deletions Adspace/ExchangeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private List<Ad> Request(Url url, Ad wrappedAd)

// Get and impression/error URLs included with this wrap
XmlNode errorUrlNode = wrapper.SelectSingleNode("./Error");
if (errorUrlNode != null)
if (errorUrlNode != null && !string.IsNullOrEmpty(errorUrlNode.InnerText))
{
ad.ErrorUrls.Add(errorUrlNode.InnerText.Trim());
}
Expand Down Expand Up @@ -708,7 +708,7 @@ private List<Ad> Request(Url url, Ad wrappedAd)

// Get and impression/error URLs included with this wrap
XmlNode errorUrlNode = inlineNode.SelectSingleNode("./Error");
if (errorUrlNode != null)
if (errorUrlNode != null && !string.IsNullOrEmpty(errorUrlNode.InnerText))
{
string errorUrl = errorUrlNode.InnerText.Trim();
if (errorUrl != "about:blank")
Expand Down Expand Up @@ -920,6 +920,8 @@ private void ReportError(List<string> urls, int errorCode)
{
foreach (string url in urls)
{
if (string.IsNullOrEmpty(url)) continue;

try
{
// Macros
Expand Down
35 changes: 35 additions & 0 deletions Helpers/CefsharpLifespanHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
* This file is part of Xibo.
*
* Xibo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* Xibo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
using CefSharp;

namespace XiboClient.Helpers
{
public class CefsharpLifespanHandler : CefSharp.Handler.LifeSpanHandler
{
protected override bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
newBrowser = null;

// Return true to cancel the popup creation
return true;
}
}
}
4 changes: 2 additions & 2 deletions Helpers/XiboRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public XiboRequestHandler(bool isConfigureProxy)
_isConfigureProxy = isConfigureProxy;
}

protected override void OnRenderProcessTerminated(IWebBrowser chromiumWebBrowser, IBrowser browser, CefTerminationStatus status)
protected override void OnRenderProcessTerminated(IWebBrowser chromiumWebBrowser, IBrowser browser, CefTerminationStatus status, int errorCode, string errorString)
{
// If the render process crashed, we should just log.
Trace.WriteLine(new LogMessage("XiboRequestHandler", "OnRenderProcessTerminate: a cef sub process has terminated. " + status.ToString()), LogType.Error.ToString());
Trace.WriteLine(new LogMessage("XiboRequestHandler", "OnRenderProcessTerminate: a cef sub process has terminated. " + status.ToString() + ", message: " + errorString), LogType.Error.ToString());
}

protected override bool GetAuthCredentials(IWebBrowser chromiumWebBrowser, IBrowser browser, string originUrl, bool isProxy, string host, int port, string realm, string scheme, IAuthCallback callback)
Expand Down
6 changes: 3 additions & 3 deletions Logic/ApplicationSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand Down Expand Up @@ -52,9 +52,9 @@ private static readonly Lazy<ApplicationSettings>
/// </summary>
private List<string> ExcludedProperties;

public string ClientVersion { get; } = "4 R402.1";
public string ClientVersion { get; } = "4 R404.1";
public string Version { get; } = "7";
public int ClientCodeVersion { get; } = 402;
public int ClientCodeVersion { get; } = 404;

private ApplicationSettings()
{
Expand Down
27 changes: 27 additions & 0 deletions Logic/HardwareKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/
using Newtonsoft.Json;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.OpenSsl;
Expand All @@ -29,12 +30,15 @@
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace XiboClient
{
class HardwareKey
{
private static object _locker = new object();
private static string operatingSystemJson = string.Empty;

private static AsymmetricCipherKeyPair _keys;
private string _hardwareKey;
Expand Down Expand Up @@ -301,5 +305,28 @@ public static string LocalIPAddress()
.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork)
.ToString();
}

public static string OperatingSystemAsJson()
{
if (string.IsNullOrEmpty(operatingSystemJson))
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
using (JsonWriter writer = new JsonTextWriter(sw))
{
writer.Formatting = Formatting.None;
writer.WriteStartObject();
writer.WritePropertyName("version");
writer.WriteValue(Environment.OSVersion.Platform.ToString());
writer.WritePropertyName("sdk");
writer.WriteValue(Environment.OSVersion.Version.ToString());
writer.WriteEndObject();
}

operatingSystemJson = sb.ToString();
}

return operatingSystemJson;
}
}
}
4 changes: 2 additions & 2 deletions OptionsForm.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void Button_Connect_Click(object sender, RoutedEventArgs e)
"windows",
ApplicationSettings.Default.ClientVersion,
ApplicationSettings.Default.ClientCodeVersion,
Environment.OSVersion.ToString(),
HardwareKey.OperatingSystemAsJson(),
this.hardwareKey.MacAddress,
this.hardwareKey.Channel,
this.hardwareKey.getXmrPublicKey(),
Expand Down Expand Up @@ -410,7 +410,7 @@ private async void AuthCodeTimer_Elapsed(object sender, System.Timers.ElapsedEve
"windows",
ApplicationSettings.Default.ClientVersion,
ApplicationSettings.Default.ClientCodeVersion,
Environment.OSVersion.ToString(),
HardwareKey.OperatingSystemAsJson(),
this.hardwareKey.MacAddress,
this.hardwareKey.Channel,
this.hardwareKey.getXmrPublicKey(),
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Xibo Digital Signage")]
[assembly: AssemblyProduct("Xibo")]
[assembly: AssemblyCopyright("Copyright © Xibo Signage Ltd 2023")]
[assembly: AssemblyCopyright("Copyright © Xibo Signage Ltd 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down Expand Up @@ -49,6 +49,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.402.1.0")]
[assembly: AssemblyFileVersion("4.402.1.0")]
[assembly: AssemblyVersion("4.404.1.0")]
[assembly: AssemblyFileVersion("4.404.1.0")]
[assembly: Guid("3bd467a4-4ef9-466a-b156-a79c13a863f7")]
2 changes: 1 addition & 1 deletion Rendering/Layout.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2022 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand Down
7 changes: 6 additions & 1 deletion Rendering/Region.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ private void StopMedia(Media media)
// Call any error urls.
foreach (string url in media.AdspaceExchangeErrorUrls)
{
if (string.IsNullOrEmpty(url)) continue;

try
{
// Macros
Expand All @@ -756,7 +758,10 @@ private void StopMedia(Media media)
// Call the URL
new Flurl.Url(uri).WithTimeout(10).GetAsync().ContinueWith(t =>
{
LogMessage.Error("Region", "StopMedia", "failed to report error to " + uri);
if (t.Exception != null)
{
LogMessage.Error("Region", "StopMedia", "failed to report error to " + uri + ", e: " + t.Exception.Message);
}
},
TaskContinuationOptions.OnlyOnFaulted);
}
Expand Down
36 changes: 24 additions & 12 deletions Rendering/Video.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -139,7 +139,15 @@ private void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
if (_duration == 0)
{
// Add the duration of the video
watchmanTtl = watchmanTtl.Add(this.mediaElement.NaturalDuration.TimeSpan);
if (this.mediaElement.NaturalDuration == System.Windows.Duration.Automatic)
{
// This is strange, so we will just log and keep the watchman duration at 60 seconds
LogMessage.Audit("Video", "MediaElement_MediaOpened", "Duration not detected on open");
}
else
{
watchmanTtl = watchmanTtl.Add(this.mediaElement.NaturalDuration.TimeSpan);
}
}
else
{
Expand Down Expand Up @@ -217,16 +225,6 @@ private void MediaElement_Loaded(object sender, RoutedEventArgs e)
{
Trace.WriteLine(new LogMessage("Video", "MediaElement_Loaded: " + this.Id + " Control loaded, calling Play."), LogType.Audit.ToString());

try
{
this.mediaElement.Play();
}
catch (Exception ex)
{
// Problem calling play, we should expire.
Trace.WriteLine(new LogMessage("Video", "MediaElement_Loaded: " + this.Id + " Media Failed. E = " + ex.Message), LogType.Error.ToString());
}

// We make a watchman to check that the video actually gets loaded.
_StartWatchman = new DispatcherTimer { Interval = TimeSpan.FromSeconds(ApplicationSettings.Default.VideoStartTimeout) };
_StartWatchman.Tick += (timerSender, args) =>
Expand All @@ -248,6 +246,20 @@ private void MediaElement_Loaded(object sender, RoutedEventArgs e)
};

_StartWatchman.Start();

// Actually play the video
try
{
this.mediaElement.Play();
}
catch (Exception ex)
{
// Problem calling play, we should expire.
Trace.WriteLine(new LogMessage("Video", "MediaElement_Loaded: " + this.Id + " Media Failed. E = " + ex.Message), LogType.Error.ToString());

// Cancel the watchman
_StartWatchman.Stop();
}
}

#endregion
Expand Down
11 changes: 6 additions & 5 deletions Rendering/WebCef.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2021 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand Down Expand Up @@ -60,6 +60,7 @@ public override void RenderMedia(double position)
Name = "region_" + this.regionId
};
webView.RequestContext = new CefSharp.RequestContext(requestContextSettings);
webView.LifeSpanHandler = new CefsharpLifespanHandler();

// Configure run time CEF settings?
CefSharp.Cef.UIThreadTaskFactory.StartNew(() =>
Expand All @@ -72,14 +73,14 @@ public override void RenderMedia(double position)
// NTLM/Auth Server White Lists.
if (!string.IsNullOrEmpty(ApplicationSettings.Default.AuthServerWhitelist))
{
if (!webView.RequestContext.SetPreference("auth.server_whitelist", ApplicationSettings.Default.AuthServerWhitelist, out string error))
if (!webView.RequestContext.SetPreference("auth.server_allowlist", ApplicationSettings.Default.AuthServerWhitelist, out string error))
{
Trace.WriteLine(new LogMessage("WebCef", "RenderMedia: auth.server_whitelist. e = " + error), LogType.Info.ToString());
Trace.WriteLine(new LogMessage("WebCef", "RenderMedia: auth.server_allowlist. e = " + error), LogType.Info.ToString());
}

if (!webView.RequestContext.SetPreference("auth.negotiate_delegate_whitelist", ApplicationSettings.Default.AuthServerWhitelist, out string error2))
if (!webView.RequestContext.SetPreference("auth.negotiate_delegate_allowlist", ApplicationSettings.Default.AuthServerWhitelist, out string error2))
{
Trace.WriteLine(new LogMessage("WebCef", "RenderMedia: auth.negotiate_delegate_whitelist. e = " + error2), LogType.Info.ToString());
Trace.WriteLine(new LogMessage("WebCef", "RenderMedia: auth.negotiate_delegate_allowlist. e = " + error2), LogType.Info.ToString());
}
}
}
Expand Down
35 changes: 32 additions & 3 deletions Rendering/WebEdge.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
*
Expand Down Expand Up @@ -76,6 +76,16 @@ private async void InitialiseWebView()
// Environment
CoreWebView2EnvironmentOptions environmentOptions;

// Where should we store user data?
string userDataFolder = ApplicationSettings.Default.LibraryPath;

// Workaround for paths which do not have a trailing slash and are therefore not detected as absolute
// e.g. E:
if (!userDataFolder.EndsWith("\\") && !userDataFolder.EndsWith("/"))
{
userDataFolder += "\\";
}

// NTLM/Auth Server White Lists.
if (!string.IsNullOrEmpty(ApplicationSettings.Default.AuthServerWhitelist))
{
Expand All @@ -98,15 +108,20 @@ private async void InitialiseWebView()
await this.webView.EnsureCoreWebView2Async(
await CoreWebView2Environment.CreateAsync(
null,
ApplicationSettings.Default.LibraryPath,
environmentOptions));
userDataFolder,
environmentOptions
));

// Proxy
// Not yet supported https://github.com/MicrosoftEdge/WebView2Feedback/issues/132
/*if (!string.IsNullOrEmpty(ApplicationSettings.Default.ProxyUser))
{
}*/

// Console logs
this.webView.CoreWebView2.GetDevToolsProtocolEventReceiver("Log.entryAdded").DevToolsProtocolEventReceived += OnConsoleMessage;
await this.webView.CoreWebView2.CallDevToolsProtocolMethodAsync("Log.enable", "{}");
}

/// <summary>
Expand Down Expand Up @@ -135,6 +150,7 @@ private void WebView_CoreWebView2InitializationCompleted(object sender, Microsof
if (e.IsSuccess)
{
webView.CoreWebView2.Settings.IsPinchZoomEnabled = isPinchToZoomEnabled;
webView.CoreWebView2.Settings.IsStatusBarEnabled = false;
_webViewInitialised = true;
}
else
Expand Down Expand Up @@ -270,5 +286,18 @@ protected override string MakeHtmlSubstitutions(string cachedFile)
html += "<!--CACHEDATE=" + DateTime.Now.ToString() + "-->";
return html;
}

/// <summary>
/// Log console messages
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnConsoleMessage(object sender, CoreWebView2DevToolsProtocolEventReceivedEventArgs e)
{
if (e != null && e.ParameterObjectAsJson != null)
{
Trace.WriteLine("WebView2:" + e.ParameterObjectAsJson);
}
}
}
}
Loading

0 comments on commit 9509081

Please sign in to comment.