Reputation: 119
I am new in Socketio,i integrate it with Flask also I have an issue with sending events when it connects but nothing happens, as the fired message is not printed when socket send message here is my code :
from myproject import app
from flask_socketio import SocketIO
socketio = SocketIO(app)
if __name__ == '__main__':
#app.run(debug=True)
socketio.run(app,debug=True)
this controller code
from flask import render_template,url_for,flash,redirect,request,Blueprint,request,json,jsonify,session,Response
from flask_login import login_user, current_user, logout_user, login_required
from myproject import db
from myproject import app
from myproject.models import User ,Presentaions,PresntaionImages,PresntaionVideos,Settings,Colors,Hand,PresnterFrameMode,SlidingMode
from myproject.users.dataValidator import *
from myproject.handler import *
import datetime
from sqlalchemy import func
from sqlalchemy.sql import text
# Define a Flask Blueprint named 'streaming'
streaming = Blueprint('streaming', __name__)
@streaming.route('/streaming/show/<int:id>', methods=['GET'])
@login_required
def show(id):
presntaion = Presentaions.query.filter_by(id=id, deleted=1).first()
pagetitle = "Presenter X | Streaming Details"
return render_template('streaming_template/show.html', presntaion=presntaion,pagetitle=pagetitle)
@socketio.on('message')
def message(data):
send(data)
print(f"Message received: {data}")
this my js code
document.addEventListener('DOMContentLoaded', () => {
// Connect to websocket
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port);
// Retrieve username
socket.on('connect',()=>{
socket.send("i am connected");
//console.log("WebSocket connected");
});
I tried more and more for searching to solve this issue
Upvotes: 0
Views: 34