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 @socketio.on('message') # ok
def webrtc_message(data): def webrtc_message(data):
sid = request.sid from_sid = request.sid
target_sid = None
#print('Message from {}: {}'.format(sid, data)) #print('Message from {}: {}'.format(sid, data))
if isinstance(data, str): if isinstance(data, str):
try: try:
jsonData = json.loads(data) 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) data = json.dumps(jsonData)
except json.JSONDecodeError: except json.JSONDecodeError:
print("could not decode json") print("could not decode json")
elif isinstance(data, dict): elif isinstance(data, dict):
data['from_sid'] = sid data['from_sid'] = from_sid
if 'sid' in data:
target_sid = data['sid']
else: else:
print("unknown message type") 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 @socketio.on('battery') # ok
def battery_message(data): def battery_message(data):

Loading…
Cancel
Save