Skip to content

Commit 1908cae

Browse files
committed
External WS
Added support for external OBS Websockets, so OBS WS can act as a "server". This allows the tally lights to be controlled from a separate computer.
1 parent 0651e34 commit 1908cae

File tree

5 files changed

+139
-65
lines changed

5 files changed

+139
-65
lines changed

Diff for: toOBSComputer/OBSTallyClient/MainProgram.cs

+20-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public partial class MainProgram : Form
1616
OBSWebsocket mainWebsocket = new OBSWebsocket();
1717

1818
// Public variables
19+
public string wsPort;
20+
public string wsAddress;
1921
public string source1;
2022
public string source2;
2123
public string source3;
@@ -63,17 +65,20 @@ private void Form1_Load(object sender, EventArgs e)
6365

6466
try
6567
{
66-
mainWebsocket.Connect("ws://127.0.0.1:4444", wsPassword);
68+
69+
mainWebsocket.WSTimeout = TimeSpan.FromSeconds(1);
70+
mainWebsocket.Connect("ws://"+wsAddress+":"+wsPort, wsPassword);
6771
if (mainWebsocket.IsConnected)
6872
{
73+
6974
lastLiveScene = mainWebsocket.GetCurrentScene().Name; //Initialize lastLiveScene at the current live scene
70-
75+
7176
//Update label text
7277
label1.Text = source1; label1.Font = scaleFont(label1);
7378
label2.Text = source2; label2.Font = scaleFont(label2);
7479
label3.Text = source3; label3.Font = scaleFont(label3);
7580
label4.Text = source4; label4.Font = scaleFont(label4);
76-
81+
7782
RefreshLabels(PreviewSceneSources, Color.Green); //Set label colors for preview sources
7883
RefreshLabels(LiveSceneSources, Color.Red); //Set label colors for live sources
7984
}
@@ -85,8 +90,8 @@ private void Form1_Load(object sender, EventArgs e)
8590
}
8691
catch
8792
{
88-
8993
}
94+
9095
}
9196

9297
// Main loop //
@@ -110,7 +115,7 @@ private void MainLoop(object sender, EventArgs e) // Loops continuously 100ms
110115
////////////// LIVE //////////////
111116
if (currentLiveScene != lastLiveScene) //If live scene state changes
112117
{
113-
//Console.WriteLine("Live state has changed"); //Debugging
118+
Console.WriteLine("Live state has changed"); //Debugging
114119
// Update live label colors for UI app
115120
ColorAllLabels(Color.Gray); //Gray out all labels
116121
if (button2.Text == "Previews ON") { RefreshLabels(PreviewSceneSources, Color.Green); } //Refresh preview labels
@@ -129,7 +134,7 @@ private void MainLoop(object sender, EventArgs e) // Loops continuously 100ms
129134
// Update previews after prieview on/off is toggled
130135
if (lastbutton2State != button2_ClickCount)
131136
{
132-
//Console.WriteLine("Previews on."); //Debugging
137+
Console.WriteLine("Previews on."); //Debugging
133138
RefreshLabels(PreviewSceneSources, Color.Green); //Refresh preview labels
134139
RefreshLabels(LiveSceneSources, Color.Red); //Set label colors for live sources
135140
lastbutton2State = button2_ClickCount; //Update lastbutton2State
@@ -141,7 +146,7 @@ private void MainLoop(object sender, EventArgs e) // Loops continuously 100ms
141146
// Update preview label colors for UI app
142147
if (currentPreviewScene != lastPreviewScene) //If preview scene state changes
143148
{
144-
//Console.WriteLine("Preview state has changed"); //Debugging
149+
Console.WriteLine("Preview state has changed"); //Debugging
145150
ColorAllLabels(Color.Gray); //Gray out all labels
146151
RefreshLabels(PreviewSceneSources, Color.Green); //Set label colors for preview sources
147152
RefreshLabels(LiveSceneSources, Color.Red); //Set label colors for live sources
@@ -158,7 +163,7 @@ private void MainLoop(object sender, EventArgs e) // Loops continuously 100ms
158163
{
159164
if (lastbutton2State != button2_ClickCount) // If preview on/off toggle changes
160165
{
161-
//Console.WriteLine("Previews off."); //Debugging
166+
Console.WriteLine("Previews off."); //Debugging
162167
ColorAllLabels(Color.Gray); //Gray out all labels
163168
RefreshLabels(LiveSceneSources, Color.Red); //Refresh live labels
164169
lastbutton2State = button2_ClickCount; //Update lastbutton2State
@@ -200,8 +205,9 @@ private void WebsocketHeartbeat(object sender, EventArgs e) // Loops continuousl
200205
messageShown = true; // Set messageShown flag to true
201206
DialogResult result = MessageBox.Show("Please verify the following:\n" +
202207
"1. OBS is open and running.\n" +
203-
"2. OBS Websockets is installed and enabled.\n\n" +
204-
"Would you like to attempt to reconnect?", "OBS TALLY: Lost connection to OBS",
208+
"2. OBS Websockets is installed and enabled.\n" +
209+
"3. You have entered the correct IP address and port.\n\n" +
210+
"Would you like to attempt to reconnect? If not, click \"No\", then run the setup again.", "OBS TALLY: Lost connection to OBS",
205211
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
206212
if (result == DialogResult.Yes)
207213
{
@@ -210,7 +216,6 @@ private void WebsocketHeartbeat(object sender, EventArgs e) // Loops continuousl
210216
}
211217
else if (result == DialogResult.No)
212218
{
213-
this.Close();
214219
}
215220
}
216221
}
@@ -363,6 +368,10 @@ private void loadConfigXML()
363368
source4 = fourth.Attributes["name"].Value;
364369
XmlNode wesPass = xmlDoc.SelectSingleNode("root/Websocket");
365370
wsPassword = wesPass.Attributes["password"].Value;
371+
XmlNode wesPort = xmlDoc.SelectSingleNode("root/WebsocketPort");
372+
wsPort = wesPort.Attributes["port"].Value;
373+
XmlNode wesAddress = xmlDoc.SelectSingleNode("root/WebsocketAddress");
374+
wsAddress = wesAddress.Attributes["address"].Value;
366375
}
367376

368377
}

0 commit comments

Comments
 (0)