def chat_add(_id): try: Room.get(_id) except: return jsonify(error='No room with that name exists'), 400 user = current_user.id message = u'[%s]: %s' % (user, request.form['message']) l = logging.getLogger(_id) l.info(message) red = redis.Redis(connection_pool=pool) red.publish(_id, message) return jsonify(success='message posted')
def chat_get_or_create(): name = request.form['name'] module = Module(request.form['module_user'], request.form['module_name'], request.form['module_version']) try: Room.get(name) except: Room.add(name, module) l = logging.getLogger(name) h = logging.FileHandler(os.path.join(app.config['LOG_DIR'], name + '.log')) l.setLevel(logging.INFO) l.addHandler(h) return jsonify(room=dict(name=name))
def chat_code(_id): r = Room.get(_id) if r.module is None: return jsonify(error='no module of that name'), 404 return jsonify(module=dict( user=r.module.user, name=r.module.name, version=r.module.version, encrypt=r.module.encrypt, decrypt=r.module.decrypt, comms=r.module.comms))
def chat_stream(_id): try: Room.get(_id) except: return jsonify(error='No room with that name exists'), 400 return Response(stream(_id), mimetype="text/event-stream")