Changed spacing in html and JS files.
Changed spacing based to tab based
This commit is contained in:
parent
8227bb1861
commit
3fd791dce7
@ -26,8 +26,7 @@ socket.addEventListener('open', function (event) {
|
||||
// Got message from the server
|
||||
socket.addEventListener("message", (event) => {
|
||||
|
||||
if (event.data.startsWith("time_sync_response_backward"))
|
||||
{
|
||||
if (event.data.startsWith("time_sync_response_backward")) {
|
||||
let time_at_server = Number(event.data.slice("time_sync_response_backward".length + 1));
|
||||
let under_estimate_latest = time_at_server - get_global_time(0);
|
||||
|
||||
@ -38,8 +37,7 @@ socket.addEventListener("message", (event) => {
|
||||
console.log(`%c Updated val for under_estimate is ${under_estimate}`, "color:green");
|
||||
console.log(`%c New correction time is ${correction} miliseconds`, 'color:red; font-size:12px');
|
||||
}
|
||||
if (event.data.startsWith("time_sync_response_forward"))
|
||||
{
|
||||
if (event.data.startsWith("time_sync_response_forward")) {
|
||||
let calculated_diff = Number(event.data.slice("time_sync_response_forward".length + 1));
|
||||
over_estimates.push(calculated_diff);
|
||||
over_estimate = median(over_estimates);
|
||||
@ -48,8 +46,7 @@ socket.addEventListener("message", (event) => {
|
||||
console.log(`%c Updated val for over_estimate is ${over_estimate}`, "color:green");
|
||||
console.log(`%c New correction time is ${correction} miliseconds`, 'color:red; font-size:12px');
|
||||
}
|
||||
if (event.data.startsWith("state_update_from_server"))
|
||||
{
|
||||
if (event.data.startsWith("state_update_from_server")) {
|
||||
let state = JSON.parse(event.data.slice("state_update_from_server".length + 1));
|
||||
|
||||
// Whenever the client connects or reconnects
|
||||
@ -68,8 +65,7 @@ socket.addEventListener("message", (event) => {
|
||||
vid.currentTime = proposed_time
|
||||
}
|
||||
vid.play()
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
vid.pause()
|
||||
// condition to prevent an unnecessary seek
|
||||
if (gap > PAUSED_THRESH) {
|
||||
@ -87,8 +83,7 @@ socket.addEventListener('close', function (event) {
|
||||
});
|
||||
|
||||
|
||||
function state_change_handler(event)
|
||||
{
|
||||
function state_change_handler(event) {
|
||||
if (event !== null && event !== undefined) {
|
||||
if (event.type === 'pause')
|
||||
video_playing = false;
|
||||
@ -133,12 +128,16 @@ async function get_settings() {
|
||||
let s = null;
|
||||
await fetch('settings.json')
|
||||
.then((response) => response.json())
|
||||
.then((responseJson)=>{s = responseJson});
|
||||
.then((responseJson) => {
|
||||
s = responseJson
|
||||
});
|
||||
return s;
|
||||
}
|
||||
|
||||
function median(values) {
|
||||
if(values.length === 0) { return 0; }
|
||||
if (values.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
values.sort((x, y) => (x - y));
|
||||
let half = Math.floor(values.length / 2);
|
||||
@ -156,6 +155,7 @@ function timeout(ms) {
|
||||
function do_time_sync_one_cycle_backward() {
|
||||
socket.send("time_sync_request_backward");
|
||||
}
|
||||
|
||||
function do_time_sync_one_cycle_forward() {
|
||||
socket.send(`time_sync_request_forward ${get_global_time()}`);
|
||||
}
|
||||
|
28
src/index.js
28
src/index.js
@ -6,7 +6,9 @@ const WebSocket = require('ws');
|
||||
const app = express();
|
||||
const server = require('http').createServer(app);
|
||||
|
||||
const wss = new WebSocket.Server({ server:server });
|
||||
const wss = new WebSocket.Server({
|
||||
server: server
|
||||
});
|
||||
const settings = JSON.parse(fs.readFileSync("settings.json"));
|
||||
|
||||
const THRESH_IGNORANCE = 250;
|
||||
@ -32,24 +34,20 @@ wss.on('connection', function connection(ws) {
|
||||
ws.on('message', function message(data) {
|
||||
data = data.toString();
|
||||
|
||||
if(data.startsWith("time_sync_request_backward"))
|
||||
{
|
||||
if (data.startsWith("time_sync_request_backward")) {
|
||||
ws.send(`time_sync_response_backward ${get_time()}`);
|
||||
}
|
||||
if(data.startsWith("time_sync_request_forward"))
|
||||
{
|
||||
if (data.startsWith("time_sync_request_forward")) {
|
||||
let client_time = Number(data.slice("time_sync_request_forward".length + 1));
|
||||
ws.send(`time_sync_response_forward ${get_time() - client_time}`);
|
||||
}
|
||||
if(data.startsWith("state_update_from_client"))
|
||||
{
|
||||
if (data.startsWith("state_update_from_client")) {
|
||||
let new_state = JSON.parse(data.slice("state_update_from_client".length + 1));
|
||||
let too_soon = (get_time() - state.last_updated) < THRESH_IGNORANCE;
|
||||
let other_ip = (new_state.client_uid != state.client_uid);
|
||||
let stale = (new_state.last_updated < state.last_updated)
|
||||
|
||||
if (!stale && !(too_soon && other_ip))
|
||||
{
|
||||
if (!stale && !(too_soon && other_ip)) {
|
||||
state = new_state;
|
||||
|
||||
wss.clients.forEach(function each(client) {
|
||||
@ -69,7 +67,9 @@ wss.on('connection', function connection(ws) {
|
||||
});
|
||||
|
||||
app.use('/', express.static(__dirname));
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
}));
|
||||
app.use(bodyParser.json());
|
||||
app.use(session({
|
||||
secret: 'secret key',
|
||||
@ -85,8 +85,7 @@ app.get("/", function (req, res) {
|
||||
res.sendFile(__dirname + "/login.html");
|
||||
});
|
||||
|
||||
app.post("/login", function (req, res)
|
||||
{
|
||||
app.post("/login", function (req, res) {
|
||||
const data = req.body;
|
||||
if (!data)
|
||||
res.sendStatus(400);
|
||||
@ -129,7 +128,10 @@ app.get("/video", function (req, res) {
|
||||
res.writeHead(206, headers);
|
||||
|
||||
// create video read stream for this particular chunk
|
||||
const videoStream = fs.createReadStream(videoPath, { start, end });
|
||||
const videoStream = fs.createReadStream(videoPath, {
|
||||
start,
|
||||
end
|
||||
});
|
||||
|
||||
// Stream the video chunk to the client
|
||||
videoStream.pipe(res);
|
||||
|
Loading…
x
Reference in New Issue
Block a user