def runserver(): socketio.run(app)
from app import create_app from extensions import socketio app = create_app() socketio.run(app)
migrate = Migrate( APP, models.db, # allow migrate to notice string length changes compare_type=True) # Tests # TODO: make this not just one test before views registered if redis_connected: # Register program's standard views APP.register_blueprint(urls) elif not redis_connected: # Show only error page @APP.route('/', defaults={'path': ''}) @APP.route('/<path:path>') def redis_handler(path): return render_template('redis.html') # Tie extensions to APP fm.init_app(APP, pipe) login_manager.init_app(APP) socketio.init_app(APP) import flask_together.events # noqa if __name__ == '__main__': socketio.run(APP)
username_from = self.get_username_by_sid() user_from = User.get_by_username(username_from) user_to = User.get_by_username(data["to"]) message = Message(data["message"], data["from"], data["to"]) user_from.messages.append(message) user_to.messages.append(message) message.save() user_from.save() user_to.save() to_sid = self.get_sid_by_username(data['to']) if to_sid: emit("message", data['message'], room=to_sid) message.set_delivered() def on_get_updates(self): username = self.get_username_by_sid() user = User.get_by_username(username) messages = user.get_unread_messages() if messages: serialized_messages = [msg.serialize() for msg in messages] data = {"messages": serialized_messages} emit("update", data, room=request.sid) Message.set_messages_delivered(messages) socketio.on_namespace(ChatSocksApi('/')) if __name__ == "__main__": socketio.run(app=app, host=host, port=port)