aboutsummaryrefslogtreecommitdiff
path: root/api/game/socket.py
blob: c4e5ac7f6a346e68c3c804984c8d31589efb35df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask import Blueprint, request, make_response
from flask_socketio import SocketIO, emit, disconnect, Namespace, emit
import time
import json

class GameSocketNamespace(Namespace):
    def connect(self):
        print("new connection")
        emit("gert", {"gert": "banaan"})

    def on_connect(self):
        print("new connection")
        emit("gert", {"gert": "banaan"})

    def on_disconnect(self):
        print("disconnect")

    def new_move(self, data):
        print("new_move")
        print(data)

    def resign(self, data):
        print("resign")
        print(data)

def run(app):
    socketio = SocketIO(app)
    socketio.on_namespace(GameSocketNamespace("/game/socket"))
    socketio.run(app, host="127.0.0.1", port=5000, debug=True)