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 15:30:43 +03:00
|
|
|
import { initTopicAndSubscribeBlocking, 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-09-19 18:12:30 +03:00
|
|
|
let topic = "myTopic" + new Date().valueOf();
|
2021-07-28 13:53:38 +03:00
|
|
|
let value = "myValue";
|
2021-09-19 18:12:30 +03:00
|
|
|
console.log("Will create topic", topic);
|
2021-07-28 13:53:38 +03:00
|
|
|
// create topic (if not exists) and subscribe on it
|
2021-09-13 13:44:30 +03:00
|
|
|
let relay = Fluence.getStatus().relayPeerId;
|
2021-09-13 15:30:43 +03:00
|
|
|
await initTopicAndSubscribeBlocking(
|
|
|
|
topic, value, relay, null,
|
|
|
|
(s) => console.log(`node ${s} saved the record`)
|
|
|
|
);
|
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);
|
|
|
|
});
|