-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
119 lines (107 loc) · 3.93 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Compsoscuttly: Scuttlesaurus in the Browser</title>
<script type="text/javascript" src="./js/editable-list.js"></script>
<script type="module" src="https://unpkg.com/[email protected]/side-drawer.js"></script>
<style>
side-drawer {
background-color: #ffffff;
color: inherit;
width: 900px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}
body {
margin: 8px;
}
</style>
</head>
<body>
<h1>Compsoscuttly: Scuttlesaurus in the browser</h1>
Source on <a href="https://github.com/retog/scuttlesaurus">GitHub</a>.<br>
<a id="opener"><svg viewBox="0 0 100 80" width="40" height="40">
<title>Settings</title>
<rect width="100" height="20"></rect>
<rect y="30" width="100" height="20"></rect>
<rect y="60" width="100" height="20"></rect>
</svg></a><br>
<p>The most recent messages as they arrive:</p>
<select id="feedChooser"></select>
<div id="log">
</div>
<side-drawer id="drawer">
<editable-list id="peerList" title="Peers" add-item-text="Add new peer:">
</editable-list>
<editable-list id="feedsList" title="Subscribed Feeds" add-item-text="Add new feed:">
</editable-list>
</side-drawer>
<script>
const opener = document.getElementById("opener");
const drawer = document.getElementById("drawer");
opener.addEventListener("click", () => {
drawer.open = true;
});
</script>
<script type="module">
import ScuttlebuttHost, { parseFeedId, parseAddress } from "./js/scuttlebutt-host.js";
const logArea = document.getElementById("log");
const host = new ScuttlebuttHost({
peers: [
"ws:ssb.farewellutopia.com:8989~shs:A2x/4olpyciSh+KXTULh9QFCCBCu5SSbL4ZmytwIuZw="
],
follow: [
"@luoZnBKHXeJl4kB39uIkZnQD4L0zl6Vd+Pe75gKS4fo=.ed25519",
"@IX0YhhVNgs9btLPepGlyLpXKvB0URDHLrmrm4yDlD1c=.ed25519",
"@rdUCfjvbTlNYr0SWekHzrkiI5WcLJ6rx+VzYc8MFRuY=.ed25519"
]
});
const feedChooser = document.getElementById("feedChooser");
const populateFeedChooser = () => {
feedChooser.innerHTML = "";
host.feedsAgent.subscriptions.forEach(feed => feedChooser.innerHTML += `<option>${feed.toString()}</option>`);
}
populateFeedChooser();
let feedShowTaskCount = 0;
const showSelectedFeed = () => {
const thisShowTask = ++feedShowTaskCount;
const feedId = parseFeedId(feedChooser.value);
const showFeed = async () => {
logArea.innerHTML = "";
for await (const msg of host.feedsAgent.getFeed(feedId, { fromMessage: -5 })) {
if (thisShowTask < feedShowTaskCount) break;
logArea.innerHTML = `<br/> Feed: ${feedId} <br/>
<code>${JSON.stringify(msg)}</code><hr/>` + logArea.innerHTML;
}
};
showFeed();
}
showSelectedFeed();
feedChooser.addEventListener("change", showSelectedFeed);
//this disables blobs
host.agents = [host.feedsAgent];
host.start();
const peerList = document.getElementById("peerList");
host.peers.forEach(peer => peerList.addValue(peer.toString()));
peerList.addEventListener("change", (e) => {
console.log(`event: ${e.detail}`);
console.log(`setting: ${peerList.values}`);
//TODO be smarter
host.peers.clear();
peerList.values.forEach(addrStr => host.peers.add(parseAddress(addrStr)));
});
const feedsList = document.getElementById("feedsList");
host.followees.forEach(peer => feedsList.addValue(peer.toString()));
feedsList.addEventListener("change", (e) => {
console.log(`setting: ${feedsList.values}`);
//TODO be smarter
host.followees.clear();
feedsList.values.forEach(feedIdStr => host.followees.add(parseFeedId(feedIdStr)));
host.connectionManager.reset();
populateFeedChooser();
});
</script>
</body>
</html>