essential-actions
Clone or download
Modified Files
--- 'a/obssuite/mother/pom.xml'
+++ b/obssuite/mother/pom.xml
@@ -6,7 +6,7 @@
<groupId>com.stream-pi</groupId>
<artifactId>obssuite_motheraction</artifactId>
- <version>1.1.0</version>
+ <version>2.0.0</version>
<build>
<plugins>
--- 'a/obssuite/mother/src/main/java/mother/Mother.java'
+++ b/obssuite/mother/src/main/java/mother/Mother.java
@@ -22,8 +22,7 @@ public class Mother extends NormalAction
setVisibilityInPluginsPane(false);
setAuthor("rnayabed");
setHelpLink("https://github.com/Stream-Pi/EssentialActions");
- setVersion(new Version(1,1,0));
-
+ setVersion(MotherConnection.VERSION);
connectDisconnectButton = new Button("Connect");
@@ -63,7 +62,11 @@ public class Mother extends NormalAction
}
@Override
- public void initAction() throws Exception {
+ public void initAction() throws Exception
+ {
+ MotherConnection.setPass(getPassword());
+ MotherConnection.setUrl(getURL());
+ MotherConnection.setConnectDisconnectButton(connectDisconnectButton);
connectDisconnectButton.setOnAction(action->{
try
@@ -112,7 +115,7 @@ public class Mother extends NormalAction
{
MotherConnection.setPass(pass);
MotherConnection.setUrl(url);
- new OBSActionConnectionTask(connectDisconnectButton, true);
+ new OBSActionConnectionTask(true, null, null, null);
}
@Override
--- 'a/obssuite/mother/src/main/java/mother/OBSActionConnectionTask.java'
+++ b/obssuite/mother/src/main/java/mother/OBSActionConnectionTask.java
@@ -11,16 +11,16 @@ import com.stream_pi.util.alert.StreamPi
public class OBSActionConnectionTask extends Task<Void>
{
+ private Runnable onFailToConnectRunnable = null;
+ private Runnable onConnectRunnable = null;
+ private Runnable onDisconnectRunnable = null;
- String url, pass;
- Button connectDisconnectButton;
-
- public OBSActionConnectionTask(Button connectDisconnectButton,
- boolean runAsync)
+ public OBSActionConnectionTask(boolean runAsync, Runnable onFailToConnectRunnable,
+ Runnable onConnectRunnable, Runnable onDisconnectRunnable)
{
- this.url = MotherConnection.getUrl();
- this.pass = MotherConnection.getPass();
- this.connectDisconnectButton = connectDisconnectButton;
+ this.onFailToConnectRunnable = onFailToConnectRunnable;
+ this.onConnectRunnable = onConnectRunnable;
+ this.onDisconnectRunnable = onDisconnectRunnable;
if(runAsync)
{
@@ -37,6 +37,9 @@ public class OBSActionConnectionTask ext
{
try
{
+ String url = MotherConnection.getUrl();
+ String pass = MotherConnection.getPass();
+
setConnectDisconnectButtonDisable(true);
if(!url.startsWith("ws://"))
@@ -66,17 +69,35 @@ public class OBSActionConnectionTask ext
new StreamPiAlert("Unable to Connect", "Unable to establish connection to WebSocket with provided crendentials\n\n"+
"Detailed Error : "+message, StreamPiAlertType.ERROR).show();
MotherConnection.setRemoteController(null);
+
+ if(onFailToConnectRunnable != null)
+ {
+ onFailToConnectRunnable.run();
+ onFailToConnectRunnable = null;
+ }
});
obsRemoteController.registerDisconnectCallback(()->{
setConnectDisconnectButtonText("Connect");
MotherConnection.setRemoteController(null);
+
+ if(onDisconnectRunnable != null)
+ {
+ onDisconnectRunnable.run();
+ onDisconnectRunnable = null;
+ }
});
obsRemoteController.registerConnectCallback(onConnect->{
setConnectDisconnectButtonText("Disconnect");
MotherConnection.setRemoteController(obsRemoteController);
+
+ if(onConnectRunnable != null)
+ {
+ onConnectRunnable.run();
+ onConnectRunnable = null;
+ }
});
}
catch (Exception e)
@@ -96,18 +117,18 @@ public class OBSActionConnectionTask ext
private void setConnectDisconnectButtonText(String text)
{
- if(connectDisconnectButton == null)
+ if(MotherConnection.getConnectDisconnectButton() == null)
return;
- Platform.runLater(()-> connectDisconnectButton.setText(text));
+ Platform.runLater(()-> MotherConnection.getConnectDisconnectButton().setText(text));
}
private void setConnectDisconnectButtonDisable(boolean disable)
{
- if(connectDisconnectButton == null)
+ if(MotherConnection.getConnectDisconnectButton() == null)
return;
- Platform.runLater(()-> connectDisconnectButton.setDisable(disable));
+ Platform.runLater(()-> MotherConnection.getConnectDisconnectButton().setDisable(disable));
}
}
\ No newline at end of file
--- 'a/obssuite/mother/src/main/java/mother/motherconnection/MotherConnection.java'
+++ b/obssuite/mother/src/main/java/mother/motherconnection/MotherConnection.java
@@ -3,6 +3,8 @@ package mother.motherconnection;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
+import com.stream_pi.util.version.Version;
+import javafx.scene.control.Button;
import mother.OBSActionConnectionTask;
import net.twasi.obsremotejava.OBSRemoteController;
import net.twasi.obsremotejava.callbacks.Callback;
@@ -11,9 +13,23 @@ public class MotherConnection
{
private static OBSRemoteController obsRemoteController = null;
+ public static final Version VERSION = new Version(2,0,0);
+
private static String url = null;
private static String pass = null;
+ private static Button connectDisconnectButton = null;
+
+ public static void setConnectDisconnectButton(Button connectDisconnectButton)
+ {
+ MotherConnection.connectDisconnectButton = connectDisconnectButton;
+ }
+
+ public static Button getConnectDisconnectButton()
+ {
+ return connectDisconnectButton;
+ }
+
public static void setUrl(String url) {
MotherConnection.url = url;
}
@@ -30,16 +46,22 @@ public class MotherConnection
return pass;
}
- public void connect()
+ public static void connect()
{
- connect(true);
+ connect(true, null, null, null);
}
- public void connect(boolean runAsync)
+ public static void connect(Runnable onConnectRunnable)
{
- new OBSActionConnectionTask( null, runAsync);
+ connect(true, null, onConnectRunnable, null);
}
+ public static void connect(boolean runAsync, Runnable onFailToConnectRunnable,
+ Runnable onConnectRunnable, Runnable onDisconnectRunnable)
+ {
+ new OBSActionConnectionTask(runAsync, onFailToConnectRunnable,
+ onConnectRunnable, onDisconnectRunnable);
+ }
public static OBSRemoteController getRemoteController()
{
--- 'a/obssuite/setcurrentprofile/pom.xml'
+++ b/obssuite/setcurrentprofile/pom.xml
@@ -6,7 +6,7 @@
<groupId>com.stream-pi</groupId>
<artifactId>obssuite_setcurrentprofileaction</artifactId>
- <version>1.0.0</version>
+ <version>2.0.0</version>
<build>
<plugins>
@@ -39,7 +39,7 @@
<properties>
<ActionAPIVersion>1.0.0-SNAPSHOT</ActionAPIVersion>
<UtilVersion>1.0.0-SNAPSHOT</UtilVersion>
- <OBSSuiteMotherVersion>1.1.0</OBSSuiteMotherVersion>
+ <OBSSuiteMotherVersion>2.0.0</OBSSuiteMotherVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
--- 'a/obssuite/setcurrentprofile/src/main/java/setcurrentprofile/SetCurrentProfile.java'
+++ b/obssuite/setcurrentprofile/src/main/java/setcurrentprofile/SetCurrentProfile.java
@@ -5,58 +5,87 @@ import com.stream_pi.action_api.actionpr
import com.stream_pi.action_api.externalplugin.NormalAction;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
-import com.stream_pi.util.version.Version;
+import com.stream_pi.util.exception.MinorException;
import mother.motherconnection.MotherConnection;
-import net.twasi.obsremotejava.OBSRemoteController;
public class SetCurrentProfile extends NormalAction
{
-
public SetCurrentProfile() {
setName("Set Current Profile");
setCategory("OBS");
setVisibilityInServerSettingsPane(false);
setAuthor("rnayabed");
- setVersion(new Version(1, 0, 0));
+ setVersion(MotherConnection.VERSION);
}
@Override
- public void initProperties() throws Exception {
- // TODO Auto-generated method stub
-
- Property currentProfileProperty = new Property("current_profile", Type.STRING);
+ public void initProperties() throws Exception
+ {
+ Property currentProfileProperty = new Property("profile", Type.STRING);
currentProfileProperty.setDisplayName("Profile Name");
-
- addClientProperties(currentProfileProperty);
- }
- @Override
- public void initAction() throws Exception {
- // TODO Auto-generated method stub
+ Property autoConnectProperty = new Property("auto_connect", Type.BOOLEAN);
+ autoConnectProperty.setDefaultValueBoolean(true);
+ autoConnectProperty.setDisplayName("Auto Connect if not connected");
+
+ addClientProperties(currentProfileProperty, autoConnectProperty);
}
@Override
- public void onActionClicked() throws Exception {
- // TODO Auto-generated method stub
-
- OBSRemoteController controller = MotherConnection.getRemoteController();
+ public void onActionClicked() throws Exception
+ {
+ String profile = getClientProperties().getSingleProperty("profile").getStringValue();
+
+ if(profile.isBlank())
+ {
+ throw new MinorException("Blank Profile Name","No Profile Name specified");
+ }
- if (controller == null) {
- new StreamPiAlert("Is OBS Connected?",
- "It seems there is no connection to OBS, please connect it in Settings", StreamPiAlertType.WARNING)
- .show();
- } else {
- controller.setCurrentProfile(getClientProperties().getSingleProperty("current_profile").getStringValue(), MotherConnection.getDefaultCallBack(
- "Unable to Set Current Profile","Failed to set current profile"
- ));
+ if (MotherConnection.getRemoteController() == null)
+ {
+ boolean autoConnect = getClientProperties().getSingleProperty(
+ "auto_connect"
+ ).getBoolValue();
+
+ if(autoConnect)
+ {
+ MotherConnection.connect(()->setProfile(profile));
+ }
+ else
+ {
+ new StreamPiAlert("Is OBS Connected?",
+ "It seems there is no connection to OBS, please connect it in Settings", StreamPiAlertType.WARNING)
+ .show();
+ }
+ }
+ else
+ {
+ setProfile(profile);
}
}
- @Override
- public void onShutDown() throws Exception {
- // TODO Auto-generated method stub
-
+ public void setProfile(String profile)
+ {
+ MotherConnection.getRemoteController().setCurrentProfile(profile, setCurrentProfileResponse -> {
+ String status = setCurrentProfileResponse.getStatus();
+ String error = setCurrentProfileResponse.getError();
+
+ if(status.equals("error"))
+ {
+ String content;
+
+ if(error.equals("profile does not exist"))
+ {
+ content = "Profile "+profile+" does not exist.";
+ }
+ else
+ {
+ content = error;
+ }
+
+ new StreamPiAlert("OBS",content, StreamPiAlertType.ERROR).show();
+ }
+ });
}
-
}