Browse Source

send pings

main
Hendrik Langer 4 years ago
parent
commit
349e5f19f4
  1. 4
      raspberry/roberto/camera/camera_gstreamer_webrtc.py
  2. 6
      raspberry/roberto/views/frontend/templates/index.html
  3. 5
      raspberry/roberto/views/websocket/routes.py

4
raspberry/roberto/camera/camera_gstreamer_webrtc.py

@ -413,7 +413,7 @@ class WebRTCCamera(Thread):
else: else:
print("Unknown message \"%s\", ignoring" % data['data']) print("Unknown message \"%s\", ignoring" % data['data'])
@sio.event @sio.on('connect')
def connected(): def connected():
print("I'm connected!") print("I'm connected!")
@ -421,7 +421,7 @@ class WebRTCCamera(Thread):
def connect_error(): def connect_error():
print("The connection failed!") print("The connection failed!")
@sio.event @sio.on('disconnect')
def disconnected(): def disconnected():
print("I'm disconnected!") print("I'm disconnected!")

6
raspberry/roberto/views/frontend/templates/index.html

@ -225,6 +225,12 @@ function getConnectionStats() {
var statsInterval = window.setInterval(getConnectionStats, 1000); var statsInterval = window.setInterval(getConnectionStats, 1000);
setInterval(function(){
if (socket.connected) {
socket.emit('ping');
}
}, 5000);
</script> </script>
<script src="{{ url_for('frontend.gamepad_js') }}"></script> <script src="{{ url_for('frontend.gamepad_js') }}"></script>

5
raspberry/roberto/views/websocket/routes.py

@ -111,6 +111,11 @@ def connect():
if sid != webrtccamera.sid: if sid != webrtccamera.sid:
serial.add_callback('B', display_battery) serial.add_callback('B', display_battery)
@socketio.on('ping', namespace='/webrtc')
def ping():
sid = request.sid
print("Received ping from %s" % sid)
@socketio.on_error_default @socketio.on_error_default
def default_error_handler(e): def default_error_handler(e):
print(request.event["message"]) # "my error event" print(request.event["message"]) # "my error event"

Loading…
Cancel
Save