<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Spee.ch Claim</title>
</head>
<body>
	<div id="image">
		<h1>spee.ch</h1>
		<p>spee.ch is a single-serving site that reads and publishes images to and from the <a href="https://lbry.io">LBRY</a> blockchain.</p>
		<h3>Status:</h3>
		<p id="status">Your image is being retrieved</p>
	</div>
	<script src="/socket.io/socket.io.js"></script>
	<script>
		var socket = io();
		var url = document.URL.substring(document.URL.indexOf('3000/') + 5);
		// request the claim through the socket
		socket.emit("claim-request", url);
		// listen for updates
		socket.on("claim-update", function(data){
			console.log("data:", data);
			document.getElementById("status").innerHTML = data;
		})
		// receive the claim through the socket
		socket.on("claim-send", function(data){
			if (data.image) {
				var base64Image = 'data:image/jpeg;base64,' + data.buffer;
				document.getElementById("image").innerHTML = '<img src="' + base64Image + '"/>';
			}
		})
	</script>
</body>
</html>