registry/example/src/example.ts

24 lines
798 B
TypeScript
Raw Normal View History

2021-09-13 13:44:30 +03:00
import { Fluence } from "@fluencelabs/fluence";
2021-07-28 13:53:38 +03:00
import { krasnodar } from "@fluencelabs/fluence-network-environment";
2021-09-13 12:32:36 +03:00
import { initTopicAndSubscribe, findSubscribers } from "./generated/export";
2021-07-28 13:53:38 +03:00
async function main() {
// connect to the Fluence network
2021-09-13 13:44:30 +03:00
await Fluence.start({ connectTo: krasnodar[1] });
2021-07-28 13:53:38 +03:00
let topic = "myTopic";
let value = "myValue";
// create topic (if not exists) and subscribe on it
2021-09-13 13:44:30 +03:00
let relay = Fluence.getStatus().relayPeerId;
await initTopicAndSubscribe(topic, value, relay, null);
2021-07-28 13:53:38 +03:00
// find other peers subscribed to that topic
2021-09-13 13:44:30 +03:00
let subscribers = await findSubscribers(topic);
2021-07-28 13:53:38 +03:00
console.log("found subscribers:", subscribers);
}
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});