|
|
@ -15,8 +15,7 @@ async def background_task(): |
|
|
|
while True: |
|
|
|
await sio.sleep(10) |
|
|
|
count += 1 |
|
|
|
await sio.emit('my response', {'data': 'Server generated event'}, |
|
|
|
namespace='/test') |
|
|
|
await sio.emit('my_response', {'data': 'Server generated event'}) |
|
|
|
|
|
|
|
|
|
|
|
async def index(request): |
|
|
@ -24,58 +23,56 @@ async def index(request): |
|
|
|
return web.Response(text=f.read(), content_type='text/html') |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('my event', namespace='/test') |
|
|
|
async def test_message(sid, message): |
|
|
|
await sio.emit('my response', {'data': message['data']}, room=sid, |
|
|
|
namespace='/test') |
|
|
|
@sio.event |
|
|
|
async def my_event(sid, message): |
|
|
|
await sio.emit('my_response', {'data': message['data']}, room=sid) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('my broadcast event', namespace='/test') |
|
|
|
async def test_broadcast_message(sid, message): |
|
|
|
await sio.emit('my response', {'data': message['data']}, namespace='/test') |
|
|
|
@sio.event |
|
|
|
async def my_broadcast_event(sid, message): |
|
|
|
await sio.emit('my_response', {'data': message['data']}) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('join', namespace='/test') |
|
|
|
@sio.event |
|
|
|
async def join(sid, message): |
|
|
|
sio.enter_room(sid, message['room'], namespace='/test') |
|
|
|
await sio.emit('my response', {'data': 'Entered room: ' + message['room']}, |
|
|
|
room=sid, namespace='/test') |
|
|
|
sio.enter_room(sid, message['room']) |
|
|
|
await sio.emit('my_response', {'data': 'Entered room: ' + message['room']}, |
|
|
|
room=sid) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('leave', namespace='/test') |
|
|
|
@sio.event |
|
|
|
async def leave(sid, message): |
|
|
|
sio.leave_room(sid, message['room'], namespace='/test') |
|
|
|
await sio.emit('my response', {'data': 'Left room: ' + message['room']}, |
|
|
|
room=sid, namespace='/test') |
|
|
|
sio.leave_room(sid, message['room']) |
|
|
|
await sio.emit('my_response', {'data': 'Left room: ' + message['room']}, |
|
|
|
room=sid) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('close room', namespace='/test') |
|
|
|
async def close(sid, message): |
|
|
|
await sio.emit('my response', |
|
|
|
@sio.event |
|
|
|
async def close_room(sid, message): |
|
|
|
await sio.emit('my_response', |
|
|
|
{'data': 'Room ' + message['room'] + ' is closing.'}, |
|
|
|
room=message['room'], namespace='/test') |
|
|
|
await sio.close_room(message['room'], namespace='/test') |
|
|
|
room=message['room']) |
|
|
|
await sio.close_room(message['room']) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('my room event', namespace='/test') |
|
|
|
async def send_room_message(sid, message): |
|
|
|
await sio.emit('my response', {'data': message['data']}, |
|
|
|
room=message['room'], namespace='/test') |
|
|
|
@sio.event |
|
|
|
async def my_room_event(sid, message): |
|
|
|
await sio.emit('my_response', {'data': message['data']}, |
|
|
|
room=message['room']) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('disconnect request', namespace='/test') |
|
|
|
@sio.event |
|
|
|
async def disconnect_request(sid): |
|
|
|
await sio.disconnect(sid, namespace='/test') |
|
|
|
await sio.disconnect(sid) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('connect', namespace='/test') |
|
|
|
async def test_connect(sid, environ): |
|
|
|
await sio.emit('my response', {'data': 'Connected', 'count': 0}, room=sid, |
|
|
|
namespace='/test') |
|
|
|
@sio.event |
|
|
|
async def connect(sid, environ): |
|
|
|
await sio.emit('my_response', {'data': 'Connected', 'count': 0}, room=sid) |
|
|
|
|
|
|
|
|
|
|
|
@sio.on('disconnect', namespace='/test') |
|
|
|
def test_disconnect(sid): |
|
|
|
@sio.event |
|
|
|
def disconnect(sid): |
|
|
|
print('Client disconnected') |
|
|
|
|
|
|
|
|
|
|
|