registry/example/src/example.ts

25 lines
852 B
TypeScript
Raw Normal View History

2021-09-13 12:32:36 +03:00
import { FluencePeer } 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 12:32:36 +03:00
const peer = FluencePeer.default;
await peer.init({ 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 12:32:36 +03:00
let relay = peer.connectionInfo.connectedRelay!;
await initTopicAndSubscribe(peer, topic, value, relay, null);
2021-07-28 13:53:38 +03:00
// find other peers subscribed to that topic
2021-09-13 12:32:36 +03:00
let subscribers = await findSubscribers(peer, 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);
});