forked from IRL-CT/tinkerbelle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtinker.py
More file actions
62 lines (48 loc) · 1.41 KB
/
Copy pathtinker.py
File metadata and controls
62 lines (48 loc) · 1.41 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from flask import Flask, render_template
from flask_socketio import SocketIO, send, emit
import socket
import sys
port = 5002
app = Flask(__name__)
socketio = SocketIO(app)
def broadcast(name, value):
emit(name, value, broadcast=True, include_self=False)
def get_ip_address():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# use a public address to bypass the need to connect
s.connect(("8.8.8.8", 80))
ip_address = s.getsockname()[0]
s.close()
return ip_address
@socketio.on('connect')
def test_connect():
print('connected')
emit('after connect', {'data':'Lets dance'})
@socketio.on('message')
def handle_message(data):
print('received message: ' + data)
@socketio.on('hex')
def handle_hex(val):
broadcast('hex', val)
@socketio.on('audio')
def handle_audio(val):
broadcast('audio', val)
@socketio.on('pauseAudio')
def handle_pause(val):
broadcast('pauseAudio', val)
@socketio.on('autoFlash')
def handle_auto_flash(cfg):
broadcast('autoFlash', cfg)
@socketio.on('stopAuto')
def handle_stop_auto(_val):
broadcast('stopAuto', {})
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
ip = get_ip_address()
if ip:
print(f"access at http://{ip}:{port}")
else:
print(f"No non-local IP found. Access may be available at http://127.0.0.1:{port}")
socketio.run(app, host='0.0.0.0', port=port, debug=False, use_reloader=False, allow_unsafe_werkzeug=True)