Browse Source

fix js ping

main
Hendrik Langer 4 years ago
parent
commit
213a2d9480
  1. 4
      raspberry/roberto/views/frontend/templates/index.html
  2. 10
      raspberry/roberto/views/websocket/routes.py

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

@ -97,7 +97,7 @@
function onLocalDescription(desc) { function onLocalDescription(desc) {
console.log("Local description: " + JSON.stringify(desc)); console.log("Local description: " + JSON.stringify(desc));
webrtcPeerConnection.setLocalDescription(desc).then(function() { webrtcPeerConnection.setLocalDescription(desc).then(function() {
socket.emit('message', { type: "sdp", "data": webrtcPeerConnection.localDescription }); socket.emit('message', { "type": "sdp", "data": webrtcPeerConnection.localDescription });
}).catch(reportError); }).catch(reportError);
} }
@ -227,7 +227,7 @@ var statsInterval = window.setInterval(getConnectionStats, 1000);
setInterval(function(){ setInterval(function(){
if (socket.connected) { if (socket.connected) {
socket.emit('ping'); socket.emit('ping_message', { "type": "ping" });
} }
}, 5000); }, 5000);

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

@ -90,6 +90,11 @@ def webrtc_message(data):
print("unknown message type") print("unknown message type")
socketio.emit('message', data=data, room=ROOM, namespace='/webrtc', skip_sid=sid) socketio.emit('message', data=data, room=ROOM, namespace='/webrtc', skip_sid=sid)
@socketio.on('ping_message', namespace='/webrtc')
def ping_message(data):
sid = request.sid
print("Received ping from %s" % sid)
socketio.emit('ping_message', data={ 'type':'pong' }, room=sid, namespace='/webrtc')
@socketio.on('disconnect', namespace='/webrtc') @socketio.on('disconnect', namespace='/webrtc')
def disconnect(): def disconnect():
@ -111,11 +116,6 @@ 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