Skip to content

Commit

Permalink
Merge pull request #165 from GeekGene/feat/holo-hosting-support
Browse files Browse the repository at this point in the history
Feat/holo hosting support
  • Loading branch information
mattyg authored Aug 29, 2023
2 parents 7756cfe + 5554a51 commit a1ec6ed
Show file tree
Hide file tree
Showing 8 changed files with 949 additions and 1,002 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ target/
.running

## ui files
dist.zip
dist.zip

## holo files
holo-dev-server
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ npm start

Each new agent that you create this way will get assigned its own port and get connected to the other agents.

## Holo Hosting

1. Get a copy of the Holo envoy server directly from a Holo team member, copy it to the root of the directory as `holo-dev-server`

To test out a holo hosted agent:

```bash
npm start:agent:holo
```

## Package

To package the web happ:
Expand Down
1,847 changes: 904 additions & 943 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"start:launcher": "VITE_IS_LAUNCHER=true AGENTS=2 npm run network:launcher",
"network:launcher": "hc s clean && npm run build:happ && UI_PORT=8888 concurrently \"npm run local-services\" \"npm start -w ui\" \"npm run launch:happ:launcher\" \"holochain-playground\"",
"launch:happ:launcher": "echo \"pass\" | RUST_LOG=warn hc launch --piped -n $AGENTS workdir/mewsfeed.happ --ui-port $UI_PORT network -b http://127.0.0.1:54000 webrtc ws://127.0.0.1:55000",
"start:agent:holo": "npm run build:happ && concurrently \"echo pass | lair-keystore server\" \"./holo-dev-server ./workdir/mewsfeed.happ\" \"sleep 15 && VITE_IS_HOLO_HOSTED=true VITE_CHAPERONE_SERVER_URL=http://127.0.0.1:24274 UI_PORT=5432 npm -w ui run start\"",
"test": "npm run build:happ && npm t -w tests",
"test:watch": "cargo watch --clear -- npm test",
"package": "npm run build:happ && VITE_IS_LAUNCHER=true npm run package:ui && hc web-app pack workdir",
Expand Down Expand Up @@ -49,8 +50,5 @@
},
"engines": {
"npm": ">=7.0.0"
},
"dependencies": {
"@holo-host/web-sdk": "github:mattyg/web-sdk#fix/update-hc-client"
}
}
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@fontsource/space-mono": "^5.0.3",
"@fontsource/syne": "^5.0.3",
"@headlessui/vue": "^1.7.14",
"@holo-host/web-sdk": "0.6.13-prerelease",
"@holochain-open-dev/profiles": "^0.14.1",
"@holochain/client": "^0.15.0",
"@shoelace-style/shoelace": "^2.4.0",
Expand Down
24 changes: 14 additions & 10 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
class="w-full flex justify-center items-center relative font-content cursor-default"
>
<profiles-context :store="profilesStore">
<HoloLogin v-if="IS_HOLO_HOSTED">
<MainLayout />
</HoloLogin>

<MainLayout v-else />
<MainLayout />

<div
v-if="loadingCells"
Expand All @@ -32,7 +28,6 @@
<script setup lang="ts">
import { computed, onMounted, provide, ref, toRaw, watch } from "vue";
import { IS_HOLO_HOSTED, setupHolo, setupHolochain } from "@/utils/client";
import HoloLogin from "@/components/HoloLogin.vue";
import MainLayout from "@/layouts/MainLayout.vue";
import { PROFILES_CONFIG } from "@/utils/profiles";
import "@shoelace-style/shoelace/dist/components/spinner/spinner";
Expand Down Expand Up @@ -73,18 +68,27 @@ const dnaProperties = computed(() =>
);
onMounted(() => {
asyncRetry(setup, {
factor: 1.3,
});
setup();
});
const setup = async () => {
// Setup client
if (IS_HOLO_HOSTED) {
client.value = await setupHolo();
} else {
client.value = await setupHolochain();
client.value = await asyncRetry(setupHolochain, {
factor: 1.3,
});
}
await asyncRetry(setupApp, {
factor: 1.3,
});
};
const setupApp = async () => {
if (!client.value) throw Error("Holo / Holochain client not ready");
appInfo.value = await client.value.appInfo();
// Setup profiles
Expand Down
39 changes: 0 additions & 39 deletions ui/src/components/HoloLogin.vue

This file was deleted.

21 changes: 15 additions & 6 deletions ui/src/utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import {
CellType,
AppAgentWebsocket,
} from "@holochain/client";
import WebSdkApi from "@holo-host/web-sdk";
import WebSdkApi, { AgentState } from "@holo-host/web-sdk";

export const HOLOCHAIN_APP_ID = "mewsfeed";
export const IS_LAUNCHER = import.meta.env.VITE_IS_LAUNCHER;
export const IS_HOLO_HOSTED = import.meta.env.VITE_IS_HOLO_HOSTED;

export const HOLO_CHAPERONE_URL = import.meta.env.VITE_CHAPERONE_SERVER_URL
? import.meta.env.VITE_CHAPERONE_SERVER_URL
: "http://localhost:24274";

export const setupHolochain = async () => {
try {
const client = await AppAgentWebsocket.connect(
Expand All @@ -37,16 +33,29 @@ export const setupHolochain = async () => {
};

export const setupHolo = async () => {
const HOLO_CHAPERONE_URL = import.meta.env.VITE_CHAPERONE_SERVER_URL
? import.meta.env.VITE_CHAPERONE_SERVER_URL
: "http://localhost:24274";

try {
const client = await WebSdkApi.connect({
chaperoneUrl: HOLO_CHAPERONE_URL,
authFormCustomization: {
logoUrl: "assets/cat-eating-bird-circle.png",
appName: "mewsfeed",
requireRegistrationCode: false,
},
});

await new Promise((resolve) =>
client.on("agent-state", (state: AgentState) => {
if (state.isAvailable && state.isAnonymous) {
client.signUp({});
} else if (state.isAvailable && !state.isAnonymous) {
resolve(state);
}
})
);

return client;
} catch (e) {
console.log("Holo client setup error", e);
Expand Down

0 comments on commit a1ec6ed

Please sign in to comment.