summaryrefslogtreecommitdiffstats
path: root/webapp/app/views.py
blob: 4aa2c05461e63acb30bd878747eca26c65de87c5 (plain) (blame)
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
31
32
33
34
35
36
37
from flask import render_template, request
from app import app, sio
import time

import threading

thread = None

@app.route('/')
@app.route('/index')
def index():
    return render_template('index.html',
                           title='F16 Group1')

connections = set()

@sio.on('connect', namespace='/spawn')
def connect(sid, environ):
    print("connect ", sid)
    connections.add(sid)

@sio.on('spawn', namespace='/spawn')
def message(sid, data):
    print("message ", data)

@sio.on('disconnect', namespace='/spawn')
def disconnect(sid):
    print('disconnect', sid)
    connections.remove(sid)



def add_creature():
    time.sleep(5)
    sio.emit('new creature', {'name': 'fish1'}, namespace='/spawn')

thread = sio.start_background_task(add_creature)