Skip to content

Commit

Permalink
object subscription w/ optional params
Browse files Browse the repository at this point in the history
  • Loading branch information
d-roak committed Jul 7, 2024
1 parent 2f433bd commit 726010b
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions packages/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,28 @@ export class TopologyNode {

/// Subscribe to the object's PubSub group
/// and fetch it from a peer
async subscribeObject(objectId: string) {
async subscribeObject(objectId: string, fetch = false, peerId = "") {
this._networkNode.subscribe(objectId);
if (!fetch) return;
const message = `{
"type": "object_fetch",
"sender": "${this._networkNode.peerId}",
"data": [${uint8ArrayFromString(objectId)}]
}`;

await this._networkNode.sendGroupMessageRandomPeer(
objectId,
["/topology/message/0.0.1"],
message,
);
if (peerId === "") {
await this._networkNode.sendGroupMessageRandomPeer(
objectId,
["/topology/message/0.0.1"],
message,
);
} else {
await this._networkNode.sendMessage(
peerId,
["/topology/message/0.0.1"],
message,
);
}
}

getPeers() {
Expand Down

0 comments on commit 726010b

Please sign in to comment.