class ChatNamespace(BaseNamespace, RoomsMixin, BroadcastMixin): def on_signin(self, name, cords): name = name + str(random.randint(0,10000)) cords = str(cords).split(",") self.c = Calculate((float(cords[0]),float(cords[1]))) self.environ.setdefault('person', []).append(name) self.socket.session['person'] = name self.broadcast_event('person', self.environ['person']) self.on_update_rooms() self.join('main_room') def on_update_rooms(self): a = self.c.genList() out = json.dumps(a) self.broadcast_event('rooms', out) def on_user_message(self, msg): self.emit_to_room('main_room', 'msg_to_room', self.socket.session['person'], msg) def on_preoccupy(self, msg): self.broadcast_event('preoccupy', '%s'% (msg)) def refresh(self): pass def recv_message(self, message): print "PING!!!", message
class ChatNamespace(BaseNamespace, RoomsMixin, BroadcastMixin): def on_signin(self, name, cords): name = name + str(random.randint(0,10000)) cords = str(cords).split(",") self.c = Calculate((float(cords[0]),float(cords[1]))) self.environ.setdefault('person', []).append(name) self.socket.session['person'] = name self.broadcast_event('person', self.environ['person']) self.broadcast_event('new_user') self.on_update_rooms() self.join('main_room') def on_push(self, cords): self.broadcast_event('pull', cords ) def on_calculate(self, cords): results =[] for c in cords: if c == None: continue else: cs = str(c).split(",") cord = (cs[0], cs[1]) results.append(cord) print results b = Best() best = b.genBest(results) self.broadcast_event('best_room', best ) def on_update_rooms(self): a = self.c.genList() out = json.dumps(a) self.broadcast_event('rooms', out) def on_user_message(self, msg): self.emit_to_room('main_room', 'msg_to_room', self.socket.session['person'], msg) def on_preoccupy(self, msg): self.broadcast_event('preoccupy', '%s'% (msg)) def on_clear(self): self.broadcast_event('clear') def refresh(self): pass def recv_message(self, message): print "PING!!!", message
# Flask routes app = Flask(__name__) @app.route('/') def index(): return send_file('public/index.html') @app.route('/<path:path>') def re(path): return redirect("/") @app.route("/socket.io/<path:path>") def run_socketio(path): socketio_manage(request.environ, {'': ChatNamespace}) return Response() if __name__ == '__main__': print 'Listening on http://localhost:8080' c = Calculate((42.37223265, -71.116110)) c.genList() port = int(os.environ.get('PORT', 3000)) app.debug = True from werkzeug.wsgi import SharedDataMiddleware app = SharedDataMiddleware(app, { '/': os.path.join(os.path.dirname(__file__), 'public') }) from socketio.server import SocketIOServer SocketIOServer(('', port), app, resource="socket.io", transports=['xhr-polling','websocket'], policy_server=False).serve_forever()