This is a sample for line up module base on Flask server.
install python package gevent-websocket
pip install gevent-websocket
or use requirements.txt
pip install -r requirements.txt
import the lineup.py
module
import lineup
add route to the line up handler
app.add_url_rule('/lineup', 'lineup', lineup.handler)
run the server by line up(websocket support) instead of defaule app.run()
server = lineup.server(app)
server.serve_forever()
load lineup.js
in the html
<script src="static/js/lineup.js"></script>
write your callback function when server announce
function onmessage(data) {
// data = {'number': <your position in line>,
// 'total': <total person in line>}
if (data.number == 0) {
// do what you want to do
} else {
// you should still waiting
}
}
finally start the lineup module
lineup.init(websocket_url, onmessage);