-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
154 lines (128 loc) · 3.99 KB
/
index.html
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html>
<head>
<title> Gossip Testing </title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta icon="icon" href="icon.png" />
<script src="webxdc.js"></script>
<style type="text/css">
body {
font-family: Helvetica, Arial, sans-serif;
display: grid;
justify-items: stretch;
padding: 1em;
background: #BEA8A7;
}
h1 {
text-align: center;
color: #0D1821;
}
label {
color: #0D1821;
}
.ui {
display: flex;
flex-direction: column;
margin-bottom: 1em;
background: #F4DBD8;
padding: 1em;
border-radius: 0.5em;
max-width: 500px;
width: 100%;
}
.wrapper {
display: flex;
justify-content: center;
}
input {
background: #BEA8A7;
border: none;
border-radius: 0.5em;
padding: 8px 4px;
}
input::placeholder {
color: #847979;
}
#output {
display: flex;
flex-direction: column;
border: 2px dotted #65524D;
min-height: 300px;
border-radius: 0.5em;
padding: 0.5em;
overflow: auto;
max-height: 35vh;
}
button {
background: #C09891;
border: none;
border-radius: 0.5em;
padding: 8px 4px;
color: #0D1821;
cursor: pointer;
font: bold;
}
button:disabled {
background: #BEA8A7;
cursor: not-allowed;
}
</style>
</head>
<body>
<h1> Gossip Testing </h1>
<div class="wrapper">
<div class="ui">
<label style="margin-bottom: 2px"> Message </label>
<input id="message" placeholder="Message" style="margin-bottom: 1em"></input>
<button id="sendGossip" onclick="sendGossip()" style="margin-bottom: 0.5em"> Send GOSSIP
</button>
<button onclick="sendMsg()" style="margin-bottom: 0.5em"> Send SMTP </button>
<h1> Output </h1>
<div>
<div id="output"></div>
</div>
<button onclick="leave()" style="margin-top: 0.5em; background: #BEA8A7;"> Leave GOSSIP </button>
</div>
</div>
<script>
let webxdc = window.webxdc;
var El = function (tag, text) {
var el = document.createElement(tag);
el.innerText = text || '';
return el;
};
const realtimeChannel = window.webxdc.joinRealtimeChannel();
let enc = new TextEncoder()
let dec = new TextDecoder()
realtimeChannel.setListener((data) => {
console.log("Received Gossip: ", data);
var output = document.getElementById('output');
output.appendChild(El('span', "GOSSIP: " + dec.decode(data)));
})
window.webxdc.setUpdateListener(function (update) {
console.log("Received SMTP: ", update.payload);
var output = document.getElementById('output');
output.appendChild(El('span', "SMTP(" + update.payload.name + "): " + update.payload.msg));
});
function sendGossip() {
let msg = document.getElementById('message').value;
console.log("New Gossip message: ", enc.encode(msg));
realtimeChannel.send(enc.encode(msg));
}
function sendMsg() {
let msg = document.getElementById('message').value;
console.log("New SMTP message: ", msg);
window.webxdc.sendUpdate({
payload: {
name: window.webxdc.selfName,
msg,
},
}, "");
}
function leave() {
realtimeChannel.leave()
}
</script>
</body>
</html>