Browse Source

only send messages to target

main
Hendrik Langer 4 years ago
parent
commit
9840b9eb95
  1. 16
      raspberry/roberto/views/websocket/routes.py

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

@ -59,20 +59,28 @@ def camera():
@socketio.on('message') # ok
def webrtc_message(data):
sid = request.sid
from_sid = request.sid
target_sid = None
#print('Message from {}: {}'.format(sid, data))
if isinstance(data, str):
try:
jsonData = json.loads(data)
jsonData['from_sid'] = sid
jsonData['from_sid'] = from_sid
if 'sid' in jsonData:
target_sid = jsonData['sid']
data = json.dumps(jsonData)
except json.JSONDecodeError:
print("could not decode json")
elif isinstance(data, dict):
data['from_sid'] = sid
data['from_sid'] = from_sid
if 'sid' in data:
target_sid = data['sid']
else:
print("unknown message type")
socketio.emit('message', data=data, room=ROOM, skip_sid=sid)
if target_sid:
socketio.emit('message', data=data, room=target_sid)
else:
socketio.emit('message', data=data, room=ROOM, skip_sid=from_sid)
@socketio.on('battery') # ok
def battery_message(data):

Loading…
Cancel
Save