Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spark plugin for galene #842

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
call mvn package -DskipTests

pause
34 changes: 34 additions & 0 deletions plugins/galene/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.igniterealtime.spark.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.0.3-SNAPSHOT</version>
<relativePath>../plugin/pom.xml</relativePath>
</parent>

<artifactId>galene</artifactId>
<version>0.0.1</version>

<name>Galene SFU Plugin</name>
<description>Adds support for audio/video conferencing using Galene Media SFU</description>

<contributors>
<contributor>
<name>Dele Olajide</name>
<roles>
<role>Author</role>
</roles>
</contributor>
</contributors>

<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
</project>
1 change: 1 addition & 0 deletions plugins/galene/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a plugin for Spark that allows users to join audio and video webinars hosted by Galene
Binary file added plugins/galene/spark-galene.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions plugins/galene/src/main/java/de/mxro/process/ProcessListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.mxro.process;

/**
* A listener to intercept outputs from the process.
*
* @author Max
*
*/
public interface ProcessListener {

/**
* When the process wrote a line to its standard output stream.
*
* @param line
*/
void onOutputLine(String line);

/**
* When the process wrote a line to its error output stream.
*
* @param line
*/
void onErrorLine(String line);

/**
* When the output stream is closed.
*/
void onProcessQuit(int returnValue);

/**
* When an unexpected error is thrown while interacting with the process.
*
* @param t
*/
void onError(Throwable t);

}
129 changes: 129 additions & 0 deletions plugins/galene/src/main/java/de/mxro/process/Spawn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package de.mxro.process;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import de.mxro.process.internal.Engine;

public class Spawn {

/**
* Start a new process.
*
* @param command
* @param listener
* @param folder
* @return
*/
public static XProcess startProcess(final String command, final File folder, final ProcessListener listener) {
return startProcess(command.split(" "), folder, listener);
}

public static XProcess startProcess(final String[] command, final File folder, final ProcessListener listener) {
return Engine.startProcess(command, listener, folder);
}

public static String runCommand(final String command, final File folder) {
return runCommand(command.split(" "), folder);
}

/**
* Runs a command in a new process and stops the process thereafter.
*
* @param command
* @param folder
*/
public static String runCommand(final String[] command, final File folder) {

final CountDownLatch latch = new CountDownLatch(2);

final List<Throwable> exceptions = Collections.synchronizedList(new LinkedList<>());

final List<String> output = Collections.synchronizedList(new LinkedList<>());

latch.countDown();
final XProcess process = startProcess(command, folder, new ProcessListener() {

@Override
public void onProcessQuit(final int returnValue) {
latch.countDown();
}

@Override
public void onOutputLine(final String line) {
output.add(line);
}

@Override
public void onErrorLine(final String line) {
output.add(line);
}

@Override
public void onError(final Throwable t) {
exceptions.add(t);
}
});

try {
latch.await();
// Thread.sleep(300); // just wait for input to gobble in
} catch (final InterruptedException e) {
throw new RuntimeException(e);
}

if (exceptions.size() > 0) {
throw new RuntimeException(exceptions.get(0));
}

final StringBuilder sb = new StringBuilder();
for (final String line : new ArrayList<>(output)) {
sb.append(line).append("\n");
}

process.destory();
return sb.toString();
}

public interface Callback<Type> {
void onDone(Type t);
}

/**
* Runs bash scripts (*.sh) in a UNIX environment.
*
* @param bashScriptFile
* @return
*/
public static String runBashScript(final File bashScriptFile) {
return runCommand("/bin/bash -c " + bashScriptFile.getAbsolutePath(), bashScriptFile.getParentFile());
}

public static boolean isWindows() {
return System.getProperty("os.name").startsWith("Windows");
}

public static String sh(final File folder, final String bashCommand) {

if (!isWindows()) {
return runCommand(new String[] { "/bin/bash", "-c", bashCommand }, folder);
} else {
return runCommand(new String[] { "cmd.exe", "/C", bashCommand }, folder);
}
}

/**
* Executes a bash command.
*
* @param bashCommand
* @return
*/
public static String sh(final String bashCommand) {
return sh(null, bashCommand);
}

}
24 changes: 24 additions & 0 deletions plugins/galene/src/main/java/de/mxro/process/XProcess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package de.mxro.process;

/**
* A wrapper for {@link java.lang.Process}.
*
* @author <a href="http://www.mxro.de/">Max Rohde</a>
*
*/
public interface XProcess {

/**
* Call to push the specified {@link String} into the started processes
* input.
*
* @param line
*/
void sendLine(String line);

/**
* Try to destroy the process
*/
void destory();

}
Loading