fix socket request for live requests, not sure why emit doesnt work there

This commit is contained in:
Maxime Bloch 2019-09-26 17:47:25 +02:00
parent 44c48730c0
commit b4fd3f9710
No known key found for this signature in database
GPG key ID: CE32A7D95B7D6418
2 changed files with 8 additions and 6 deletions

View file

@ -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/<run>/<index>")
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__':

View file

@ -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);
});