From b4fd3f97102f1e451eaea17928bf8bb3d1b22f60 Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Thu, 26 Sep 2019 17:47:25 +0200 Subject: [PATCH] fix socket request for live requests, not sure why emit doesnt work there --- watcher/app.py | 13 +++++++------ watcher/static/index.js | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/watcher/app.py b/watcher/app.py index cf44d65..435795f 100644 --- a/watcher/app.py +++ b/watcher/app.py @@ -1,9 +1,8 @@ +import socket from time import time import socketio -import socket -from flask import Flask, render_template -from flask import request +from flask import Flask, render_template, request sio = socketio.Server() app = Flask(__name__) @@ -40,7 +39,9 @@ def start_run(run_index): @app.route("/link/start//") def link_start(run, index): - live_request(run, index) + request_data = live_request(run, index) + sio.emit('live_request', request_data) + if db["current_run"] != run: return "Wrong run number, check that you update your run", 404 else: @@ -73,13 +74,13 @@ def connect(sid, data): current_run = db["run_data"][db["current_run"]] sio.emit('sync_current_run', current_run, room=sid) + def live_request(run, index): ip = request.remote_addr request_data = {} request_data["hostname"] = socket.gethostbyaddr(ip) request_data["time"] = time() - - sio.emit('live_request', request_data) + return request_data if __name__ == '__main__': diff --git a/watcher/static/index.js b/watcher/static/index.js index 3b5e5de..6c6f7ce 100644 --- a/watcher/static/index.js +++ b/watcher/static/index.js @@ -44,6 +44,7 @@ require(['jquery', 'socket.io'], function(jq, io) { } }); socket.on('live_request', function(request_data) { + console.log("live request"); request_time = new Date(request_data["time"] * 1000); addLiveRequest(request_data["hostname"], request_time); });