2022-09-06 19:26:43 -04:00
|
|
|
import * as tfrpc from '/tfrpc.js';
|
|
|
|
|
|
|
|
let g_database;
|
|
|
|
let g_hash;
|
|
|
|
|
|
|
|
tfrpc.register(async function localStorageGet(key) {
|
|
|
|
return app.localStorageGet(key);
|
|
|
|
});
|
|
|
|
tfrpc.register(async function localStorageSet(key, value) {
|
|
|
|
return app.localStorageSet(key, value);
|
|
|
|
});
|
|
|
|
tfrpc.register(async function databaseGet(key) {
|
|
|
|
return g_database ? g_database.get(key) : undefined;
|
|
|
|
});
|
|
|
|
tfrpc.register(async function databaseSet(key, value) {
|
|
|
|
return g_database ? g_database.set(key, value) : undefined;
|
|
|
|
});
|
2022-09-11 13:42:41 -04:00
|
|
|
tfrpc.register(async function createIdentity() {
|
|
|
|
return ssb.createIdentity();
|
|
|
|
});
|
2023-10-20 10:37:24 -04:00
|
|
|
tfrpc.register(async function getServerIdentity() {
|
|
|
|
return ssb.getServerIdentity();
|
|
|
|
});
|
|
|
|
tfrpc.register(async function setServerFollowingMe(id, following) {
|
|
|
|
return ssb.setServerFollowingMe(id, following);
|
|
|
|
});
|
2022-09-06 19:26:43 -04:00
|
|
|
tfrpc.register(async function getIdentities() {
|
|
|
|
return ssb.getIdentities();
|
|
|
|
});
|
2022-09-09 22:56:15 -04:00
|
|
|
tfrpc.register(async function getAllIdentities() {
|
|
|
|
return ssb.getAllIdentities();
|
|
|
|
});
|
2023-10-30 12:18:07 -04:00
|
|
|
tfrpc.register(async function following(ids, depth) {
|
|
|
|
return ssb.following(ids, depth);
|
|
|
|
});
|
2022-09-09 22:56:15 -04:00
|
|
|
tfrpc.register(async function getBroadcasts() {
|
|
|
|
return ssb.getBroadcasts();
|
|
|
|
});
|
|
|
|
tfrpc.register(async function getConnections() {
|
|
|
|
return ssb.connections();
|
|
|
|
});
|
2023-01-17 19:57:54 -05:00
|
|
|
tfrpc.register(async function getStoredConnections() {
|
|
|
|
return ssb.storedConnections();
|
|
|
|
});
|
|
|
|
tfrpc.register(async function forgetStoredConnection(connection) {
|
|
|
|
return ssb.forgetStoredConnection(connection);
|
|
|
|
});
|
2023-01-17 18:10:17 -05:00
|
|
|
tfrpc.register(async function createTunnel(portal, target) {
|
|
|
|
return ssb.createTunnel(portal, target);
|
2022-11-12 22:36:48 -05:00
|
|
|
});
|
2022-11-08 21:15:33 -05:00
|
|
|
tfrpc.register(async function connect(token) {
|
|
|
|
await ssb.connect(token);
|
|
|
|
});
|
2022-11-08 20:47:47 -05:00
|
|
|
tfrpc.register(async function closeConnection(id) {
|
|
|
|
await ssb.closeConnection(id);
|
|
|
|
});
|
2022-09-06 19:26:43 -04:00
|
|
|
tfrpc.register(async function query(sql, args) {
|
|
|
|
let result = [];
|
2023-02-14 21:43:08 -05:00
|
|
|
await ssb.sqlAsync(sql, args, function callback(row) {
|
2022-09-06 19:26:43 -04:00
|
|
|
result.push(row);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
tfrpc.register(async function appendMessage(id, message) {
|
|
|
|
return ssb.appendMessageWithIdentity(id, message);
|
|
|
|
});
|
|
|
|
core.register('message', async function message_handler(message) {
|
|
|
|
if (message.event == 'hashChange') {
|
|
|
|
g_hash = message.hash;
|
|
|
|
await tfrpc.rpc.hashChanged(message.hash);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
tfrpc.register(function getHash(id, message) {
|
|
|
|
return g_hash;
|
|
|
|
});
|
2022-09-14 20:16:37 -04:00
|
|
|
tfrpc.register(function setHash(hash) {
|
|
|
|
return app.setHash(hash);
|
|
|
|
});
|
2022-09-06 19:26:43 -04:00
|
|
|
ssb.addEventListener('message', async function (id) {
|
|
|
|
await tfrpc.rpc.notifyNewMessage(id);
|
|
|
|
});
|
|
|
|
tfrpc.register(async function store_blob(blob) {
|
|
|
|
if (Array.isArray(blob)) {
|
|
|
|
blob = Uint8Array.from(blob);
|
|
|
|
}
|
|
|
|
return await ssb.blobStore(blob);
|
|
|
|
});
|
2022-10-18 19:00:57 -04:00
|
|
|
tfrpc.register(async function get_blob(id) {
|
|
|
|
return utf8Decode(await ssb.blobGet(id));
|
|
|
|
});
|
2023-05-09 21:30:15 -04:00
|
|
|
tfrpc.register(async function store_message(message) {
|
|
|
|
return await ssb.storeMessage(message);
|
|
|
|
});
|
2022-10-18 19:00:57 -04:00
|
|
|
tfrpc.register(function apps() {
|
|
|
|
return core.apps();
|
|
|
|
});
|
2023-05-17 10:10:49 -04:00
|
|
|
tfrpc.register(async function try_decrypt(id, content) {
|
|
|
|
return await ssb.privateMessageDecrypt(id, content);
|
|
|
|
});
|
2023-08-31 21:34:01 -04:00
|
|
|
tfrpc.register(async function encrypt(id, recipients, content) {
|
|
|
|
return await ssb.privateMessageEncrypt(id, recipients, content);
|
|
|
|
});
|
2022-09-09 22:56:15 -04:00
|
|
|
ssb.addEventListener('broadcasts', async function () {
|
|
|
|
await tfrpc.rpc.set('broadcasts', await ssb.getBroadcasts());
|
|
|
|
});
|
|
|
|
|
|
|
|
core.register('onConnectionsChanged', async function () {
|
|
|
|
await tfrpc.rpc.set('connections', await ssb.connections());
|
|
|
|
});
|
2022-09-06 19:26:43 -04:00
|
|
|
|
|
|
|
async function main() {
|
|
|
|
if (typeof database !== 'undefined') {
|
|
|
|
g_database = await database('ssb');
|
|
|
|
}
|
|
|
|
await app.setDocument(utf8Decode(await getFile('index.html')));
|
|
|
|
}
|
|
|
|
main();
|