diff --git a/apps/ssb/tf-tab-connections.js b/apps/ssb/tf-tab-connections.js
index 25a6d5b4..b51b4d7f 100644
--- a/apps/ssb/tf-tab-connections.js
+++ b/apps/ssb/tf-tab-connections.js
@@ -42,11 +42,8 @@ class TfTabConnectionsElement extends LitElement {
let self = this;
let peers = this.broadcasts.filter(x => x.tunnel?.id == connection);
if (peers.length) {
- return html`
-
- ${peers.map(x => html`${self.render_room_peer(x)}`)}
-
- `;
+ let connections = this.connections.map(x => x.id);
+ return html`${peers.filter(x => connections.indexOf(x.pubkey) == -1).map(x => html`${self.render_room_peer(x)}`)}`;
}
}
@@ -59,7 +56,7 @@ class TfTabConnectionsElement extends LitElement {
return html`
self._tunnel(connection.tunnel.id, connection.pubkey)} value="Connect">
-
+ 📡
`;
}
@@ -79,6 +76,18 @@ class TfTabConnectionsElement extends LitElement {
this.stored_connections = (await tfrpc.rpc.getStoredConnections()) || [];
}
+ render_connection(connection) {
+ return html`
+ tfrpc.rpc.closeConnection(connection.id)} value="Close">
+
+ ${connection.tunnel !== undefined ? '🚇' : html`(${connection.host}:${connection.port})`}
+
+ ${this.connections.filter(x => x.tunnel === this.connections.indexOf(connection)).map(x => html`- ${this.render_connection(x)}
`)}
+ ${this.render_room_peers(connection.id)}
+
+ `;
+ }
+
render() {
let self = this;
return html`
@@ -93,12 +102,8 @@ class TfTabConnectionsElement extends LitElement {
Connections
Stored Connections (WIP)
diff --git a/src/ssb.c b/src/ssb.c
index 01d74d5e..e55ed935 100644
--- a/src/ssb.c
+++ b/src/ssb.c
@@ -1219,6 +1219,11 @@ bool tf_ssb_connection_get_id(tf_ssb_connection_t* connection, char* out_id, siz
tf_ssb_id_bin_to_str(out_id, out_id_size, connection->serverpub);
}
+tf_ssb_connection_t* tf_ssb_connection_get_tunnel(tf_ssb_connection_t* connection)
+{
+ return connection ? connection->tunnel_connection : NULL;
+}
+
static bool _tf_ssb_is_already_connected(tf_ssb_t* ssb, uint8_t* id, tf_ssb_connection_t* ignore_connection)
{
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next)
diff --git a/src/ssb.h b/src/ssb.h
index 8c1a3438..c3ebeb10 100644
--- a/src/ssb.h
+++ b/src/ssb.h
@@ -125,6 +125,7 @@ void tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value, tf_ssb_
bool tf_ssb_connection_is_client(tf_ssb_connection_t* connection);
const char* tf_ssb_connection_get_host(tf_ssb_connection_t* connection);
int tf_ssb_connection_get_port(tf_ssb_connection_t* connection);
+tf_ssb_connection_t* tf_ssb_connection_get_tunnel(tf_ssb_connection_t* connection);
tf_ssb_t* tf_ssb_connection_get_ssb(tf_ssb_connection_t* connection);
JSContext* tf_ssb_connection_get_context(tf_ssb_connection_t* connection);
sqlite3* tf_ssb_connection_get_db(tf_ssb_connection_t* connection);
diff --git a/src/ssb.js.c b/src/ssb.js.c
index 13b92b7f..eee8d6cb 100644
--- a/src/ssb.js.c
+++ b/src/ssb.js.c
@@ -22,6 +22,10 @@
#include
#include
+#if !defined(_countof)
+#define _countof(a) ((int)(sizeof((a)) / sizeof(*(a))))
+#endif
+
static JSClassID _tf_ssb_classId;
void _tf_ssb_on_rpc(tf_ssb_connection_t* connection, uint8_t flags, int32_t request_number, JSValue args, const uint8_t* message, size_t size, void* user_data);
@@ -319,16 +323,34 @@ static JSValue _tf_ssb_connections(JSContext* context, JSValueConst this_val, in
tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId);
if (ssb)
{
- const char** connections = tf_ssb_get_connection_ids(ssb);
- if (connections)
+ tf_ssb_connection_t* connections[32];
+ int count = tf_ssb_get_connections(ssb, connections, _countof(connections));
+
+ result = JS_NewArray(context);
+ for (int i = 0; i < count; i++)
{
- result = JS_NewArray(context);
- uint32_t i = 0;
- for (const char** p = connections; *p; p++, i++)
+ char id[k_id_base64_len] = { 0 };
+ tf_ssb_connection_t* connection = connections[i];
+ JSValue object = JS_NewObject(context);
+ tf_ssb_connection_get_id(connection, id, sizeof(id));
+ JS_SetPropertyStr(context, object, "id", JS_NewString(context, id));
+ JS_SetPropertyStr(context, object, "host", JS_NewString(context, tf_ssb_connection_get_host(connection)));
+ JS_SetPropertyStr(context, object, "port", JS_NewInt32(context, tf_ssb_connection_get_port(connection)));
+ tf_ssb_connection_t* tunnel = tf_ssb_connection_get_tunnel(connection);
+ if (tunnel)
{
- JS_SetPropertyUint32(context, result, i, JS_NewString(context, *p));
+ int tunnel_index = -1;
+ for (int j = 0; j < count; j++)
+ {
+ if (connections[j] == tunnel)
+ {
+ tunnel_index = j;
+ break;
+ }
+ }
+ JS_SetPropertyStr(context, object, "tunnel", JS_NewInt32(context, tunnel_index));
}
- tf_free(connections);
+ JS_SetPropertyUint32(context, result, i, object);
}
}
return result;