示例#1
0
def send_msg(data):
    """
    发送消息
    :param data:
    :return:
    """
    send('send_msg')
    msg = data.get('msg', {})
    msg_type = 'single' if msg.get('is_to_group', '0') == '0' else 'group'
    mime_type = msg.get('mime_type', '0')
    to_id = msg.get('to_id')
    content = msg.get('content')
    #文件类型消息的文件名
    filename = msg.get('filename')
    res_data = api_request('send_msg', {'msg_type': msg_type, 'to_id': to_id, 'content': content, 'type': 1, 'mime_type': mime_type, 'filename': filename})
    contact = data.get('contact')
    now = datetime.now()
    msg['add_time'] = now.strftime('%Y-%m-%d %H:%M:%S')
    contact['msg_time'] = msg['add_time']
    #发送单人消息
    if contact.get('is_to_group') == '0':
        room = online_users[msg.get('to_id')]
    else:
        room = to_id

    sio.emit('recv', data, room=room)
示例#2
0
def post_resources(Model, data):
    with orm.db_session:
        setattr(g, 'in_celery', True)
        # this is just a virtual test
        # emit("user created!")
        print "get data: ", data
        send(data)
示例#3
0
def get_friends():
    """
    获取好友列表
    :return:
    """
    send('get_friends')
    data = api_request('get_friends')
    emit('res_friends', data)
示例#4
0
def get_fans():
    """
    获取粉丝列表
    :return:
    """
    send('get_fans')
    data = api_request('get_fans')
    emit('res_fans', data)
示例#5
0
def get_follows():
    """
    获取关注列表
    :return:
    """
    send('get_follows')
    data = api_request('get_follows')
    emit('res_follows', data)
示例#6
0
def get_groups():
    """
    获取群列表
    :return:
    """
    send('get_groups')
    data = api_request('get_groups', {'uid': session.get('user').get('id')})
    emit('res_groups', data)
示例#7
0
def get_rct_contacts():
    """
    获取最近联系人
    :return:
    """
    send('get_rct_contacts')
    data = api_request('get_rct_contacts')
    emit('res_rct_contacts', data)
def on_connect():
    room_id = 777
    print('SERVER 5001>>> A user has been connected.')
    join_room(room_id)
    send('SERVER 5001>>> User has joined the room: ' + str(room_id) + '.', room=room_id)
    print('SERVER 5001>>> User has joined the room ' + str(room_id) + '.')
    socketio.emit('my_event', 'data_string1')
    emit('my_event', 'data_string2')
示例#9
0
def get_no_read_msg(req_data):
    """
    获取未读消息
    :param req_data:
    :return:
    """
    send('get_no_read_msg')
    res_data = api_request('get_no_read_msg', req_data)
    emit('res_no_read_msg', res_data)
示例#10
0
def get_user_info():
    """
    获取用户信息
    :return:
    """
    send('get_user_info')
    emit('res_user_info', {
        'success': True,
        'data': session.get('user')
    })
示例#11
0
def dustbin():
    try:
        import pdb;pdb.set_trace()
        id = request.args.get('id',None)
        completeness = request.args.get('per')
        dustbin_object = model.dustbin_data.objects(id=id)
        if len(dustbin_object) < 0:
            abort(400)
        dustbin_object = dustbin_object[0]
        dustbin_object.completeness = completeness
        dustbin_object.save()
        send("hello",namespace='/chat')
        return "success"
    except:
        abort(400)
示例#12
0
def dustbin(id,completeness):
    try:
        import pdb;pdb.set_trace()
        dustbin_object = model.dustbin_data.objects(id=id)
        if len(dustbin_object) < 0:
            abort(400)
        dustbin_object = dustbin_object[0]
        dustbin_object.completeness = completeness
        dustbin_object.save()
        send("hello",namespace='/chat')
        data = {}
        for key in dustbin_object:
           data[key] = str(d[key])
        return data
    except Exception as e:
        return e
示例#13
0
def on_message(msg):
    """
    socket.io 消息事件
    :param msg:
    :return:
    """
    to_sid = None
    if msg.startswith('@'):
        msg_start = msg.index(':')
        to_nickname = msg[1:msg_start]
        to_sid = online_users.get(to_nickname)
        #print online_users
        if not to_sid:
            send(to_nickname + 'is not online')
            return
        else:
            sio.send(session['nickname'] + 'say to your:' + msg[msg_start+1:], room=to_sid)
    else:
        sio.send(session['nickname'] + ':' + msg, room=to_sid)
示例#14
0
文件: sio.py 项目: txdywy/flask
def handle_message(message):
    print('received message: ' + message)
    send('re:' + message)
    emit('other', { 'hello': 'hahahahah' })
示例#15
0
from flask import Flask , request, send_from_directory, jsonify
def handle_message(message):
    print('SERVER 5000>>> received message: ' + message)
    send(message, broadcast=True)
示例#17
0
def on_connect():
    """
    socket.io 连接事件
    """
    online_users[session.get('user').get('id')] = request.sid
    send('connect')
示例#18
0
 def cb_handle_message(message):
     flask_socketio.send('message received!')
示例#19
0
def test_message(message):
    print("called!")
    print("receive: ")
    print(message)
    #emit('aaa', message)
    send(message, namespace=namespace)
示例#20
0
def on_connect_test():
    send('connected-test')
示例#21
0
 def on_connect(self):
     send('connected-ns')
示例#22
0
def on_json(data):
    send(data, json=True, broadcast=True)
    if not data.get('noackargs'):
        return data
示例#23
0
def on_message(message):
    send(message)
    if message == 'test session':
        session['a'] = 'b'
    if message not in "test noackargs":
        return message
示例#24
0
def on_message_test(message):
    send(message)
示例#25
0
def on_json_test(data):
    send(data, json=True, namespace='/test')
示例#26
0
def on_connect():
    send('connected')
示例#27
0
from flask import Flask , request, send_from_directory, jsonify
示例#28
0
def on_room_namespace_event(data):
    room = data.pop('room')
    send('room message', room=room)
示例#29
0
def  handleMessage(msg):
    print('Message: ' + msg)
    send(msg, broadcast=True)
示例#30
0
 def cb_handle_connect():
     flask_socketio.send('connected')