Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: test #503

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions examples/grid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,48 @@
import { DRPNode } from "@ts-drp/node";
import { DRPNode, DRPNodeConfig } from "@ts-drp/node";
import { enableTracing, IMetrics, OpentelemetryMetrics } from "@ts-drp/tracer";

import { Grid } from "./objects/grid";
import { render, enableUIControls, renderInfo } from "./render";
import { gridState } from "./state";
import { getColorForPeerId } from "./util/color";

export function getNetworkConfigFromEnv() {
export function getNetworkConfigFromEnv(): DRPNodeConfig {
const hasBootstrapPeers = Boolean(import.meta.env.VITE_BOOTSTRAP_PEERS);
const hasDiscoveryInterval = Boolean(import.meta.env.VITE_DISCOVERY_INTERVAL);

const hasEnv = hasBootstrapPeers || hasDiscoveryInterval;

const config: Record<string, unknown> = {
browser_metrics: true,
const config: DRPNodeConfig = {
network_config: {
browser_metrics: true,
},
};

if (!hasEnv) {
config.network_config = {
...config.network_config,
bootstrap_peers: [
"/ip4/127.0.0.1/tcp/50000/ws/p2p/12D3KooWC6sm9iwmYbeQJCJipKTRghmABNz1wnpJANvSMabvecwJ",
],
browser_metrics: true,
};
return config;
}

if (hasBootstrapPeers) {
config.bootstrap_peers = import.meta.env.VITE_BOOTSTRAP_PEERS.split(",");
config.network_config = {
...config.network_config,
bootstrap_peers: import.meta.env.VITE_BOOTSTRAP_PEERS.split(","),
};
}

if (hasDiscoveryInterval) {
config.pubsub = {
peer_discovery_interval: import.meta.env.VITE_DISCOVERY_INTERVAL,
config.network_config = {
...config.network_config,
pubsub: {
...config.network_config?.pubsub,
peer_discovery_interval: import.meta.env.VITE_DISCOVERY_INTERVAL,
},
};
}

Expand Down Expand Up @@ -139,7 +155,7 @@ async function main() {
}

const networkConfig = getNetworkConfigFromEnv();
gridState.node = new DRPNode(networkConfig ? { network_config: networkConfig } : undefined);
gridState.node = new DRPNode(networkConfig);
await gridState.node.start();
await gridState.node.networkNode.isDialable(async () => {
console.log("Started node", import.meta.env);
Expand Down
4 changes: 4 additions & 0 deletions examples/grid/src/objects/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export class Grid implements DRP {
}

moveUser(userId: string, direction: string): void {
this._moveUser(userId, direction);
}

private _moveUser(userId: string, direction: string): void {
const userColorString = [...this.positions.keys()].find((u) => u.startsWith(`${userId}:`));
if (userColorString) {
const position = this.positions.get(userColorString);
Expand Down
10 changes: 2 additions & 8 deletions packages/object/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,8 @@ export class DRPObject implements DRPObjectBase {
if ((propKey as string).startsWith("query_")) {
return Reflect.apply(applyTarget, thisArg, args);
}
const callerName = new Error().stack?.split("\n")[2]?.trim().split(" ")[1];
if (callerName?.startsWith("DRPObject.resolveConflicts")) {
return Reflect.apply(applyTarget, thisArg, args);
}
if (!callerName?.startsWith("Proxy.")) {
return obj.callFn(fullPropKey, args, vertexType);
}
return Reflect.apply(applyTarget, thisArg, args);

return obj.callFn(fullPropKey, args, vertexType);
},
});
}
Expand Down