blob: ad568f7835fcbf20018c51294cad5357bed9ae19 (
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
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
|
<!doctype>
<html>
<title>Whisper test</title>
<head>
<script type="text/javascript" src="../ext/bignumber.min.js"></script>
<script type="text/javascript" src="../ext/ethereum.js/dist/ethereum.js"></script>
</head>
<body>
<h1>Whisper test</h1>
<button onclick="test()">Send</button>
<button onclick="test2()">Private send</button>
<table width="100%" id="table">
<tr>
<td>Count</td>
<td id="count"></td>
</tr>
<tr>
<td>ID</td>
<td id="id"></td>
</tr>
<tr>
<td>Has identity</td>
<td id="known"></td>
</tr>
</table>
</body>
<script type="text/javascript">
var web3 = require('web3');
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));
var shh = web3.shh;
var id = shh.newIdentity();
document.querySelector("#id").innerHTML = id;
document.querySelector("#known").innerHTML = shh.haveIdentity(id);
var watch = shh.watch({topics: ["test"]})
watch.arrived(function(message) {
document.querySelector("#table").innerHTML += "<tr><td colspan='2'>"+JSON.stringify(message)+"</td></tr>";
});
var selfWatch = shh.watch({to: id, topics: ["test"]})
selfWatch.arrived(function(message) {
document.querySelector("#table").innerHTML += "<tr><td>To me</td><td>"+JSON.stringify(message)+"</td></tr>";
});
function test() {
shh.post({topics: ["test"], payload: web3.fromAscii("test it")});
count();
}
function test2() {
shh.post({to: id, topics: ["test"], payload: web3.fromAscii("Private")});
count();
}
function count() {
document.querySelector("#count").innerHTML = watch.messages().length;
}
</script>
</html>
|