Esempio n. 1
0
def connect():
    print('connected', current_user().id)
    message = {
        'type': 'join',
        'channel': Channel.default_channel().name,
        'username': current_user().username,
        'avatar': current_user().avatar,
        'content': '{} 加入聊天'.format(current_user().username)
    }
    print(message)
    emit('message', message, broadcast=True)
Esempio n. 2
0
def text(message):
    """Sent by a client when the user entered a new message.
    The message is sent to all people in the room."""
    # room = message.get('channel')
    message['type'] = 'message'
    message['username'] = current_user().username
    message['avatar'] = current_user().avatar
    room = message.get('channel', Channel.default_channel().name)
    print(message)
    # Channel.findByName(room).save_chat(Chat(message))
    chat = {
        'content': message.get('content', ''),
        'user': current_user(),
        'channel': Channel.findByName(room),
    }
    Chat(chat).save()
    join_room(room)
    emit('message', message, broadcast=True)