简体   繁体   中英

Flask-SocketIO and SocketIO Client; Client Emit event doesn't trigger consistently

Whenever I click on my send button, the emit event doesn't trigger consistently (sometimes it triggers, sometimes it doesn't). It does trigger when I spam click on my send button.

Here is my server.py

@socketio.on('message')
def message(message_data):
    print(message_data)
    room = message_data['channel']
    emit('broadcast', message_data, room=room)

And here is my client.js which is supposed to trigger the send event

socket.on('connect', function (){
                socket.emit('join channel', {
                    'channel_id': localStorage.getItem('channel_id')
                })
            })

            $("#send").on('click', function (){
                prevent_blank_text()
                socket.emit('message',{
                    'message': $("#message").val(),
                    'user': localStorage.getItem('channel_user'),
                    'channel': localStorage.getItem('channel_id'),
                    'timestamp': new Date().toLocaleString()
                }, function (){
                    $("#message").val('')
                })
            })

Note: the connect event is decoupled from the click event, I just included it there just in case that's where the problem is stemming from.

Could someone point me in the right direction?

EDIT: Apparently bootstrap's btn-large is what's causing the problem, it wasn't a socketio problem

<button type="button" id="send" class="btn btn-success">Send</button>

This fixed my send button

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM