-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
61 lines (51 loc) · 1.49 KB
/
index.js
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
const gatewayHTTP = 'http://localhost:1633';
const gatewayWS = 'ws://localhost:1733';
const topic = 'ws-poc';
let listen = (openCallback, messageCallback) => {
// Create WebSocket connection.
const socket = new WebSocket(`${gatewayWS}/pss/subscribe/${topic}`);
// Listen for messages
socket.addEventListener('message', async function (event) {
console.log(event)
messageCallback(await event.data.text());
});
// Log errors
socket.addEventListener('error', function (event) {
console.log(event)
});
};
let send = async (prefix, publicKey, messageText) => {
var b = document.getElementById("bzzAudioSend");
b.play();
let url = `${gatewayHTTP}/pss/send/${topic}/${prefix}?recipient=${publicKey}`;
return await axios.post(url, messageText);
};
let init = async () => {
let app = new Vue({
el: '#app',
data: {
messages: [
],
overlayAddress: "",
publicKey: "",
messageText: "",
},
methods: {
sendMessage: async function(){
send(
this.overlayAddress,
this.publicKey,
this.messageText
);
}
}
});
listen(console.log, (message) => {
if(message != ""){
app.messages.push({message: message});
var b = document.getElementById("bzzAudioReceive");
b.play();
}
});
};
init();