| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | <!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> | 
					
						
							| 
									
										
										
										
											2015-02-03 07:16:05 -08:00
										 |  |  | <button onclick="test2()">Private send</button> | 
					
						
							| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | <table width="100%" id="table"> | 
					
						
							| 
									
										
										
										
											2015-01-30 13:47:18 +01:00
										 |  |  | 	<tr> | 
					
						
							|  |  |  | 		<td>Count</td> | 
					
						
							|  |  |  | 		<td id="count"></td> | 
					
						
							|  |  |  | 	</tr> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | 	<tr> | 
					
						
							|  |  |  | 		<td>ID</td> | 
					
						
							|  |  |  | 		<td id="id"></td> | 
					
						
							|  |  |  | 	</tr> | 
					
						
							| 
									
										
										
										
											2015-01-30 13:47:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	<tr> | 
					
						
							|  |  |  | 		<td>Has identity</td> | 
					
						
							|  |  |  | 		<td id="known"></td> | 
					
						
							|  |  |  | 	</tr> | 
					
						
							| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | </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; | 
					
						
							| 
									
										
										
										
											2015-01-30 13:47:18 +01:00
										 |  |  | 	document.querySelector("#known").innerHTML =  shh.haveIdentity(id); | 
					
						
							| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 13:47:18 +01:00
										 |  |  | 	var watch = shh.watch({topics: ["test"]}) | 
					
						
							|  |  |  | 	watch.arrived(function(message) { | 
					
						
							| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | 		document.querySelector("#table").innerHTML += "<tr><td colspan='2'>"+JSON.stringify(message)+"</td></tr>"; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-03 07:16:05 -08:00
										 |  |  | 	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>"; | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | 	function test() { | 
					
						
							| 
									
										
										
										
											2015-01-30 13:47:18 +01:00
										 |  |  | 		shh.post({topics: ["test"], payload: web3.fromAscii("test it")}); | 
					
						
							|  |  |  | 		count(); | 
					
						
							| 
									
										
										
										
											2015-02-03 07:16:05 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-01-30 13:47:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-03 07:16:05 -08:00
										 |  |  | 	function test2() { | 
					
						
							|  |  |  | 		shh.post({to: id, topics: ["test"], payload: web3.fromAscii("Private")}); | 
					
						
							|  |  |  | 		count(); | 
					
						
							| 
									
										
										
										
											2015-01-30 13:47:18 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function count() { | 
					
						
							|  |  |  | 		document.querySelector("#count").innerHTML = watch.messages().length; | 
					
						
							| 
									
										
										
										
											2015-01-30 13:25:12 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </html> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |