Browse Source

display chat

main
Hendrik Langer 4 years ago
parent
commit
6fc7f73c3e
  1. 17
      raspberry/roberto/views/frontend/templates/index.html
  2. 21
      raspberry/roberto/views/websocket/routes.py

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

@ -50,6 +50,14 @@
}
.stats-box {
display: none;
position: absolute;
left: 10px;
top: 100px;
color: white;
opacity: 0.6;
z-index: 1;
}
#chat {
position: absolute;
right: 20px;
top: 100px;
@ -81,6 +89,7 @@
</form>
</div>
<div class="stats-box"></div>
<div id="chat"></div>
<!--<h2 id="start">Press a button on your controller to start</h2>-->
@ -185,6 +194,14 @@ socket.on('battery', (data) => {
ctx.fillText(data, 3*canvas.width/4, 30);
});
socket.on('text', (data) => {
console.log('Text received: ',data);
var chatlog = document.getElementById("chat");
var new_message = document.createElement('p');
new_message.innerHTML = data;
chatlog.append(new_message);
});
function displayText(text, left, top) {
var canvas = document.getElementById("textoverlay");
var ctx = canvas.getContext("2d");

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

@ -37,16 +37,6 @@ def applyDeadZone(value, threshold):
new_value = new_value * -1
return new_value
@socketio.on('text')
def display_text(text):
print("display_text()")
print(text['data'])
if isinstance(text['data'], str):
if len(text['data']) < 250:
from roberto import serial
command = 'T '+str(text['data'])
serial.write(bytes(command, "utf8"))
# https://pfertyk.me/2020/03/webrtc-a-working-example/
from roberto import webrtccamera
@ -87,6 +77,17 @@ def battery_message(data):
sid = request.sid
socketio.emit('battery', data, room=ROOM, skip_sid=sid)
@socketio.on('text')
def display_text(text):
print("display_text()")
print(text['data'])
if isinstance(text['data'], str):
if len(text['data']) < 250:
from roberto import serial
command = 'T '+str(text['data'])
serial.write(bytes(command, "utf8"))
socketio.emit('text', text, room=ROOM)
@socketio.on('disconnect')
def disconnect():
sid = request.sid

Loading…
Cancel
Save