def msgsendersock(json):
    global slnoforcommt
    if "t" in checkonlinemain(json):
        db.session.add(
            commdb(json["userid"], json["userplace"], json["msg"][:100],
                   json["etime"], ""))
        db.session.commit()
        print("MSg:" + json["msg"], "\nfrom user" + json["userid"])

        if (slnoforcommt == 0):
            mesgs = commdb.query.order_by(commdb.etime.desc()).first()
            slnoforcommt = mesgs.slno
        else:
            slnoforcommt += 1
        rmsg = {
            "slno": slnoforcommt,
            "userid": json["userid"],
            "userplace": json["userplace"],
            "comm": json["msg"],
            "etime": json["etime"]
        }
        if "filesl" in json:
            urmsg = rmsg.split("\n")[0]
            if urmsg == '':
                socketio.emit("fsend")
            #TODO:webrtc...........and socketio
        socketio.emit('update', rmsg, broadcast=True)
        send_android({
            "type": "update",
            "slno": slnoforcommt,
            "userid": json["userid"],
            "userplace": json["userplace"],
            "comm": json["msg"],
            "etime": json["etime"]
        })
Beispiel #2
0
def addComment():
    print([
        request.form.get("subpost"),
        request.form.get("postUUID"),
        request.form.get("sid")
    ])
    if checkExists([
            request.form.get("subpost"),
            request.form.get("postUUID"),
            request.form.get("sid")
    ]):
        post = Post.query.filter_by(uuid=request.form.get("postUUID")).first()
        subpost = SubPost(subpost=request.form.get("subpost"),
                          post_id=post.id,
                          user_id=current_user.id,
                          username=current_user.username)
        db.session.add(subpost)
        db.session.commit()
        data = [subpost.subpost, subpost.username]
        socketio.emit('recieveComment',
                      data,
                      room=request.form.get("postUUID"),
                      skip_sid=request.form.get("sid"),
                      broadcast=True)
        alertPost(post.user_id, current_user.username, post)
        return jsonify(data)
    print("failure")
    return jsonify("")
def test_disconnect():
    etime = int(time.time())
    add_stat("A user disconnects")
    users = userlogins.query.filter(userlogins.rtime >= etime - 8).all()
    rmsg = {}
    rmsg["length_json"] = len(users)
    for u in range(len(users)):
        rmsg[u] = {"userid": users[u].userid, "userplace": users[u].userplace}
    socketio.emit("online_check", rmsg, broadcast=True)
    print('user disconected')
def conn(msg):
    print("connected")
    socketio.emit("update")
    etime = int(time.time())
    users = userlogins.query.filter(userlogins.rtime >= etime - 8).all()
    rmsg = {}
    rmsg["length_json"] = len(users)
    for u in range(len(users)):
        rmsg[u] = {"userid": users[u].userid, "userplace": users[u].userplace}
    socketio.emit("online_check", rmsg, broadcast=True)
Beispiel #5
0
def update_state():
        global socketio
        global cur_dest_id
        global dest_conf
        global msg
        if cur_status == states.PLAY:
                msg = dest_conf.id_tree[cur_dest_id]['name']
		pin_on(cur_dest_id)
	else:
		msg = config.STOP_STATE_MSG
		resetPins()
        socketio.emit('my response',{'data':msg},namespace='/test')
Beispiel #6
0
def update_state():
    global socketio
    global cur_dest_id
    global dest_conf
    global msg
    if cur_status == states.PLAY:
        msg = dest_conf.id_tree[cur_dest_id]['name']
        pin_on(cur_dest_id)
    else:
        msg = config.STOP_STATE_MSG
        resetPins()
    socketio.emit('my response', {'data': msg}, namespace='/test')
Beispiel #7
0
def on_comments():
    if request.method == 'POST':
        if not request.is_json:
            author = request.form.get('author')
            title = request.form.get('title')
            content = request.form.get('content')
        else:
            author = request.get_json().get('author')
            title = request.get_json().get('title')
            content = request.get_json().get('content')

        comment = db.create_comment(title, content, author)
        socketio.emit('new comment', {'comment': model_to_dict(comment)},
                      broadcast=True)

        return jsonify({'comment': model_to_dict(comment)})

    comments = db.get_comments().dicts()

    return jsonify({'comments': [comment for comment in comments]})
Beispiel #8
0
 def callback(progress):
     socketio.emit('progress', data={'progress': progress}, room=room)
def add_stat(comm):
    etime = int(time.time())
    db.session.add(stattable(comm, etime))
    db.session.commit()
    socketio.emit("updatestat", {"comm": comm, "etime": etime}, broadcast=True)
    send_android({"type": "updatestat", "comm": comm, "etime": etime})