added bash script to automatically start gameplay

This commit is contained in:
2021-08-22 01:08:01 +04:00
parent c5bed3afa2
commit 27c7e264b8
9 changed files with 77 additions and 42 deletions

3
.gitignore vendored
View File

@@ -2,4 +2,5 @@ config.json
env/ env/
remotegameplay remotegameplay
room.json room.json
laplace laplace
/scripts

View File

@@ -23,7 +23,7 @@ type Config struct {
BarrierHostName string BarrierHostName string
Rooms string Rooms string
IPAddress string IPAddress string
BinaryToExecute string ScriptToExecute string
} }
// Exists reports whether the named file or directory exists. // Exists reports whether the named file or directory exists.
@@ -62,7 +62,7 @@ func SetDefaults() error {
defaults["BarrierHostName"] = name defaults["BarrierHostName"] = name
defaults["Rooms"] = defaultPath + "room.json" defaults["Rooms"] = defaultPath + "room.json"
defaults["IPAddress"] = "0.0.0.0" defaults["IPAddress"] = "0.0.0.0"
defaults["BinaryToExecute"] = "/home/akilan/.local/share/Steam/steamapps/common/X-Plane 11" defaults["ScriptToExecute"] = ""
//Paths to search for config file //Paths to search for config file
configPaths = append(configPaths, defaultPath) configPaths = append(configPaths, defaultPath)

View File

@@ -25,16 +25,16 @@
<div class="separator"></div> <div class="separator"></div>
<h4>Start sharing your screen</h4> <!-- <h4>Start sharing your screen</h4>-->
<p class="help-text"> <!-- <p class="help-text">-->
Click the button below to create a new streaming room, <!-- Click the button below to create a new streaming room,-->
where you can share your screen with your peers. <!-- where you can share your screen with your peers.-->
A RoomID will be generated, and you can share the RoomID to your peers. <!-- A RoomID will be generated, and you can share the RoomID to your peers.-->
</p> <!-- </p>-->
<button type="button" class="btn btn-dark btn-block" id="btnStream">Start sharing</button> <!-- <button type="button" class="btn btn-dark btn-block" id="btnStream">Start sharing</button>-->
<div class="separator"></div> <!-- <div class="separator"></div>-->
<h4>Join streaming room</h4> <h4>Join streaming room</h4>
<p class="help-text"> <p class="help-text">

View File

@@ -225,8 +225,9 @@ function getServerHostName() {
// Source https://stackoverflow.com/questions/247483/http-get-request-in-javascript // Source https://stackoverflow.com/questions/247483/http-get-request-in-javascript
var xmlHttp = new XMLHttpRequest() var xmlHttp = new XMLHttpRequest()
xmlHttp.open( "GET", getHttpUrl() + "/hostname", false ); // false for synchronous request xmlHttp.open( "GET", getHttpUrl() + "/hostname", false ); // false for synchronous request
xmlHttp.send( null ); xmlHttp.send(null);
LaplaceVar.ui.barrierhostname.innerHTML = xmlHttp.responseText LaplaceVar.ui.barrierhostname.innerHTML = xmlHttp.responseText
//console.log(window.location.href.split('?')[0])
} }
function updateStatusUIStream() { function updateStatusUIStream() {
@@ -252,7 +253,7 @@ function getWebsocketUrl() {
function getHttpUrl() { function getHttpUrl() {
//if (window.location.protocol === "https:") { //if (window.location.protocol === "https:") {
return `${window.location.href}` return window.location.href.split('?')[0]
// } else { // } else {
// return `${window.location.href}` // return `${window.location.href}`
// } // }
@@ -580,8 +581,17 @@ function routeByUrl() {
if (paramStream && paramStream.length > 0) { if (paramStream && paramStream.length > 0) {
return doStream(); return doStream();
} }
// If the room ID is provided
const roomId = u.searchParams.get('roomID');
if (roomId && roomId.length > 0) {
AddRoomID(roomId);
}
} }
// Adds the room information to the ID inputRoomID
function AddRoomID(roomID) {
document.getElementById('inputRoomID').value = roomID
}
function leaveRoom() { function leaveRoom() {
window.location.href = getBaseUrl(); window.location.href = getBaseUrl();
} }

View File

@@ -7,38 +7,24 @@
# Updating and installing go compiler # Updating and installing go compiler
apt update apt update
apt install -y golang apt install -y golang
apt install -y jq
# Installing git ## Installing git
apt install -y git apt install -y git
## Installing barrier
# Installing barrier
apt install -y barrier apt install -y barrier
## Installing chromium
# Installing chromium
wget https://github.com/RobRich999/Chromium_Clang/releases/download/v94.0.4585.0-r904940-linux64-deb-avx/chromium-browser-unstable_94.0.4585.0-1_amd64.deb wget https://github.com/RobRich999/Chromium_Clang/releases/download/v94.0.4585.0-r904940-linux64-deb-avx/chromium-browser-unstable_94.0.4585.0-1_amd64.deb
apt install -y ./chromium-browser-unstable_94.0.4585.0-1_amd64.deb apt install -y ./chromium-browser-unstable_94.0.4585.0-1_amd64.deb
#
# clone remotegameplay distribution ## clone remotegameplay distribution
git clone https://github.com/Akilan1999/remotegameplay git clone https://github.com/Akilan1999/remotegameplay
# enter cloned directory ## enter cloned directory
cd remotegameplay cd remotegameplay
# sets REMOTEGAMEPLAY path
export REMOTEGAMEPLAY=$PWD export REMOTEGAMEPLAY=$PWD
# Build laplace binary file # Build laplace binary file
go build . go build .
./laplace -setconfig # Set configuration laplace file
./laplace -tls -addr 0.0.0.0:8888 & ./laplace -setconfig
./laplace -headless -addr `$1` &
sleep 2
./laplace -headless -roomInfo >> /tmp/output.txt
# Installation game script here and start remote gameplay

14
main.go
View File

@@ -71,7 +71,7 @@ func main() {
TaskExecute = *BinaryToExcute TaskExecute = *BinaryToExcute
} else { } else {
// Read binary from config file // Read binary from config file
TaskExecute = Config.BinaryToExecute TaskExecute = Config.ScriptToExecute
} }
// Starting screen share headless // Starting screen share headless
@@ -84,7 +84,11 @@ func main() {
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
// Task to be executed // Task to be executed
RunTask(TaskExecute) err = RunTask(TaskExecute)
if err != nil {
fmt.Println(err)
return
}
return return
@@ -94,7 +98,7 @@ func main() {
if *killServer { if *killServer {
cmd := exec.Command("pkill" ,"laplace") cmd := exec.Command("pkill" ,"laplace")
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Fatalln(err) fmt.Println(err)
} }
return return
} }
@@ -102,7 +106,7 @@ func main() {
if *killChromium { if *killChromium {
cmd := exec.Command("pkill" ,"chromium") cmd := exec.Command("pkill" ,"chromium")
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Fatalln(err) fmt.Println(err)
} }
return return
} }
@@ -151,7 +155,7 @@ func Ip4or6(s string) string {
func RunTask(task string) error { func RunTask(task string) error {
// Halts the process // Halts the process
cmd := exec.Command(task) cmd := exec.Command("sh",task)
if err := cmd.Start(); err != nil { if err := cmd.Start(); err != nil {
return err return err
} }

28
run.sh Normal file
View File

@@ -0,0 +1,28 @@
# Starts server and runs it silently (i.e no output in the terminal)
./laplace -tls -addr 0.0.0.0:8888 > /dev/null 2>&1 &
# Starts chromium browser and runs it silently (i.e no output in the terminal)
./laplace -headless -addr ${1} > /dev/null 2>&1 &
# Lets the script sleep for 2 seconds
sleep 2
# Gets roomInfo and stores in the tmp directory as JSON
./laplace -headless -roomInfo > /tmp/output.txt
# Gets the room ID from the JSON file and outputs to tmp directory as text
jq .id /tmp/output.txt > /tmp/test.txt
# Gets roomID from tmp directory as text
roomID=$(cat /tmp/test.txt)
# remove " from string
roomID=$(echo "$roomID" | tr -d '"')
# Checks if the IP address is a IPV6 or IPV4 address
if [ "$1" != "${1#*[0-9].[0-9]}" ]; then
echo "https://"${1}":8888/?roomID="${roomID}
elif [ "$1" != "${1#*:[0-9a-fA-F]}" ]; then
echo "https://["${1}"]:8888/?roomID="${roomID}
else
echo "Unrecognized IP format '$1'"
fi

0
scripts/.gitkeep Normal file
View File

6
scripts/xplane11 Executable file
View File

@@ -0,0 +1,6 @@
# Navigating to the directory where XPlane11 is present
cd /home/akilan/.local/share/Steam/steamapps/common/X-Plane\ 11/
# Execute Xplane 11 binary
./X-Plane-x86_64