forked from j62/ctbrec
Fire events from LocalRecorder
This commit is contained in:
parent
5b8cfc02d6
commit
80381c0d49
|
@ -48,6 +48,7 @@ import javafx.scene.control.Alert;
|
||||||
import javafx.scene.control.Tab;
|
import javafx.scene.control.Tab;
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.media.AudioClip;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
|
@ -93,14 +94,7 @@ public class CamrecApplication extends Application {
|
||||||
createGui(primaryStage);
|
createGui(primaryStage);
|
||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
|
|
||||||
new Thread(() -> {
|
registerAlertSystem();
|
||||||
try {
|
|
||||||
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Platform.runLater(() -> registerAlertSystem());
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logEnvironment() {
|
private void logEnvironment() {
|
||||||
|
@ -211,28 +205,41 @@ public class CamrecApplication extends Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerAlertSystem() {
|
private void registerAlertSystem() {
|
||||||
Notification.Notifier.setNotificationOwner(primaryStage);
|
new Thread(() -> {
|
||||||
EventBusHolder.BUS.register(new Object() {
|
try {
|
||||||
@Subscribe
|
// don't register before 1 minute has passed, because directly after
|
||||||
public void modelEvent(Map<String, Object> e) {
|
// the start of ctbrec, an event for every online model would be fired,
|
||||||
try {
|
// which is annoying as f
|
||||||
if (Objects.equals("model.status", e.get("event"))) {
|
Thread.sleep(TimeUnit.MINUTES.toMillis(1));
|
||||||
String status = (String) e.get("status");
|
} catch (InterruptedException e) {
|
||||||
Model model = (Model) e.get("model");
|
e.printStackTrace();
|
||||||
LOG.debug("Alert: {} is {}", model.getName(), status);
|
}
|
||||||
if (Objects.equals("online", status)) {
|
LOG.debug("Alert System registered");
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
notifier.notifyInfo("Model Online", model.getName() + " is now online");
|
Notification.Notifier.setNotificationOwner(primaryStage);
|
||||||
//AudioClip clip = new AudioClip("file:///tmp/Oxygen-Im-Highlight-Msg.mp3");
|
EventBusHolder.BUS.register(new Object() {
|
||||||
//clip.play();
|
@Subscribe
|
||||||
});
|
public void modelEvent(Map<String, Object> e) {
|
||||||
|
LOG.debug("Alert: {}", e);
|
||||||
|
try {
|
||||||
|
if (Objects.equals("model.status", e.get("event"))) {
|
||||||
|
String status = (String) e.get("status");
|
||||||
|
Model model = (Model) e.get("model");
|
||||||
|
if (Objects.equals("online", status)) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
notifier.notifyInfo("Model Online", model.getName() + " is now online");
|
||||||
|
AudioClip clip = new AudioClip(getClass().getResource("/Oxygen-Im-Highlight-Msg.mp3").toString());
|
||||||
|
clip.play();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e1) {
|
});
|
||||||
e1.printStackTrace();
|
});
|
||||||
}
|
}).start();
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeColorSchemeStyleSheet(Stage primaryStage) {
|
private void writeColorSchemeStyleSheet(Stage primaryStage) {
|
||||||
|
|
Binary file not shown.
|
@ -36,6 +36,7 @@ import com.iheartradio.m3u8.ParseException;
|
||||||
import com.iheartradio.m3u8.PlaylistException;
|
import com.iheartradio.m3u8.PlaylistException;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
|
import ctbrec.EventBusHolder;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.OS;
|
import ctbrec.OS;
|
||||||
import ctbrec.Recording;
|
import ctbrec.Recording;
|
||||||
|
@ -179,6 +180,7 @@ public class LocalRecorder implements Recorder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
fireRecordingStateChanged(model, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopRecordingProcess(Model model) {
|
private void stopRecordingProcess(Model model) {
|
||||||
|
@ -188,6 +190,7 @@ public class LocalRecorder implements Recorder {
|
||||||
if(!Config.isServerMode()) {
|
if(!Config.isServerMode()) {
|
||||||
postprocess(download);
|
postprocess(download);
|
||||||
}
|
}
|
||||||
|
fireRecordingStateChanged(model, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void postprocess(Download download) {
|
private void postprocess(Download download) {
|
||||||
|
@ -368,6 +371,7 @@ public class LocalRecorder implements Recorder {
|
||||||
} else {
|
} else {
|
||||||
postprocess(d);
|
postprocess(d);
|
||||||
}
|
}
|
||||||
|
fireRecordingStateChanged(m, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Model m : restart) {
|
for (Model m : restart) {
|
||||||
|
@ -434,7 +438,11 @@ public class LocalRecorder implements Recorder {
|
||||||
List<Model> models = getModelsRecording();
|
List<Model> models = getModelsRecording();
|
||||||
for (Model model : models) {
|
for (Model model : models) {
|
||||||
try {
|
try {
|
||||||
|
boolean wasOnline = model.isOnline();
|
||||||
boolean isOnline = model.isOnline(IGNORE_CACHE);
|
boolean isOnline = model.isOnline(IGNORE_CACHE);
|
||||||
|
if(wasOnline != isOnline) {
|
||||||
|
fireModelOnlineStateChanged(model, isOnline);
|
||||||
|
}
|
||||||
LOG.trace("Checking online state for {}: {}", model, (isOnline ? "online" : "offline"));
|
LOG.trace("Checking online state for {}: {}", model, (isOnline ? "online" : "offline"));
|
||||||
if (isOnline && !isSuspended(model) && !recordingProcesses.containsKey(model)) {
|
if (isOnline && !isSuspended(model) && !recordingProcesses.containsKey(model)) {
|
||||||
LOG.info("Model {}'s room back to public", model);
|
LOG.info("Model {}'s room back to public", model);
|
||||||
|
@ -468,6 +476,25 @@ public class LocalRecorder implements Recorder {
|
||||||
}
|
}
|
||||||
LOG.debug(getName() + " terminated");
|
LOG.debug(getName() + " terminated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireModelOnlineStateChanged(Model model, boolean online) {
|
||||||
|
Map<String, Object> evt = new HashMap<>();
|
||||||
|
evt.put("event", "model.status");
|
||||||
|
evt.put("status", online ? "online" : "offline");
|
||||||
|
evt.put("model", model);
|
||||||
|
EventBusHolder.BUS.post(evt);
|
||||||
|
LOG.debug("Event fired {}", evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireRecordingStateChanged(Model model, boolean recording) {
|
||||||
|
Map<String, Object> evt = new HashMap<>();
|
||||||
|
evt.put("event", "recording.status");
|
||||||
|
evt.put("status", recording ? "started" : "stopped");
|
||||||
|
evt.put("model", model);
|
||||||
|
EventBusHolder.BUS.post(evt);
|
||||||
|
LOG.debug("Event fired {}", evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PostProcessingTrigger extends Thread {
|
private class PostProcessingTrigger extends Thread {
|
||||||
|
|
Loading…
Reference in New Issue