websockets tests
This commit is contained in:
parent
08d182e87e
commit
6955fcabc1
@ -10,7 +10,7 @@ app = Flask(__name__)
|
|||||||
|
|
||||||
|
|
||||||
# .WAV (i.e.) FILE REQUEST
|
# .WAV (i.e.) FILE REQUEST
|
||||||
@app.route("/process_audio_request_file", methods=['POST'])
|
@app.route("/process_voice", methods=['POST'])
|
||||||
def process_audio_request_android():
|
def process_audio_request_android():
|
||||||
print("[" + request.remote_addr + "] - New STT request")
|
print("[" + request.remote_addr + "] - New STT request")
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ def process_audio_request_android():
|
|||||||
|
|
||||||
# TODO: send to each skill to answer the questions
|
# TODO: send to each skill to answer the questions
|
||||||
|
|
||||||
return {"transcription": text, "answer": "I'm still learning how to respond to that..."}
|
return {"transcription": text, "status": 200}
|
||||||
|
|
||||||
|
|
||||||
@app.route("/process_text", methods=['POST'])
|
@app.route("/process_text", methods=['POST'])
|
||||||
|
47
jarvis/utils/templates/index.html
Normal file
47
jarvis/utils/templates/index.html
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Socket-Test</title>
|
||||||
|
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.5.4/socket.io.js"></script>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
namespace = '/test';
|
||||||
|
var socket = io(namespace);
|
||||||
|
|
||||||
|
socket.on('connect', function() {
|
||||||
|
socket.emit('my_event', {data: 'connected to the SocketServer...'});
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('my_response', function(msg, cb) {
|
||||||
|
$('#log').append('<br>' + $('<div/>').text('logs #' + msg.count + ': ' + msg.data).html());
|
||||||
|
if (cb)
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
$('form#emit').submit(function(event) {
|
||||||
|
socket.emit('my_event', {data: $('#emit_data').val()});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
$('form#disconnect').submit(function(event) {
|
||||||
|
socket.emit('disconnect_request');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body style="background-color:white;">
|
||||||
|
|
||||||
|
<h1 style="background-color:white;">Socket</h1>
|
||||||
|
<form id="emit" method="POST" action='#'>
|
||||||
|
<input type="text" name="emit_data" id="emit_data" placeholder="Message">
|
||||||
|
<input type="submit" value="Send Message">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form id="disconnect" method="POST" action="#">
|
||||||
|
<input type="submit" value="Disconnect Server">
|
||||||
|
</form>
|
||||||
|
<h2 style="background-color:white;">Logs</h2>
|
||||||
|
<div id="log" ></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
39
jarvis/utils/websocketstest.py
Normal file
39
jarvis/utils/websocketstest.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from flask import Flask, render_template, session, copy_current_request_context
|
||||||
|
from flask_socketio import SocketIO, emit, disconnect
|
||||||
|
from threading import Lock
|
||||||
|
|
||||||
|
|
||||||
|
async_mode = None
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config['SECRET_KEY'] = 'secret!'
|
||||||
|
socket_ = SocketIO(app, async_mode=async_mode)
|
||||||
|
thread = None
|
||||||
|
thread_lock = Lock()
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def index():
|
||||||
|
return render_template('index.html', async_mode=socket_.async_mode)
|
||||||
|
|
||||||
|
|
||||||
|
@socket_.on('my_event', namespace='/test')
|
||||||
|
def test_message(message):
|
||||||
|
session['receive_count'] = session.get('receive_count', 0) + 1
|
||||||
|
emit('my_response',
|
||||||
|
{'data': message['data'], 'count': session['receive_count']})
|
||||||
|
|
||||||
|
|
||||||
|
@socket_.on('disconnect_request', namespace='/test')
|
||||||
|
def disconnect_request():
|
||||||
|
@copy_current_request_context
|
||||||
|
def can_disconnect():
|
||||||
|
disconnect()
|
||||||
|
|
||||||
|
session['receive_count'] = session.get('receive_count', 0) + 1
|
||||||
|
emit('my_response',
|
||||||
|
{'data': 'Disconnected!', 'count': session['receive_count']},
|
||||||
|
callback=can_disconnect)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
socket_.run(app, debug=True, host='0.0.0.0')
|
@ -2,3 +2,4 @@ requests~=2.28.1
|
|||||||
Flask~=2.2.2
|
Flask~=2.2.2
|
||||||
adapt-parser==1.0.0
|
adapt-parser==1.0.0
|
||||||
lingua-franca~=0.4.3
|
lingua-franca~=0.4.3
|
||||||
|
Flask-SocketIO==5.3.2
|
Loading…
Reference in New Issue
Block a user