forked from j62/ctbrec
1
0
Fork 0

Fix Bongacams login in external browser

This commit is contained in:
0xb00bface 2020-10-25 20:33:56 +01:00
parent f04681a8be
commit dfb1083c45
2 changed files with 26 additions and 10 deletions

View File

@ -31,7 +31,8 @@ public class ExternalBrowser implements AutoCloseable {
private Socket socket; private Socket socket;
private Thread reader; private Thread reader;
private volatile boolean stopped = true; private volatile boolean stopped = true;
private Object ready = new Object(); private volatile boolean browserReady = false;
private Object browserReadyLock = new Object();
public static ExternalBrowser getInstance() { public static ExternalBrowser getInstance() {
return INSTANCE; return INSTANCE;
@ -46,14 +47,22 @@ public class ExternalBrowser implements AutoCloseable {
addProxyConfig(jsonConfig.getJSONObject("config")); addProxyConfig(jsonConfig.getJSONObject("config"));
p = new ProcessBuilder(OS.getBrowserCommand()).start(); if (LOG.isTraceEnabled()) {
p = new ProcessBuilder(OS.getBrowserCommand("--enable-logging")).start();
new StreamRedirectThread(p.getInputStream(), System.err); new StreamRedirectThread(p.getInputStream(), System.err);
new StreamRedirectThread(p.getErrorStream(), System.err); new StreamRedirectThread(p.getErrorStream(), System.err);
} else {
p = new ProcessBuilder(OS.getBrowserCommand()).start();
new StreamRedirectThread(p.getInputStream(), OutputStream.nullOutputStream());
new StreamRedirectThread(p.getErrorStream(), OutputStream.nullOutputStream());
}
LOG.debug("Browser started"); LOG.debug("Browser started");
connectToRemoteControlSocket(); connectToRemoteControlSocket();
synchronized (ready) { while (!browserReady) {
ready.wait(); synchronized (browserReadyLock) {
browserReadyLock.wait(100);
}
} }
if(LOG.isTraceEnabled()) { if(LOG.isTraceEnabled()) {
LOG.debug("Connected to remote control server. Sending config {}", jsonConfig); LOG.debug("Connected to remote control server. Sending config {}", jsonConfig);
@ -129,8 +138,9 @@ public class ExternalBrowser implements AutoCloseable {
try { try {
BufferedReader br = new BufferedReader(new InputStreamReader(in)); BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line; String line;
synchronized (ready) { synchronized (browserReadyLock) {
ready.notify(); browserReady = true;
browserReadyLock.notifyAll();
} }
while( !Thread.interrupted() && (line = br.readLine()) != null ) { while( !Thread.interrupted() && (line = br.readLine()) != null ) {
LOG.debug("Browser output: {}", line); LOG.debug("Browser output: {}", line);
@ -145,6 +155,12 @@ public class ExternalBrowser implements AutoCloseable {
if(!stopped) { if(!stopped) {
LOG.error("Couldn't read browser output", e); LOG.error("Couldn't read browser output", e);
} }
} finally {
stopped = true;
synchronized (browserReadyLock) {
browserReady = true;
browserReadyLock.notifyAll();
}
} }
} }

View File

@ -59,12 +59,12 @@ public class BongaCamsElectronLoginDialog {
Thread.sleep(500); Thread.sleep(500);
String username = Config.getInstance().getSettings().bongaUsername; String username = Config.getInstance().getSettings().bongaUsername;
if (username != null && !username.trim().isEmpty()) { if (username != null && !username.trim().isEmpty()) {
browser.executeJavaScript("$('input[name=\"log_in[username]\"]').attr('value','" + username + "')"); browser.executeJavaScript("document.getElementById('log_in_username').value = '" + username + "';");
} }
String password = Config.getInstance().getSettings().bongaPassword; String password = Config.getInstance().getSettings().bongaPassword;
if (password != null && !password.trim().isEmpty()) { if (password != null && !password.trim().isEmpty()) {
password = password.replace("'", "\\'"); password = password.replace("'", "\\'");
browser.executeJavaScript("$('input[name=\"log_in[password]\"]').attr('value','" + password + "')"); browser.executeJavaScript("document.getElementById('log_in_password').value = '" + password + "';");
} }
String[] simplify = new String[] { String[] simplify = new String[] {
"$('div#header').css('display','none');", "$('div#header').css('display','none');",