|
@ -18,65 +18,62 @@ async def background_task(): |
|
|
while True: |
|
|
while True: |
|
|
await sio.sleep(10) |
|
|
await sio.sleep(10) |
|
|
count += 1 |
|
|
count += 1 |
|
|
await sio.emit('my response', {'data': 'Server generated event'}, |
|
|
await sio.emit('my_response', {'data': 'Server generated event'}) |
|
|
namespace='/test') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('my event', namespace='/test') |
|
|
@sio.on('my_event') |
|
|
async def test_message(sid, message): |
|
|
async def test_message(sid, message): |
|
|
await sio.emit('my response', {'data': message['data']}, room=sid, |
|
|
await sio.emit('my_response', {'data': message['data']}, room=sid) |
|
|
namespace='/test') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('my broadcast event', namespace='/test') |
|
|
@sio.on('my_broadcast_event') |
|
|
async def test_broadcast_message(sid, message): |
|
|
async def test_broadcast_message(sid, message): |
|
|
await sio.emit('my response', {'data': message['data']}, namespace='/test') |
|
|
await sio.emit('my_response', {'data': message['data']}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('join', namespace='/test') |
|
|
@sio.on('join') |
|
|
async def join(sid, message): |
|
|
async def join(sid, message): |
|
|
sio.enter_room(sid, message['room'], namespace='/test') |
|
|
sio.enter_room(sid, message['room']) |
|
|
await sio.emit('my response', {'data': 'Entered room: ' + message['room']}, |
|
|
await sio.emit('my_response', {'data': 'Entered room: ' + message['room']}, |
|
|
room=sid, namespace='/test') |
|
|
room=sid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('leave', namespace='/test') |
|
|
@sio.on('leave') |
|
|
async def leave(sid, message): |
|
|
async def leave(sid, message): |
|
|
sio.leave_room(sid, message['room'], namespace='/test') |
|
|
sio.leave_room(sid, message['room']) |
|
|
await sio.emit('my response', {'data': 'Left room: ' + message['room']}, |
|
|
await sio.emit('my_response', {'data': 'Left room: ' + message['room']}, |
|
|
room=sid, namespace='/test') |
|
|
room=sid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('close room', namespace='/test') |
|
|
@sio.on('close room') |
|
|
async def close(sid, message): |
|
|
async def close(sid, message): |
|
|
await sio.emit('my response', |
|
|
await sio.emit('my_response', |
|
|
{'data': 'Room ' + message['room'] + ' is closing.'}, |
|
|
{'data': 'Room ' + message['room'] + ' is closing.'}, |
|
|
room=message['room'], namespace='/test') |
|
|
room=message['room']) |
|
|
await sio.close_room(message['room'], namespace='/test') |
|
|
await sio.close_room(message['room']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('my room event', namespace='/test') |
|
|
@sio.on('my_room_event') |
|
|
async def send_room_message(sid, message): |
|
|
async def send_room_message(sid, message): |
|
|
await sio.emit('my response', {'data': message['data']}, |
|
|
await sio.emit('my_response', {'data': message['data']}, |
|
|
room=message['room'], namespace='/test') |
|
|
room=message['room']) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('disconnect request', namespace='/test') |
|
|
@sio.on('disconnect request') |
|
|
async def disconnect_request(sid): |
|
|
async def disconnect_request(sid): |
|
|
await sio.disconnect(sid, namespace='/test') |
|
|
await sio.disconnect(sid) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('connect', namespace='/test') |
|
|
@sio.on('connect') |
|
|
async def test_connect(sid, environ): |
|
|
async def test_connect(sid, environ): |
|
|
global background_task_started |
|
|
global background_task_started |
|
|
if not background_task_started: |
|
|
if not background_task_started: |
|
|
sio.start_background_task(background_task) |
|
|
sio.start_background_task(background_task) |
|
|
background_task_started = True |
|
|
background_task_started = True |
|
|
await sio.emit('my response', {'data': 'Connected', 'count': 0}, room=sid, |
|
|
await sio.emit('my_response', {'data': 'Connected', 'count': 0}, room=sid) |
|
|
namespace='/test') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@sio.on('disconnect', namespace='/test') |
|
|
@sio.on('disconnect') |
|
|
def test_disconnect(sid): |
|
|
def test_disconnect(sid): |
|
|
print('Client disconnected') |
|
|
print('Client disconnected') |
|
|
|
|
|
|
|
|