Improves some documentation.
I was starting to get confused.
This commit is contained in:
@@ -1,3 +1,12 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This module contains the browser addon that handles most of the logic for internet songs. When the :browser module is
|
||||||
|
* built, this addon is added to the browser's list of extensions. Then, when it is run, the addon will start the
|
||||||
|
* intermediary program. Then, it will receive commands from the interface through the intermediary application and
|
||||||
|
* manipulate the browser state based on those commands. It will then send the results of those commands back through
|
||||||
|
* the intermediary. The addon will also periodically shoot off updates to the browser.
|
||||||
|
*/
|
||||||
import org.apache.tools.ant.taskdefs.condition.Os
|
import org.apache.tools.ant.taskdefs.condition.Os
|
||||||
|
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
@@ -6,10 +15,17 @@ import java.nio.file.StandardCopyOption
|
|||||||
import java.util.stream.Stream
|
import java.util.stream.Stream
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
|
/**
|
||||||
|
* This configuration is used to export the packaged addon for installation into a browser.
|
||||||
|
*/
|
||||||
addonBuild {
|
addonBuild {
|
||||||
canBeConsumed = true
|
canBeConsumed = true
|
||||||
canBeResolved = false
|
canBeResolved = false
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* The nativeApp configuration is used to import a native application that this addon will start when the browser
|
||||||
|
* does.
|
||||||
|
*/
|
||||||
nativeApp.extendsFrom runtime
|
nativeApp.extendsFrom runtime
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +46,7 @@ extension.description = "A link between the Universal Music Player and the web b
|
|||||||
extension.id = "universalmusic@regis.edu"
|
extension.id = "universalmusic@regis.edu"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an addon manifest for running
|
* Creates an addon manifest that defines details for the native application that is run when the app starts.
|
||||||
*/
|
*/
|
||||||
abstract class BuildManifest extends DefaultTask {
|
abstract class BuildManifest extends DefaultTask {
|
||||||
@OutputFile
|
@OutputFile
|
||||||
@@ -66,7 +82,7 @@ abstract class BuildManifest extends DefaultTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Installs the addon manifest, adding registery keys on Windows and creating the appropriate files on Mac and Linux.
|
||||||
*/
|
*/
|
||||||
abstract class InstallAddon extends DefaultTask {
|
abstract class InstallAddon extends DefaultTask {
|
||||||
@InputFile
|
@InputFile
|
||||||
@@ -97,16 +113,25 @@ dependencies {
|
|||||||
nativeApp project(path: ":addonInter", configuration: 'nativeBuild')
|
nativeApp project(path: ":addonInter", configuration: 'nativeBuild')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a build manifest that defines details for the native application defined by nativeApp dependencies that will
|
||||||
|
* be run.
|
||||||
|
*/
|
||||||
tasks.register('buildManifest', BuildManifest) {
|
tasks.register('buildManifest', BuildManifest) {
|
||||||
manifests = new File(buildDir, "${extension.name.get()}.json")
|
manifests = new File(buildDir, "${extension.name.get()}.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the build manifest to the OS, allowing for the native application to run properly.
|
||||||
|
* This task depends on buildManifest
|
||||||
|
*/
|
||||||
def installAddon = tasks.register('installAddon', InstallAddon) {
|
def installAddon = tasks.register('installAddon', InstallAddon) {
|
||||||
inputFile = buildManifest.manifests
|
inputFile = buildManifest.manifests
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a packaged (albiet unsigned) Firefox addon from the src/main directory.
|
* Creates a packaged (albiet unsigned) Firefox addon from the src/main directory.
|
||||||
|
* This task is finished by calling installAddon
|
||||||
*/
|
*/
|
||||||
tasks.register('zipAddon', Zip) {
|
tasks.register('zipAddon', Zip) {
|
||||||
dependsOn configurations.nativeApp
|
dependsOn configurations.nativeApp
|
||||||
@@ -146,6 +171,9 @@ tasks.register("clean", Delete) {
|
|||||||
followSymlinks = false
|
followSymlinks = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Exports the packaged addon task.
|
||||||
|
*/
|
||||||
artifacts {
|
artifacts {
|
||||||
addonBuild(zipAddon)
|
addonBuild(zipAddon)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* The background script forms the core of the addon. Running when the browser starts, it starts the native application
|
||||||
|
* (the intermediary program that connects to the interface). The native application will send it commands in the
|
||||||
|
* format of a JSON object containing a "messageNum" field (containing a session-unique identifier for that message) and
|
||||||
|
* "message" (containing the actual message, of which can be of any type). The message data will be forwarded to several
|
||||||
|
* listeners. The listeners will output a single value (or throw an error). In response to either, the addon will send
|
||||||
|
* a JSON object back to the native application in the following format:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* {
|
||||||
|
* "messageNum": 0, // The ID of the message that this response corresponds to
|
||||||
|
* "message": { //A wrapper that contains, among other things, the return data
|
||||||
|
* "type": "edu.regis.universeplayer.browserCommands.CommandReturn", // An identifier that tells the interface to treat this data as a return value for a command
|
||||||
|
* "returnValue": null, // The actual data returned by the listeners. In the event of an error, this will be null.
|
||||||
|
* "confirmation": { // Contains extra metadata about how the command was executed
|
||||||
|
* "type": "edu.regis.universeplayer.browserCommands.CommandConfirmation", // Another identifier for the interface
|
||||||
|
* "message": "Done", // A human-readable message on the results of execution. For non-error returns, this will simply be "done."
|
||||||
|
"errorCode": { // If an error was thrown, this object will contain data on that. Otherwise, it will be null
|
||||||
|
"type": "edu.regis.universeplayer.browserCommands.BrowserError",
|
||||||
|
"name": "",
|
||||||
|
"message": "",
|
||||||
|
"stack", []
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* The default one (registered by this script) does the majority of processing. This default listener takes an object
|
||||||
|
* with a single "type" field that corresponds to an instance of edu.regis.universeplayer.browserCommands.BrowserQuery
|
||||||
|
* in the Java interface. Using that "type" field, it determines what action to take and uses extra data within the
|
||||||
|
* message object. Should the message be something delegated to a foreground tab (i.e. controlling a YouTube video),
|
||||||
|
* the listener will forward the message to the tab in the following format before returning:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* {
|
||||||
|
* "num": 0, // The ID of the tab-specific message. This is independent of the "messageNum" field above
|
||||||
|
* "message": {} // A copy of the actual message sent.
|
||||||
|
* }
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* Either way,
|
||||||
|
*
|
||||||
|
* Then, whenever it receives a command from the application,
|
||||||
|
* it will forward that command to several listeners. One of those listeners, a default one registered by this script,
|
||||||
|
* does the majority of processing. If the message is marked for a specific tab (one running the foreground.js script),
|
||||||
|
* the message is forwarded to that tab for further processing before retrieving the value. Either way,
|
||||||
|
*/
|
||||||
let logger = new Logger("background");
|
let logger = new Logger("background");
|
||||||
|
|
||||||
logger.pushUpdate = function (message)
|
logger.pushUpdate = function (message)
|
||||||
@@ -357,6 +406,12 @@ function queryTab(tab, message)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains a list of listeners that will act upon messages from the native app.
|
||||||
|
*
|
||||||
|
* @see handleMessage(message)
|
||||||
|
*/
|
||||||
|
var listeners = [
|
||||||
/**
|
/**
|
||||||
* A callback for when the native application sends a message.
|
* A callback for when the native application sends a message.
|
||||||
*
|
*
|
||||||
@@ -365,7 +420,7 @@ function queryTab(tab, message)
|
|||||||
* or a new value.
|
* or a new value.
|
||||||
* @return Either the value passed on returnValue or a new value.
|
* @return Either the value passed on returnValue or a new value.
|
||||||
*/
|
*/
|
||||||
var listeners = [function (message, returnValue) {
|
function (message, returnValue) {
|
||||||
if (typeof message == "object" && "type" in message)
|
if (typeof message == "object" && "type" in message)
|
||||||
{
|
{
|
||||||
let type = message.type;
|
let type = message.type;
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* The foreground script serves as the core for managing playback of a song. It receives messages forwarded from the background
|
||||||
|
*/
|
||||||
|
|
||||||
let logger = new Logger("foreground");
|
let logger = new Logger("foreground");
|
||||||
console.debug("Loading foreground.js");
|
console.debug("Loading foreground.js");
|
||||||
let background;
|
let background;
|
||||||
@@ -70,7 +76,16 @@ function handleMessage(message)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Calling this function will forward playback data to the browser background (and by extension, the
|
* Calling this function will forward playback data to the browser background (and by extension, the
|
||||||
* interface) as specified by the parameters.
|
* interface) as specified by the parameters. The sent data will be in the following format:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* {
|
||||||
|
* "type": "edu.regis.universeplayer.PlaybackInfo",
|
||||||
|
* "currentSong": {},
|
||||||
|
* "status": "STATUS",
|
||||||
|
* "playTime": 0
|
||||||
|
* }
|
||||||
|
* </code>
|
||||||
*
|
*
|
||||||
* @param {string} status The playback status. This can be "PLAYING", "PAUSED", "STOPPED",
|
* @param {string} status The playback status. This can be "PLAYING", "PAUSED", "STOPPED",
|
||||||
* "FINISHED", or "EMPTY"
|
* "FINISHED", or "EMPTY"
|
||||||
@@ -88,7 +103,14 @@ function onStatusUpdate(status, time, songData)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards an update to the background (and by extension, the interface).
|
* Forwards an update to the background (and by extension, the interface). The data will be in the following format:
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* {
|
||||||
|
* "type": "update",
|
||||||
|
* "data": {} // The actual data sent.
|
||||||
|
* }
|
||||||
|
* </code>
|
||||||
*
|
*
|
||||||
* @param {object|Promise} response The data to forward. If this data is a Promise, then the data
|
* @param {object|Promise} response The data to forward. If this data is a Promise, then the data
|
||||||
* will be forwarded upon completion.
|
* will be forwarded upon completion.
|
||||||
@@ -110,10 +132,16 @@ function sendUpdate(response)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
|
/*
|
||||||
|
* Preinitializes a few things
|
||||||
|
*/
|
||||||
while (preload.length > 0)
|
while (preload.length > 0)
|
||||||
{
|
{
|
||||||
preload.pop()();
|
preload.pop()();
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* Connects to the background.
|
||||||
|
*/
|
||||||
background = browser.runtime.connect({name:"universalMusic"});
|
background = browser.runtime.connect({name:"universalMusic"});
|
||||||
|
|
||||||
// sendUpdate("loaded");
|
// sendUpdate("loaded");
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import org.apache.tools.ant.taskdefs.condition.Os
|
|
||||||
|
|
||||||
import java.lang.reflect.Method
|
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Paths
|
|
||||||
import java.nio.file.StandardCopyOption
|
|
||||||
import java.util.stream.Stream
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This module contains a program separate from both the browser and the interface. Firefox's native messaging API can
|
||||||
|
* only start a process, it can't communicate with a process that is already running. That is where this module comes
|
||||||
|
* in. The browser will start this module, and the interface will create a server over the localhost. When this program
|
||||||
|
* is started, it connects to that server. It will then relay messages between the browser and interface, translating
|
||||||
|
* between JSON and serialized Java objects as needed.
|
||||||
*/
|
*/
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
@@ -16,10 +14,17 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
|
/**
|
||||||
|
* The native build artifact is used by the addon build process to ensure that it knows where the executable can be
|
||||||
|
* found. This is because the addon needs to have the executable registered on install.
|
||||||
|
*/
|
||||||
nativeBuild {
|
nativeBuild {
|
||||||
canBeConsumed = true
|
canBeConsumed = true
|
||||||
canBeResolved = false
|
canBeResolved = false
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* The install configuration is used for when we are packaging up the intermediary program.
|
||||||
|
*/
|
||||||
install {
|
install {
|
||||||
canBeConsumed = true
|
canBeConsumed = true
|
||||||
canBeResolved = false
|
canBeResolved = false
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package edu.regis.universeplayer.addon;
|
||||||
|
|
||||||
|
public class BrowserLinkTest
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This module is responsible for handling an instance of the Firefox web browser during runtime. This will install the
|
||||||
|
* appropriate version of Firefox Developer edition to the application installation directory, downloading it directly
|
||||||
|
* from Mozilla (administrator privileges are needed on Windows). It will also compile addon dependencies and add them
|
||||||
|
* to the install.
|
||||||
|
*
|
||||||
|
* This is all done prior to compiling the Java component of this module. The Java component is a single library that
|
||||||
|
* contains the appropriate methods to launch the browser and relay messages to and from the running instance.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.apache.tools.ant.taskdefs.condition.Os
|
import org.apache.tools.ant.taskdefs.condition.Os
|
||||||
@@ -12,10 +20,16 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
|
/**
|
||||||
|
* Addons are dependencies that will be added to the Firefox installation as an extension.
|
||||||
|
*/
|
||||||
addon {
|
addon {
|
||||||
canBeConsumed = false
|
canBeConsumed = false
|
||||||
canBeResolved = true
|
canBeResolved = true
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This will be how the browser policy and addon configuration will be exported.
|
||||||
|
*/
|
||||||
install {
|
install {
|
||||||
canBeConsumed = true
|
canBeConsumed = true
|
||||||
canBeResolved = false
|
canBeResolved = false
|
||||||
@@ -49,11 +63,6 @@ repositories {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class InstallBrowserTask extends DefaultTask {
|
|
||||||
@OutputFile
|
|
||||||
final abstract DirectoryProperty installation = project.objects.directoryProperty()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'org.slf4j:slf4j-api:1.7.30'
|
implementation 'org.slf4j:slf4j-api:1.7.30'
|
||||||
implementation 'org.apache.logging.log4j:log4j-api:2.13.3'
|
implementation 'org.apache.logging.log4j:log4j-api:2.13.3'
|
||||||
@@ -64,6 +73,11 @@ dependencies {
|
|||||||
addon project(path: ":add-on", configuration: 'addonBuild')
|
addon project(path: ":add-on", configuration: 'addonBuild')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the 64-bit Linux Firefox installer.
|
||||||
|
*
|
||||||
|
* @return The msi file that installs firefox.
|
||||||
|
*/
|
||||||
task downloadWindows_x86_64(type: Download) {
|
task downloadWindows_x86_64(type: Download) {
|
||||||
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/win64/en-US/Firefox%20Setup%20${firefox_revision}.msi"
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/win64/en-US/Firefox%20Setup%20${firefox_revision}.msi"
|
||||||
dest layout.buildDirectory.file("installer.msi")
|
dest layout.buildDirectory.file("installer.msi")
|
||||||
@@ -71,6 +85,11 @@ task downloadWindows_x86_64(type: Download) {
|
|||||||
onlyIfModified true
|
onlyIfModified true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the 32-bit Linux Firefox installer.
|
||||||
|
*
|
||||||
|
* @return The msi file that installs firefox.
|
||||||
|
*/
|
||||||
task downloadWindows_x86(type: Download) {
|
task downloadWindows_x86(type: Download) {
|
||||||
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/win32/en-US/Firefox%20Setup%20${firefox_revision}.msi"
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/win32/en-US/Firefox%20Setup%20${firefox_revision}.msi"
|
||||||
dest layout.buildDirectory.file("installer.msi")
|
dest layout.buildDirectory.file("installer.msi")
|
||||||
@@ -78,6 +97,11 @@ task downloadWindows_x86(type: Download) {
|
|||||||
onlyIfModified true
|
onlyIfModified true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the 64-bit Linux Firefox installation.
|
||||||
|
*
|
||||||
|
* @return The tar file that contains the Firefox download.
|
||||||
|
*/
|
||||||
task downloadLinux_x86_64(type: Download) {
|
task downloadLinux_x86_64(type: Download) {
|
||||||
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/linux-x86_64/en-US/firefox-${firefox_revision}.tar.bz2"
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/linux-x86_64/en-US/firefox-${firefox_revision}.tar.bz2"
|
||||||
dest layout.buildDirectory.file("installer.tar.bz2")
|
dest layout.buildDirectory.file("installer.tar.bz2")
|
||||||
@@ -85,6 +109,11 @@ task downloadLinux_x86_64(type: Download) {
|
|||||||
onlyIfModified true
|
onlyIfModified true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads the 32-bit Linux Firefox installation.
|
||||||
|
*
|
||||||
|
* @return The tar file that contains the Firefox download.
|
||||||
|
*/
|
||||||
task downloadLinux_i686(type: Download) {
|
task downloadLinux_i686(type: Download) {
|
||||||
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/linux-i686/en-US/firefox-${firefox_revision}.tar.bz2"
|
src "https://download-installer.cdn.mozilla.net/pub/${firefox_module}/releases/${firefox_revision}/linux-i686/en-US/firefox-${firefox_revision}.tar.bz2"
|
||||||
dest layout.buildDirectory.file("installer.tar.bz2")
|
dest layout.buildDirectory.file("installer.tar.bz2")
|
||||||
@@ -92,6 +121,14 @@ task downloadLinux_i686(type: Download) {
|
|||||||
onlyIfModified true
|
onlyIfModified true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs the 64-bit Windows Firefox to the firefox directory within the project root ($rootDir/firefox). Note that
|
||||||
|
* administrator privileges will be needed to properly install.
|
||||||
|
*
|
||||||
|
* This depends on the output of downloadWindows_x86_64.
|
||||||
|
*
|
||||||
|
* @return The directory Firefox was installed to.
|
||||||
|
*/
|
||||||
task installWindows_x86_64(dependsOn: downloadWindows_x86_64, type: Exec) {
|
task installWindows_x86_64(dependsOn: downloadWindows_x86_64, type: Exec) {
|
||||||
workingDir layout.buildDirectory
|
workingDir layout.buildDirectory
|
||||||
commandLine 'msiexec', '/i', '"' + downloadWindows_x86_64.dest + '"', '/li', '"install.log"', '/qb', "INSTALL_DIRECTORY_PATH=\"$rootDir\\firefox\"", 'TASKBAR_SHORTCUT=false', 'DESKTOP_SHORTCUT=false', 'INSTALL_MAINTENANCE_SERVICE=false'
|
commandLine 'msiexec', '/i', '"' + downloadWindows_x86_64.dest + '"', '/li', '"install.log"', '/qb', "INSTALL_DIRECTORY_PATH=\"$rootDir\\firefox\"", 'TASKBAR_SHORTCUT=false', 'DESKTOP_SHORTCUT=false', 'INSTALL_MAINTENANCE_SERVICE=false'
|
||||||
@@ -102,6 +139,14 @@ installWindows_x86_64.doFirst {
|
|||||||
println "Administrator privileges needed for installing Firefox. Please confirm on the popup."
|
println "Administrator privileges needed for installing Firefox. Please confirm on the popup."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs the 32-bit Windows Firefox to the firefox directory within the project root ($rootDir/firefox). Note that
|
||||||
|
* administrator privileges will be needed to properly install.
|
||||||
|
*
|
||||||
|
* This depends on the output of downloadWindows_x86.
|
||||||
|
*
|
||||||
|
* @return The directory Firefox was installed to.
|
||||||
|
*/
|
||||||
task installWindows_x86(dependsOn: downloadWindows_x86, type: Exec) {
|
task installWindows_x86(dependsOn: downloadWindows_x86, type: Exec) {
|
||||||
workingDir layout.buildDirectory
|
workingDir layout.buildDirectory
|
||||||
commandLine 'msiexec', '/i', '"' + downloadWindows_x86.dest + '"', '/li', '"install.log"', '/qb', "INSTALL_DIRECTORY_PATH=\"$rootDir/firefox\"", 'TASKBAR_SHORTCUT=false', 'DESKTOP_SHORTCUT=false', 'INSTALL_MAINTENANCE_SERVICE=false'
|
commandLine 'msiexec', '/i', '"' + downloadWindows_x86.dest + '"', '/li', '"install.log"', '/qb', "INSTALL_DIRECTORY_PATH=\"$rootDir/firefox\"", 'TASKBAR_SHORTCUT=false', 'DESKTOP_SHORTCUT=false', 'INSTALL_MAINTENANCE_SERVICE=false'
|
||||||
@@ -112,10 +157,20 @@ installWindows_x86.doFirst {
|
|||||||
println "Administrator privileges needed for installing Firefox. Please confirm on the popup."
|
println "Administrator privileges needed for installing Firefox. Please confirm on the popup."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the Firefox installation directory, $rootDir/firefox.
|
||||||
|
*/
|
||||||
task deleteFirefoxWindows(type: Delete) {
|
task deleteFirefoxWindows(type: Delete) {
|
||||||
delete "$rootDir/firefox"
|
delete "$rootDir/firefox"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoke's the Firefox's Windows uninstaller.
|
||||||
|
*
|
||||||
|
* This task will call deleteFirefoxWindows.
|
||||||
|
*
|
||||||
|
* @return The directory Firefox was installed to.
|
||||||
|
*/
|
||||||
task uninstallFirefoxWindows(type: Exec) {
|
task uninstallFirefoxWindows(type: Exec) {
|
||||||
workingDir layout.buildDirectory
|
workingDir layout.buildDirectory
|
||||||
commandLine 'cmd', '/c', "$rootDir\\firefox\\uninstall\\helper.exe", '/S'
|
commandLine 'cmd', '/c', "$rootDir\\firefox\\uninstall\\helper.exe", '/S'
|
||||||
@@ -126,6 +181,13 @@ uninstallFirefoxWindows.doFirst {
|
|||||||
}
|
}
|
||||||
uninstallFirefoxWindows.finalizedBy deleteFirefoxWindows
|
uninstallFirefoxWindows.finalizedBy deleteFirefoxWindows
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs the 64-bit Linux Firefox to the firefox directory within the project root ($rootDir/firefox).
|
||||||
|
*
|
||||||
|
* This depends on the output of downloadLinux_x86_64.
|
||||||
|
*
|
||||||
|
* @return The directory Firefox was installed to.
|
||||||
|
*/
|
||||||
task installLinux_x86_64(dependsOn: downloadLinux_x86_64, type: Copy) {
|
task installLinux_x86_64(dependsOn: downloadLinux_x86_64, type: Copy) {
|
||||||
from(tarTree(downloadLinux_x86_64.dest)) {
|
from(tarTree(downloadLinux_x86_64.dest)) {
|
||||||
include "firefox/**"
|
include "firefox/**"
|
||||||
@@ -137,6 +199,13 @@ task installLinux_x86_64(dependsOn: downloadLinux_x86_64, type: Copy) {
|
|||||||
// outputs.dir(new File(rootDir, "firefox"))
|
// outputs.dir(new File(rootDir, "firefox"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs the 32-bit Linux Firefox to the firefox directory within the project root ($rootDir/firefox).
|
||||||
|
*
|
||||||
|
* This depends on the output of downloadLinux_i686.
|
||||||
|
*
|
||||||
|
* @return The directory Firefox was installed to.
|
||||||
|
*/
|
||||||
task installLinux_i686(dependsOn: downloadLinux_i686, type: Copy) {
|
task installLinux_i686(dependsOn: downloadLinux_i686, type: Copy) {
|
||||||
from(tarTree(downloadLinux_i686.dest)) {
|
from(tarTree(downloadLinux_i686.dest)) {
|
||||||
include "firefox/**"
|
include "firefox/**"
|
||||||
@@ -148,6 +217,14 @@ task installLinux_i686(dependsOn: downloadLinux_i686, type: Copy) {
|
|||||||
outputs.dir("$rootDir/firefox")
|
outputs.dir("$rootDir/firefox")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs the version of Firefox appropriate for the current system.
|
||||||
|
*
|
||||||
|
* This depends on the output of installWindows_x86_64, installWindows_x86, installLinux_x86_64, or installLinux_i686,
|
||||||
|
* depending on the architecture.
|
||||||
|
*
|
||||||
|
* @return The directory Firefox was installed in.
|
||||||
|
*/
|
||||||
task installFirefox() {
|
task installFirefox() {
|
||||||
if (Os.isFamily(Os.FAMILY_WINDOWS))
|
if (Os.isFamily(Os.FAMILY_WINDOWS))
|
||||||
{
|
{
|
||||||
@@ -201,6 +278,11 @@ task installFirefox() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the folders that addons will be stored in, the /distribution/extensions folder.
|
||||||
|
*
|
||||||
|
* This task depends on installFirefox.
|
||||||
|
*/
|
||||||
task setupProfile {
|
task setupProfile {
|
||||||
dependsOn installFirefox
|
dependsOn installFirefox
|
||||||
doFirst {
|
doFirst {
|
||||||
@@ -215,10 +297,19 @@ task setupProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This task sets up the policies that Firefox will use when creating new profiles. These are copied from the
|
||||||
|
* browserConf directory.
|
||||||
|
*
|
||||||
|
* This task depends on setupProfile.
|
||||||
|
*/
|
||||||
task movePolicies(type: Copy) {
|
task movePolicies(type: Copy) {
|
||||||
dependsOn setupProfile
|
dependsOn setupProfile
|
||||||
from files("browserConf")
|
from files("browserConf")
|
||||||
into "$rootDir/firefox/"
|
into "$rootDir/firefox/"
|
||||||
|
/*
|
||||||
|
* Registers any required addons as needed.
|
||||||
|
*/
|
||||||
filesMatching('**/policies.json'){
|
filesMatching('**/policies.json'){
|
||||||
def pre = ""
|
def pre = ""
|
||||||
for (File addon: configurations.addon.resolve())
|
for (File addon: configurations.addon.resolve())
|
||||||
@@ -240,6 +331,11 @@ task movePolicies(type: Copy) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds all addon dependencies and copies them to the Firefox installation's distribution/extensions folder.
|
||||||
|
*
|
||||||
|
* Depends on installFirefox, setupProfile, and addon dependencies.
|
||||||
|
*/
|
||||||
task installAddons(type: Copy) {
|
task installAddons(type: Copy) {
|
||||||
dependsOn setupProfile
|
dependsOn setupProfile
|
||||||
dependsOn configurations.addon
|
dependsOn configurations.addon
|
||||||
@@ -250,6 +346,11 @@ task installAddons(type: Copy) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zips all addons and browser policies into a conf.tar file.
|
||||||
|
*
|
||||||
|
* I don't actually remember what this is supposed to do.
|
||||||
|
*/
|
||||||
task zipPolicies(type: Tar) {
|
task zipPolicies(type: Tar) {
|
||||||
archiveFileName = "conf.tar"
|
archiveFileName = "conf.tar"
|
||||||
destinationDirectory = file("$buildDir")
|
destinationDirectory = file("$buildDir")
|
||||||
@@ -280,9 +381,15 @@ tasks.named('clean') {
|
|||||||
}
|
}
|
||||||
println configurations.getNames()
|
println configurations.getNames()
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The java runtime requires the browser to be set up beforehand.
|
||||||
|
*/
|
||||||
compileJava.dependsOn installAddons
|
compileJava.dependsOn installAddons
|
||||||
compileJava.dependsOn movePolicies
|
compileJava.dependsOn movePolicies
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Exports the addons and policy configuration.
|
||||||
|
*/
|
||||||
artifacts {
|
artifacts {
|
||||||
install(zipPolicies)
|
install(zipPolicies)
|
||||||
}
|
}
|
||||||
@@ -4,16 +4,17 @@
|
|||||||
|
|
||||||
package edu.regis.universeplayer.browser;
|
package edu.regis.universeplayer.browser;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import edu.regis.universeplayer.ConfigManager;
|
||||||
|
import edu.regis.universeplayer.Log;
|
||||||
|
import edu.regis.universeplayer.browserCommands.BrowserConstants;
|
||||||
|
import edu.regis.universeplayer.browserCommands.MessageRunner;
|
||||||
import org.apache.logging.log4j.core.DefaultLoggerContextAccessor;
|
import org.apache.logging.log4j.core.DefaultLoggerContextAccessor;
|
||||||
import org.apache.logging.log4j.core.LogEvent;
|
import org.apache.logging.log4j.core.LogEvent;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
@@ -24,43 +25,69 @@ import java.util.Arrays;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import edu.regis.universeplayer.ConfigManager;
|
/**
|
||||||
import edu.regis.universeplayer.Log;
|
* This message runner is responsible for starting an instance of a browser
|
||||||
import edu.regis.universeplayer.browserCommands.BrowserConstants;
|
* and running messages to and from it. This runner provides a static method,
|
||||||
import edu.regis.universeplayer.browserCommands.MessageRunner;
|
* {@link #createBrowser()}, that starts an instance of the Firefox browser.
|
||||||
import edu.regis.universeplayer.browserCommands.UpdateListener;
|
* That instance contains an addon that starts up a third process, the
|
||||||
|
* intermediary program. The intermediary program connects to the interface
|
||||||
|
* and relays messages between the browser and this runner.
|
||||||
|
*/
|
||||||
public class Browser extends MessageRunner
|
public class Browser extends MessageRunner
|
||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Browser.class);
|
private static final Logger logger = LoggerFactory.getLogger(Browser.class);
|
||||||
private static final Logger browserLogger =
|
private static final Logger browserLogger =
|
||||||
LoggerFactory.getLogger("browser");
|
LoggerFactory.getLogger("browser");
|
||||||
|
|
||||||
private static Browser INSTANCE;
|
private static Browser INSTANCE;
|
||||||
|
/*
|
||||||
|
* This boolean keeps track of whether the browser has started or not.
|
||||||
|
* Threads that need to wait for the browser to start can wait upon this
|
||||||
|
* object's monitor.
|
||||||
|
*/
|
||||||
private static final AtomicBoolean instanceWaiter = new AtomicBoolean();
|
private static final AtomicBoolean instanceWaiter = new AtomicBoolean();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the running instance of the browser.
|
||||||
|
*
|
||||||
|
* @return The running Browser instance, or null if it is not running.
|
||||||
|
*/
|
||||||
public static Browser getInstance()
|
public static Browser getInstance()
|
||||||
{
|
{
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Process process;
|
private final Process process;
|
||||||
private final ServerSocket server;
|
private final ServerSocket server;
|
||||||
private final Socket socket;
|
private final Socket socket;
|
||||||
|
|
||||||
private boolean running = true;
|
private boolean running = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launches a browser instance.
|
||||||
|
*
|
||||||
|
* @return The instance launched.
|
||||||
|
* @throws IOException
|
||||||
|
* @throws InterruptedException
|
||||||
|
*/
|
||||||
public static Browser createBrowser() throws IOException, InterruptedException
|
public static Browser createBrowser() throws IOException, InterruptedException
|
||||||
{
|
{
|
||||||
if (INSTANCE != null)
|
if (INSTANCE != null)
|
||||||
{
|
{
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Creates a server on the localhost. When the browser starts the
|
||||||
|
* intermediary program, that program will attempt to connect to this
|
||||||
|
* server. Any messages the browser outputs will eventually be received
|
||||||
|
* here, and any messages to send will first be pushed through this
|
||||||
|
* server.
|
||||||
|
*/
|
||||||
ServerSocket server = new ServerSocket(BrowserConstants.PORT, 50, InetAddress
|
ServerSocket server = new ServerSocket(BrowserConstants.PORT, 50, InetAddress
|
||||||
.getByName(null));
|
.getByName(null));
|
||||||
logger.debug("Server started.");
|
logger.debug("Server started.");
|
||||||
|
|
||||||
int startExit;
|
int startExit;
|
||||||
Process browserProcess = launchBrowser();
|
Process browserProcess = launchBrowser();
|
||||||
/*
|
/*
|
||||||
@@ -85,7 +112,10 @@ public class Browser extends MessageRunner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug("Browser started.");
|
logger.debug("Browser started.");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Waits for the intermediary program to connect to our server.
|
||||||
|
*/
|
||||||
ConnectException connErr = null;
|
ConnectException connErr = null;
|
||||||
logger.debug("Attempting connection");
|
logger.debug("Attempting connection");
|
||||||
Socket socket = server.accept();
|
Socket socket = server.accept();
|
||||||
@@ -113,12 +143,25 @@ public class Browser extends MessageRunner
|
|||||||
{
|
{
|
||||||
logger.debug("Connection established.");
|
logger.debug("Connection established.");
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* Now that the socket connection has been set up, we can create the
|
||||||
|
* message runner.
|
||||||
|
*/
|
||||||
INSTANCE = new Browser(socket, server, browserProcess);
|
INSTANCE = new Browser(socket, server, browserProcess);
|
||||||
instanceWaiter.set(true);
|
instanceWaiter.set(true);
|
||||||
notifyAllInstance();
|
notifyAllInstance();
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a browser message runner,
|
||||||
|
*
|
||||||
|
* @param socket - The socket that the browser's intermediary program is
|
||||||
|
* using.
|
||||||
|
* @param server - The server that is hosting the above socket.
|
||||||
|
* @param process - The process controlling the browser instance.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
private Browser(Socket socket, ServerSocket server, Process process) throws IOException
|
private Browser(Socket socket, ServerSocket server, Process process) throws IOException
|
||||||
{
|
{
|
||||||
super("BrowserRunner", socket.getInputStream(), socket
|
super("BrowserRunner", socket.getInputStream(), socket
|
||||||
@@ -126,9 +169,9 @@ public class Browser extends MessageRunner
|
|||||||
this.socket = socket;
|
this.socket = socket;
|
||||||
this.server = server;
|
this.server = server;
|
||||||
this.process = process;
|
this.process = process;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sends browser logs to the main log.
|
* Automatically sends browser logs that come through to the main log.
|
||||||
*/
|
*/
|
||||||
this.addUpdateListener((object, runner) ->
|
this.addUpdateListener((object, runner) ->
|
||||||
{
|
{
|
||||||
@@ -142,7 +185,7 @@ public class Browser extends MessageRunner
|
|||||||
Object[] params = null;
|
Object[] params = null;
|
||||||
if (log.message.length == 1 && !(log.message[0] instanceof String))
|
if (log.message.length == 1 && !(log.message[0] instanceof String))
|
||||||
{
|
{
|
||||||
log.message = new Object[] {"{}", log.message[0]};
|
log.message = new Object[]{"{}", log.message[0]};
|
||||||
}
|
}
|
||||||
if (log.message.length == 1)
|
if (log.message.length == 1)
|
||||||
{
|
{
|
||||||
@@ -202,7 +245,13 @@ public class Browser extends MessageRunner
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc} This keeps the thread running for as long as the
|
||||||
|
* connection exists.
|
||||||
|
*
|
||||||
|
* @return Whether we chould stop this thread or not.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean onRun()
|
protected boolean onRun()
|
||||||
{
|
{
|
||||||
@@ -214,7 +263,10 @@ public class Browser extends MessageRunner
|
|||||||
}
|
}
|
||||||
return !this.running;
|
return !this.running;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc} This shuts down the socket, server, and browser process.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onClose()
|
protected void onClose()
|
||||||
{
|
{
|
||||||
@@ -243,18 +295,19 @@ public class Browser extends MessageRunner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Called to stop the browser.
|
||||||
*/
|
*/
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
this.running = false;
|
this.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method for launching a browser instance
|
* Utility method for launching a browser instance process.
|
||||||
*
|
*
|
||||||
|
* @return The process responsible for the browser.
|
||||||
* @throws IOException - Thrown if there is a problem launching the
|
* @throws IOException - Thrown if there is a problem launching the
|
||||||
* browser.
|
* browser.
|
||||||
*/
|
*/
|
||||||
@@ -290,15 +343,23 @@ public class Browser extends MessageRunner
|
|||||||
{
|
{
|
||||||
throw new IOException("Could not find Firefox installation for OS " + os + " " + arch);
|
throw new IOException("Could not find Firefox installation for OS " + os + " " + arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return process;
|
return process;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void notifyInstance()
|
/**
|
||||||
|
* Notifies a single random waiting thread that the browser message
|
||||||
|
* runner has started.
|
||||||
|
*/
|
||||||
|
private static void notifyInstance()
|
||||||
{
|
{
|
||||||
instanceWaiter.notify();
|
instanceWaiter.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alerts all threads waiting for the browser to start that the browser has
|
||||||
|
* started.
|
||||||
|
*/
|
||||||
public static void notifyAllInstance()
|
public static void notifyAllInstance()
|
||||||
{
|
{
|
||||||
synchronized (instanceWaiter)
|
synchronized (instanceWaiter)
|
||||||
@@ -306,7 +367,13 @@ public class Browser extends MessageRunner
|
|||||||
instanceWaiter.notifyAll();
|
instanceWaiter.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes the current thread to wait for the browser process to start and
|
||||||
|
* the message runner to properly set up.
|
||||||
|
*
|
||||||
|
* @throws InterruptedException
|
||||||
|
*/
|
||||||
public static void waitInstance() throws InterruptedException
|
public static void waitInstance() throws InterruptedException
|
||||||
{
|
{
|
||||||
synchronized (instanceWaiter)
|
synchronized (instanceWaiter)
|
||||||
@@ -314,7 +381,13 @@ public class Browser extends MessageRunner
|
|||||||
instanceWaiter.wait();
|
instanceWaiter.wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes the current thread to wait for the browser process to start and
|
||||||
|
* the message runner to properly set up.
|
||||||
|
*
|
||||||
|
* @throws InterruptedException
|
||||||
|
*/
|
||||||
public static void waitInstance(long timeoutMillis) throws InterruptedException
|
public static void waitInstance(long timeoutMillis) throws InterruptedException
|
||||||
{
|
{
|
||||||
synchronized (instanceWaiter)
|
synchronized (instanceWaiter)
|
||||||
@@ -322,7 +395,13 @@ public class Browser extends MessageRunner
|
|||||||
instanceWaiter.wait(timeoutMillis);
|
instanceWaiter.wait(timeoutMillis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes the current thread to wait for the browser process to start and
|
||||||
|
* the message runner to properly set up.
|
||||||
|
*
|
||||||
|
* @throws InterruptedException
|
||||||
|
*/
|
||||||
public static void waitInstance(long timeoutMillis, int nanos) throws InterruptedException
|
public static void waitInstance(long timeoutMillis, int nanos) throws InterruptedException
|
||||||
{
|
{
|
||||||
synchronized (instanceWaiter)
|
synchronized (instanceWaiter)
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
* Copyright (c) 2021 William Hubbard. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This module contains a series of classes used by multiple modules (notably, the :browser and :interface modules).
|
||||||
|
* Notably, it contains commands that the browser reacts to, the response structure, and data structures that is
|
||||||
|
* frequently passed to and from the interface and browser.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
@@ -24,6 +28,8 @@ dependencies {
|
|||||||
|
|
||||||
implementation 'net.harawata:appdirs:1.2.1'
|
implementation 'net.harawata:appdirs:1.2.1'
|
||||||
|
|
||||||
|
implementation 'net.harawata:appdirs:1.2.1'
|
||||||
|
|
||||||
// Declare the dependency for your favourite test framework you want to use in your tests.
|
// Declare the dependency for your favourite test framework you want to use in your tests.
|
||||||
// TestNG is also supported by the Gradle Test task. Just change the
|
// TestNG is also supported by the Gradle Test task. Just change the
|
||||||
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
|
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.util.Arrays;
|
|||||||
public interface MessageSerializer
|
public interface MessageSerializer
|
||||||
{
|
{
|
||||||
Logger getLogger();
|
Logger getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an object into a form that can be sent.
|
* Converts an object into a form that can be sent.
|
||||||
*
|
*
|
||||||
@@ -33,7 +33,7 @@ public interface MessageSerializer
|
|||||||
return byteStream.toByteArray();
|
return byteStream.toByteArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a byte stream into an object.
|
* Converts a byte stream into an object.
|
||||||
*
|
*
|
||||||
@@ -57,15 +57,20 @@ public interface MessageSerializer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes a message to the output stream.
|
* Writes a message to the output stream.
|
||||||
|
* <p>
|
||||||
|
* By default, it will first write the number of the message (one integer
|
||||||
|
* of 4 bytes), and then the length of the message in bytes (another
|
||||||
|
* integer of four bytes). It finally writes the data stream before
|
||||||
|
* flushing the stream.
|
||||||
*
|
*
|
||||||
* @param out - The output stream to write to.
|
* @param out - The output stream to write to.
|
||||||
* @param messageNum - The ID of the message being sent. This will help keep
|
* @param messageNum - The ID of the message being sent. This will help keep
|
||||||
* track of responses.
|
* track of responses.
|
||||||
* @param message - The actual message contents to write.
|
* @param message - The actual message contents to write.
|
||||||
* @throws IOException Thrown when an exception occures
|
* @throws IOException Thrown when an exception occurs
|
||||||
*/
|
*/
|
||||||
default void writeMessage(OutputStream out, int messageNum, byte[] message) throws IOException
|
default void writeMessage(OutputStream out, int messageNum, byte[] message) throws IOException
|
||||||
{
|
{
|
||||||
@@ -94,9 +99,9 @@ public interface MessageSerializer
|
|||||||
out.write(message);
|
out.write(message);
|
||||||
out.flush();
|
out.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads a message from the input stream
|
* Reads a message from the input stream.
|
||||||
*
|
*
|
||||||
* @param in - The input stream to read from.
|
* @param in - The input stream to read from.
|
||||||
* @return Two byte arrays, each with their own value encoded. The first is
|
* @return Two byte arrays, each with their own value encoded. The first is
|
||||||
@@ -153,7 +158,7 @@ public interface MessageSerializer
|
|||||||
getLogger().trace("Reading message");
|
getLogger().trace("Reading message");
|
||||||
return new byte[][]{messageNum, message};
|
return new byte[][]{messageNum, message};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called when an error in deserialization occurs.
|
* This method is called when an error in deserialization occurs.
|
||||||
*
|
*
|
||||||
|
|||||||
BIN
interface/src/test/resources/samples/Fishing_village.wav
Normal file
BIN
interface/src/test/resources/samples/Fishing_village.wav
Normal file
Binary file not shown.
BIN
interface/src/test/resources/samples/Rising_Moon.mp3
Normal file
BIN
interface/src/test/resources/samples/Rising_Moon.mp3
Normal file
Binary file not shown.
Binary file not shown.
BIN
interface/src/test/resources/samples/ambient2(Nautilus).mp3
Normal file
BIN
interface/src/test/resources/samples/ambient2(Nautilus).mp3
Normal file
Binary file not shown.
BIN
interface/src/test/resources/samples/k.wav
Normal file
BIN
interface/src/test/resources/samples/k.wav
Normal file
Binary file not shown.
BIN
interface/src/test/resources/samples/sPACE.wav
Normal file
BIN
interface/src/test/resources/samples/sPACE.wav
Normal file
Binary file not shown.
BIN
interface/src/test/resources/samples/song_of_the_sea.ogg
Normal file
BIN
interface/src/test/resources/samples/song_of_the_sea.ogg
Normal file
Binary file not shown.
Reference in New Issue
Block a user