-
Notifications
You must be signed in to change notification settings - Fork 16
/
doc-test-signal.ts
54 lines (49 loc) · 1.51 KB
/
doc-test-signal.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { AdminWebsocket, AppWebsocket, CellType } from "./lib/index.js";
const adminWs = await AdminWebsocket.connect({
url: new URL("ws://127.0.0.1:65000"),
wsClientOptions: { origin: "my-happ" },
});
const agent_key = await adminWs.generateAgentPubKey();
const role_name = "foo";
const installed_app_id = "test-app";
const appInfo = await adminWs.installApp({
agent_key,
path: "./test/e2e/fixture/test.happ",
installed_app_id,
membrane_proofs: {},
});
await adminWs.enableApp({ installed_app_id });
if (!(CellType.Provisioned in appInfo.cell_info[role_name][0])) {
throw new Error(`No cell found under role name ${role_name}`);
}
const { cell_id } = appInfo.cell_info[role_name][0][CellType.Provisioned];
await adminWs.authorizeSigningCredentials(cell_id);
await adminWs.attachAppInterface({ port: 65001, allowed_origins: "my-happ" });
const issuedToken = await adminWs.issueAppAuthenticationToken({
installed_app_id,
});
const appWs = await AppWebsocket.connect({
url: new URL("ws://127.0.0.1:65001"),
token: issuedToken.token,
wsClientOptions: { origin: "my-happ" },
});
let signalCb;
const signalReceived = new Promise<void>((resolve) => {
signalCb = (signal) => {
console.log("signal received", signal);
// act on signal
resolve();
};
});
appWs.on("signal", signalCb);
// trigger an emit_signal
await appWs.callZome({
cell_id,
zome_name: "foo",
fn_name: "emitter",
provenance: agent_key,
payload: null,
});
await signalReceived;
await appWs.client.close();
await adminWs.client.close();