-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
45 lines (34 loc) · 1.12 KB
/
app.py
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
def about():
window.location = "./pages/about.html"
def sendMsg():
textfield = document.getElementById("input")
textfield.focus()
text = textfield.value
if text: # ignore empty field
window.webxdc.sendUpdate(
{
"payload": {
"sender": window.webxdc.selfName,
"text": text,
}
},
f'someone typed "{text}"',
)
textfield.value = ""
def receiveUpdate(update):
msg = update.payload
msgs = document.getElementById("msgs")
msgs.innerHTML += f"<strong><{msg['sender']}></strong> {msg['text']}<br>"
def onInput():
if event.key == "Enter":
sendMsg()
def _onload():
body = document.getElementsByTagName("body")[0]
body.innerHTML += (
'<input id="input" type="text" onkeydown="app.onInput();"/>'
+ '<button onclick="app.sendMsg();">Send</button>'
+ ' <button onclick="app.about();">About</button>'
+ '<p id="msgs"></p>'
)
window.webxdc.setUpdateListener(receiveUpdate, 0) # process incoming messages
window.onload = _onload