diff --git a/bin/servercoms.py b/bin/servercoms.py new file mode 100644 index 0000000..b54b320 --- /dev/null +++ b/bin/servercoms.py @@ -0,0 +1,48 @@ +import requests + +class ServerComs: + def __init__(self): + pass + + def connect(self, url): + try: + self.x = requests.get(f"{url}/tryconnect") + return True + except Exception: + return False + + def postcurrentsong(self, url, data): + try: + self.x = requests.post(f"{url}/postcurrentsong", {"songname":data}) + return True + except Exception: + return False + + def postupcomingsongs(self, url, data): + try: + self.x = requests.post(f"{url}/postupcomingsongs", {"songs":data}) + return True + except Exception: + return False + + def postplaybackpos(self, url, data): + try: + self.x = requests.post(f"{url}/postplayback", {"pos":data}) + return True + except Exception: + return False + + def postsonglength(self, url, data): + try: + self.x = requests.post(f"{url}/postsonglength", {"length":data}) + return True + except Exception: + return False + + def postfullscreen(self, url, data): + try: + self.x = requests.post(f"{url}/postfullscreen", {"fullscreen":data}) + return True + except Exception: + return False + \ No newline at end of file diff --git a/nodeserver/server.js b/nodeserver/server.js new file mode 100644 index 0000000..ddca80e --- /dev/null +++ b/nodeserver/server.js @@ -0,0 +1,93 @@ +const express = require('express'); +const http = require('http'); +const bodyParser = require('body-parser'); +const ip = require('ip') + +// GET IP OF SYSTEM AND DISPLAY TO USER +console.log("\n\nThis PC's IP address: " + ip.address()); +console.log("Use this IP address when connecting to this server from the player and display!") + +// INITIALIZE VARIABLES +var app = express(); +var playbackpos = "1" +var upcomingsongs = "Test\nTest2\nTest3" +var currentsong = "This is a song" +var songmaxlength = "100" +var fullscreen = "False" + + +// CONFIG FOR EXPRESS +app.use(bodyParser.urlencoded({extended : true})) + + +///////////////// +////// API ////// +///////////////// + +app.get('/tryconnect', (request, response) => { + console.log("connecting") + response.send("ok") +}) + + +// Get data (Interface for Screen) +app.get('/playbackpos', (request, response) => { + response.send(playbackpos) +}) + +app.get('/upcomingsongs', (request, response) => { + response.send(upcomingsongs) +}) + +app.get('/songmaxlength', (request, response) => { + response.send(songmaxlength) +}) + +app.get('/currentsong', (request, response) => { + response.send(currentsong) +}) + +app.get('/fullscreen', (request, response) => { + response.send(fullscreen) +}) + + +// POST data (Interface for Player) +app.post('/postplayback', (request, response) => { + playbackpos = request.body.pos + response.send("ok") +}) + +app.post('/postupcomingsogns', (request, response) => { + upcomingsongs = request.body.songs + response.send("ok") +}) + +app.post('/postcurrentsong', (request, response) => { + currentsong = request.body.songname + response.send("ok") +}) + +app.post('/postfullscreen', (request, response) => { + fullscreen = request.body.fullscreen + response.send("ok") +}) + +app.post('/postsonglength', (request, response) => { + songmaxlength = request.body.length + response.send("ok") +}) + + +// Test functions +app.post('/testrequest', (request, response) => { + console.log("request received") + console.log(request.body) + response.send(request.body) + response.status(200) +}) + +// Create and run server +http.createServer(app).listen(8000, function () { + console.log("\n\n-------------------\n\n Server started\n\n-------------------\n") +}) \ No newline at end of file