import {LitElement, html} from './lit-all.min.js'; import * as tfrpc from '/static/tfrpc.js'; class TfTabConnectionsElement extends LitElement { static get properties() { return { broadcasts: {type: Array}, identities: {type: Array}, connections: {type: Array}, stored_connections: {type: Array}, users: {type: Object}, }; } constructor() { super(); let self = this; this.broadcasts = []; this.identities = []; this.connections = []; this.stored_connections = []; this.users = {}; tfrpc.rpc.getAllIdentities().then(function(identities) { self.identities = identities || []; }); tfrpc.rpc.getStoredConnections().then(function(connections) { self.stored_connections = connections || []; }); } render_connection_summary(connection) { if (connection.address && connection.port) { return html`(${connection.address}:${connection.port})`; } else if (connection.tunnel) { return html`(room peer)`; } else { return JSON.stringify(connection); } } render_room_peers(connection) { let self = this; let peers = this.broadcasts.filter(x => x.tunnel?.id == connection); if (peers.length) { return html` `; } } async _tunnel(portal, target) { return tfrpc.rpc.createTunnel(portal, target); } render_room_peer(connection) { let self = this; return html`
  • self._tunnel(connection.tunnel.id, connection.pubkey)} value="Connect">
  • `; } render_broadcast(connection) { return html`
  • tfrpc.rpc.connect(connection)} value="Connect"> ${this.render_connection_summary(connection)}
  • `; } async forget_stored_connection(connection) { await tfrpc.rpc.forgetStoredConnection(connection); this.stored_connections = (await tfrpc.rpc.getStoredConnections()) || []; } render() { let self = this; return html`

    New Connection

    tfrpc.rpc.connect(self.renderRoot.getElementById('code').value)} value="Connect">

    Broadcasts

    Connections

    Stored Connections (WIP)

    Local Accounts

    `; } } customElements.define('tf-tab-connections', TfTabConnectionsElement);