Skip to content

Commit

Permalink
added class to store html and css for site
Browse files Browse the repository at this point in the history
  • Loading branch information
sandsalamand committed Jul 21, 2021
1 parent eb7174b commit 2cb980f
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 20 deletions.
Binary file modified .vs/StreamLabs_Helper/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
1 change: 0 additions & 1 deletion .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"ExpandedNodes": [
""
],
"SelectedNode": "\\WebParser.cs",
"PreviewInSolutionExplorer": false
}
Binary file modified .vs/slnx.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace StreamLabs_Helper
{
public class DataManager
{
private static string defaultUrl = "https://w2g.tv/rooms/e6shdqxijs69ovevtd?lang=en";
private static string defaultUrl = "https://w2g.tv/rooms/challengerandymusic-h749vkhemnt5dmld09?lang=en";
private static string prefFileName = "Preferences.txt";

private static string preferenceFilePath;
Expand Down
10 changes: 7 additions & 3 deletions ProgramManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Timers;
using System.Threading;
using System.Threading.Tasks;

namespace StreamLabs_Helper
Expand Down Expand Up @@ -90,7 +89,7 @@ static void Timer_Elapsed(object sender, ElapsedEventArgs e)
Set_Timer(timerInterval);
}

static async Task<WebParser.ParsingStatus> FindIFrameDontUpdateDelegate() //might need to de-async this since it needs to run once before program can do anything
static async Task<WebParser.ParsingStatus> FindIFrameDontUpdateDelegate()
{
var result = await parser.FindIFrameOnPage(url);
Console.WriteLine("iframeResult: " + result);
Expand All @@ -114,10 +113,10 @@ static void Timer_Elapsed(object sender, ElapsedEventArgs e)
try
{
string foundText = await parser.GetIFrameTitle();
Console.WriteLine("foundText: " + foundText);
if (foundText is null) {
return WebParser.ParsingStatus.Failure;
}
Console.WriteLine("foundText: " + foundText);
server.UpdateResponse(foundText);
return WebParser.ParsingStatus.Success;
}
Expand All @@ -128,6 +127,11 @@ static void Timer_Elapsed(object sender, ElapsedEventArgs e)
}
}

public static void Print(string message)
{
Console.WriteLine((message ?? "empty message") + Environment.NewLine);
}

public static void Error(string message = "unspecified error", bool fatal = false)
{
Console.WriteLine(message + "\n");
Expand Down
16 changes: 3 additions & 13 deletions Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,13 @@ class Server : IDisposable
{
static volatile HttpListener _httpListener = new HttpListener();
Thread _responseThread;
private string responsePrefix;
private string responseSuffix;
private string responseString;
private object threadLock = new object();
private bool shouldRun = true;

public Server(string message = null)
{
string parseInterval = (ProgramManager.timerInterval / 1000).ToString();
Console.WriteLine("parseInterval: " + parseInterval);
responsePrefix =
"<html><head><title>Watch2Gether Title Displayer</title><meta http-equiv=\"refresh\" content=\""
+ parseInterval + "\"></head><body>";
responseSuffix = "</body></html>";
string defaultWelcome = responsePrefix + "<em>Server initializing.... If this takes longer than 10 seconds," +
"then it's bugged. Check to make sure a youtube video is playing (not a built-in Blender short), then restart this app.</em>" + responseSuffix;
responseString = message ?? defaultWelcome;
responseString = WebSite.FormSite(message);
}

public bool StartServer(string mode)
Expand Down Expand Up @@ -100,9 +90,9 @@ void ResponseThread()
}
}

public void UpdateResponse(string response) //updates the reponse that the server will display
public void UpdateResponse(string newResponse) //updates the reponse that the server will display
{
responseString = responsePrefix + response + responseSuffix;
responseString = WebSite.FormSite(newResponse);
}

public static bool IsAdministrator()
Expand Down
55 changes: 55 additions & 0 deletions WebSite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StreamLabs_Helper
{
static class WebSite
{
static private int updateInterval = 3; //change to use WebSite as timer authority
public static string defaultMessage { get; } = "<em>Server initializing.... If this takes longer than 10 seconds," +
"then it's bugged. Check to make sure a youtube video is playing (not a built-in Blender short), then restart this app.</em>";
private static HtmlStruct SiteHtml;
private static string cssText = @"<style>
body {
font-size: 5vw;
}
</style>";

struct HtmlStruct
{
public string head;
public string bodyPrefix;
public string bodySuffix;
}

static WebSite()
{
ProgramManager.Print("updateInterval: " + updateInterval);
FormHtml();
}

public static string FormSite(string message)
{
if (message is not null)
return (SiteHtml.head + SiteHtml.bodyPrefix + message + SiteHtml.bodySuffix);
else
return defaultMessage;
}

private static void FormHtml()
{
SiteHtml.head = FormHead(updateInterval, cssText);
SiteHtml.bodyPrefix = "<body>";
SiteHtml.bodySuffix = "</body></html>";
}

private static string FormHead(int refreshRate, string css)
{
return "<html><head><title>Watch2Gether Title Displayer</title>" + css + "<meta http-equiv=\"refresh\" content=\""
+ refreshRate.ToString() + "\"></head><body>";
}
}
}
2 changes: 0 additions & 2 deletions XmlHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
Expand Down

0 comments on commit 2cb980f

Please sign in to comment.