From bfdd897a2096a009e28df6dce7cc332b162f50b4 Mon Sep 17 00:00:00 2001 From: ShakedAp Date: Sun, 25 Jun 2023 09:07:52 +0300 Subject: [PATCH] Added settings file and removed videos from repo Created settings.json that contains the settings Created .gitignore that ignores the videos folder Modified index.js to take the settings settings.json Modified client.js to take the WebSocket settings from the window --- .gitignore | 1 + client.js | 11 +++++++++-- index.js | 5 +++-- settings.json | 5 +++++ 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 settings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6aa7838 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vidoes \ No newline at end of file diff --git a/client.js b/client.js index 03fd9cd..e969b18 100644 --- a/client.js +++ b/client.js @@ -1,6 +1,5 @@ const vid = document.querySelector('video') -const socket = new WebSocket('ws://192.168.68.118:3000'); - +const socket = new WebSocket(`ws://${window.location.hostname}:${window.location.port}`); // if the new tms is within this margin of the current tms, then the change is ignored for smoother viewing const PLAYING_THRESH = 1 const PAUSED_THRESH = 0.01 @@ -130,6 +129,14 @@ function get_global_time(delta = 0) { return d.getTime() + delta; } +async function get_settings() { + let s = null; + await fetch('settings.json') + .then((response)=>response.json()) + .then((responseJson)=>{s = responseJson}); + return s; +} + function median(values) { if(values.length === 0) { return 0; } diff --git a/index.js b/index.js index cfe0f25..d2d886f 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ const server = require('http').createServer(app); const WebSocket = require('ws'); const wss = new WebSocket.Server({ server:server }); +const settings = JSON.parse(fs.readFileSync("settings.json")); const THRESH_IGNORANCE = 250; let users_amount = 0; @@ -83,7 +84,7 @@ app.get("/video", function (req, res) { } // get video stats (about 61MB) - const videoPath = "videos/Shreksophone_Original.mp4"; + const videoPath = settings.video_path; const videoSize = fs.statSync(videoPath).size; // Parse Range @@ -111,7 +112,7 @@ app.get("/video", function (req, res) { videoStream.pipe(res); }); -server.listen(3000, () => console.log(`Listening on port: 3000`)); +server.listen(settings.server_port, settings.server_ip, () => console.log(`Listening on port: 3000`)); function get_time(){ diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..2a57c3e --- /dev/null +++ b/settings.json @@ -0,0 +1,5 @@ +{ + "server_ip": "192.168.68.118", + "server_port": 3000, + "video_path": "videos/bigbuck.mp4" +} \ No newline at end of file