@hypersoniclabs/helix-sdk 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -0
- package/dist/camera.d.ts +14 -0
- package/dist/camera.js +72 -0
- package/dist/camera.js.map +1 -0
- package/dist/index.d.ts +106 -2
- package/dist/index.js +640 -9
- package/dist/index.js.map +1 -1
- package/dist/multiplayer-contract/credential.d.ts +42 -0
- package/dist/multiplayer-contract/credential.js +5 -0
- package/dist/multiplayer-contract/credential.js.map +1 -0
- package/dist/multiplayer-contract/index.d.ts +14 -0
- package/dist/multiplayer-contract/index.js +30 -0
- package/dist/multiplayer-contract/index.js.map +1 -0
- package/dist/multiplayer-contract/messages.d.ts +284 -0
- package/dist/multiplayer-contract/messages.js +111 -0
- package/dist/multiplayer-contract/messages.js.map +1 -0
- package/dist/multiplayer-contract/room.d.ts +126 -0
- package/dist/multiplayer-contract/room.js +17 -0
- package/dist/multiplayer-contract/room.js.map +1 -0
- package/dist/multiplayer-contract/state.d.ts +61 -0
- package/dist/multiplayer-contract/state.js +15 -0
- package/dist/multiplayer-contract/state.js.map +1 -0
- package/dist/multiplayer.d.ts +133 -0
- package/dist/multiplayer.js +334 -0
- package/dist/multiplayer.js.map +1 -0
- package/dist/protocol.d.ts +196 -1
- package/dist/protocol.js +16 -4
- package/dist/protocol.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +14 -1
package/README.md
CHANGED
|
@@ -36,6 +36,23 @@ loginButton.onclick = async () => {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
Helix.auth.onAuthChanged((user) => updateUi(user)); // login + logout
|
|
39
|
+
|
|
40
|
+
// Ask the HELIX shell to render native status notifications.
|
|
41
|
+
Helix.notify.success('Prize claimed', 'Welcome Chip added to inventory');
|
|
42
|
+
Helix.notify.failure('Purchase failed', 'Not enough LIX');
|
|
43
|
+
Helix.notify.notification('Quest updated', 'Return to the VIP lounge');
|
|
44
|
+
Helix.notify.message('Nova', 'Meet me by the arcade machines');
|
|
45
|
+
|
|
46
|
+
// Publish a current interaction prompt without tying your world to a renderer.
|
|
47
|
+
Helix.prompts.set({
|
|
48
|
+
id: 'fortune-arcade.vip',
|
|
49
|
+
title: 'VIP Room',
|
|
50
|
+
description: 'Buy a keycard to enter.',
|
|
51
|
+
input: { key: 'E', label: 'Interact' },
|
|
52
|
+
actionLabel: 'Buy keycard',
|
|
53
|
+
state: 'available',
|
|
54
|
+
});
|
|
55
|
+
Helix.prompts.clear('fortune-arcade.vip');
|
|
39
56
|
```
|
|
40
57
|
|
|
41
58
|
When the world is opened directly (e.g. a local `vite dev` server with no shell), `init()` resolves
|
|
@@ -49,8 +66,92 @@ and embedded.
|
|
|
49
66
|
- `Helix.auth.isAuthenticated(): boolean`
|
|
50
67
|
- `Helix.auth.requestLogin(): Promise<HelixUser>` — resolves on login, rejects on dismiss/unavailable.
|
|
51
68
|
- `Helix.auth.onAuthChanged(fn): () => void` — fires on login and logout; returns an unsubscribe fn.
|
|
69
|
+
- `Helix.notify.show({ kind, title, message?, timeoutMs?, actionLabel?, actionHref? }): boolean`
|
|
70
|
+
- `Helix.notify.success|failure|notification|message(title, message?): boolean` — returns `false` when
|
|
71
|
+
the world is running standalone without a shell.
|
|
72
|
+
- `Helix.prompts.set({ id, title, description?, input?, actionLabel?, state?, priority? }): boolean`
|
|
73
|
+
- `Helix.prompts.clear(promptId?): boolean`
|
|
52
74
|
- `Helix.getSessionToken(): string | null` — the world-scoped token, for advanced direct API calls.
|
|
53
75
|
|
|
76
|
+
### Economy & items (v2, shell-mediated)
|
|
77
|
+
|
|
78
|
+
All of these are **server-authoritative**: the world *requests*, the shell (which holds the player's
|
|
79
|
+
session) settles with the backend and renders the purchase popup. Reads degrade to empty defaults
|
|
80
|
+
when not embedded; a purchase returns `Unauthorized` (never a fake success).
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const { lix, coins } = await Helix.wallet.getBalance();
|
|
84
|
+
Helix.wallet.onBalanceChanged((b) => updateHud(b));
|
|
85
|
+
|
|
86
|
+
// Buy a marketplace item or a world-registered product. completed === player owns it now.
|
|
87
|
+
const res = await Helix.marketplace.purchaseItem('premium_sword_001');
|
|
88
|
+
if (res.completed) equip('premium_sword_001'); // Granted | Claimed | AlreadyOwned
|
|
89
|
+
else showToast(res.status); // InsufficientFunds | Cancelled | …
|
|
90
|
+
|
|
91
|
+
await Helix.marketplace.purchaseProduct('golden_key'); // a world product
|
|
92
|
+
const items = await Helix.marketplace.getListings({ kind: 'home_item' });
|
|
93
|
+
|
|
94
|
+
// Ownership gating — works across worlds & creators (VIP / season passes).
|
|
95
|
+
if (await Helix.inventory.hasItem('vip_pass_001')) openBackstage();
|
|
96
|
+
const owned = await Helix.inventory.getMyItems();
|
|
97
|
+
await Helix.inventory.equipItem('vip_hat_001');
|
|
98
|
+
Helix.inventory.onInventoryChanged(refreshInventory);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- `Helix.wallet.getBalance()` / `onBalanceChanged(fn)`
|
|
102
|
+
- `Helix.marketplace.purchaseItem(itemId)` / `purchaseProduct(productId)` / `getListings(query?)` / `getPurchaseContext(ref)`
|
|
103
|
+
- `Helix.inventory.hasItem(id)` / `getQuantity(id)` / `getMyItems()` / `equipItem(id)` / `onInventoryChanged(fn)`
|
|
104
|
+
|
|
105
|
+
The SDK mints a stable idempotency key per purchase (reused across the popup's retries) so a dropped
|
|
106
|
+
network can never double-charge. See the backend `/api/v1/iwp/*` endpoints for the settlement layer.
|
|
107
|
+
|
|
108
|
+
### Interaction prompts
|
|
109
|
+
|
|
110
|
+
`Helix.prompts` is intentionally engine-agnostic. A Three.js, Phaser, Unity WebGL, or plain DOM world
|
|
111
|
+
can all publish the same contract: a stable prompt id, display text, optional keyboard/gamepad labels,
|
|
112
|
+
and a coarse state (`default`, `available`, `locked`, or `busy`). The shell decides how to render it.
|
|
113
|
+
|
|
114
|
+
### Rich presence
|
|
115
|
+
|
|
116
|
+
Push a **live activity** for the local player that enriches the baseline "In [World]" their friends
|
|
117
|
+
already see (in the friends sidebar and on their profile) — e.g. `Racing — lap 3/5`. It's **dynamic**:
|
|
118
|
+
call it whenever the moment changes, no registration, no per-activity setup.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
// Enrich presence with whatever the player is doing right now.
|
|
122
|
+
await Helix.presence.setActivity({
|
|
123
|
+
state: 'Racing — lap 3/5', // required, ≤128 chars — the line friends see
|
|
124
|
+
details: 'Sunset Circuit', // optional second line, ≤128 chars
|
|
125
|
+
party: { current: 2, max: 8 }, // optional party sizing
|
|
126
|
+
// image: 'my-mode-icon', // optional; omitted → the world's thumbnail (zero-config)
|
|
127
|
+
// joinable: true, // hint only; joining an instance ships with the MP runtime
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// e.g. drive it off game state
|
|
131
|
+
raceEvents.on('lap', (n, total) =>
|
|
132
|
+
Helix.presence.setActivity({ state: `Racing — lap ${n}/${total}` }),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Back to plain "In [World]". Also happens automatically when the player leaves.
|
|
136
|
+
await Helix.presence.clearActivity();
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- `Helix.presence.setActivity(activity)` → `Promise<boolean>` — `true` on success; `false` for guests,
|
|
140
|
+
outside a shell, when not in a world, or when rejected. **Never throws** into your game loop.
|
|
141
|
+
- `Helix.presence.clearActivity()` → `Promise<boolean>`.
|
|
142
|
+
|
|
143
|
+
**Server-authoritative (by design).** `setActivity` posts to the authenticated presence endpoint using
|
|
144
|
+
the player's own session. The server sets activity **only for that player** and **only for the world
|
|
145
|
+
they're currently in** — a world can never write another player's status, or a world they aren't in.
|
|
146
|
+
This is the interim of the "the world's server sets it" model: when the multiplayer room runtime lands
|
|
147
|
+
it will set activity server-to-server after authenticating the player into its instance; the API and
|
|
148
|
+
validation are already shaped for that. Backend: `POST` / `DELETE /api/v1/users/me/presence/activity`.
|
|
149
|
+
|
|
150
|
+
**Privacy & safety.** Activity is governed by the player's presence privacy (visibility
|
|
151
|
+
`Everyone / Friends only / Nobody`, plus a *hide-activity* toggle) — if they've opted out, the server
|
|
152
|
+
never emits it, to anyone. Text is length-capped, rate-limited, and screened by the shared text
|
|
153
|
+
moderation layer server-side (a bad-actor world can't push junk into a friend's status card).
|
|
154
|
+
|
|
54
155
|
## Protocol
|
|
55
156
|
|
|
56
157
|
[`src/protocol.ts`](src/protocol.ts) is the wire contract (`postMessage` messages between world and
|
package/dist/camera.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CameraAspect } from './protocol';
|
|
2
|
+
export type CaptureOptions = {
|
|
3
|
+
aspect?: CameraAspect;
|
|
4
|
+
type?: string;
|
|
5
|
+
quality?: number;
|
|
6
|
+
};
|
|
7
|
+
export type CropRect = {
|
|
8
|
+
sx: number;
|
|
9
|
+
sy: number;
|
|
10
|
+
sw: number;
|
|
11
|
+
sh: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function cropRectForAspect(w: number, h: number, aspect?: CameraAspect): CropRect;
|
|
14
|
+
export declare function captureCanvas(source: HTMLCanvasElement, opts?: CaptureOptions): Promise<Blob>;
|
package/dist/camera.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Camera capture helpers — the in-iframe pixel side of the universal world camera.
|
|
2
|
+
//
|
|
3
|
+
// The SDK core (index.ts) owns the shell-mediated `Helix.camera.savePhoto`. This
|
|
4
|
+
// file holds the pure/DOM-only capture glue so it can be unit-tested without the
|
|
5
|
+
// postMessage shell: the crop math is pure; `captureCanvas` is the one DOM call.
|
|
6
|
+
//
|
|
7
|
+
// WebGL gotcha: the drawing buffer is cleared after each frame, so reading a
|
|
8
|
+
// WebGL canvas a frame later yields black. Callers must either render into the
|
|
9
|
+
// canvas immediately before capturing (same tick), capture inside the rAF right
|
|
10
|
+
// after the world's render, or create the context with preserveDrawingBuffer.
|
|
11
|
+
// Aspect ratios as width/height. `free`/`square` are handled in cropRectForAspect.
|
|
12
|
+
const ASPECT_RATIO = {
|
|
13
|
+
portrait: 3 / 4,
|
|
14
|
+
landscape: 4 / 3,
|
|
15
|
+
};
|
|
16
|
+
// Centre-crop rectangle for a source canvas of (w×h) at the requested aspect.
|
|
17
|
+
// `free` returns the full frame; `square` is 1:1. Pure — no DOM.
|
|
18
|
+
export function cropRectForAspect(w, h, aspect = 'free') {
|
|
19
|
+
if (w <= 0 || h <= 0)
|
|
20
|
+
return { sx: 0, sy: 0, sw: Math.max(0, w), sh: Math.max(0, h) };
|
|
21
|
+
if (aspect === 'free')
|
|
22
|
+
return { sx: 0, sy: 0, sw: w, sh: h };
|
|
23
|
+
const target = aspect === 'square' ? 1 : ASPECT_RATIO[aspect];
|
|
24
|
+
const current = w / h;
|
|
25
|
+
let sw = w;
|
|
26
|
+
let sh = h;
|
|
27
|
+
if (current > target) {
|
|
28
|
+
// too wide → crop width
|
|
29
|
+
sw = Math.round(h * target);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// too tall → crop height
|
|
33
|
+
sh = Math.round(w / target);
|
|
34
|
+
}
|
|
35
|
+
const sx = Math.round((w - sw) / 2);
|
|
36
|
+
const sy = Math.round((h - sh) / 2);
|
|
37
|
+
return { sx, sy, sw, sh };
|
|
38
|
+
}
|
|
39
|
+
// Capture a (rendered) canvas to an encoded Blob, centre-cropped to `aspect`.
|
|
40
|
+
// DOM-only. Throws if the environment has no 2D canvas (non-browser) or the
|
|
41
|
+
// canvas is empty. The caller is responsible for rendering into `source` first.
|
|
42
|
+
export async function captureCanvas(source, opts = {}) {
|
|
43
|
+
const type = opts.type ?? 'image/jpeg';
|
|
44
|
+
const quality = opts.quality ?? 0.92;
|
|
45
|
+
const { sx, sy, sw, sh } = cropRectForAspect(source.width, source.height, opts.aspect ?? 'free');
|
|
46
|
+
if (sw <= 0 || sh <= 0) {
|
|
47
|
+
throw new Error('Helix.camera: nothing to capture (empty canvas)');
|
|
48
|
+
}
|
|
49
|
+
// Crop via an offscreen 2D canvas. When aspect is 'free' and no crop is needed
|
|
50
|
+
// we still copy through a 2D canvas so toBlob works uniformly across a WebGL
|
|
51
|
+
// source canvas.
|
|
52
|
+
const out = typeof OffscreenCanvas !== 'undefined'
|
|
53
|
+
? new OffscreenCanvas(sw, sh)
|
|
54
|
+
: Object.assign(document.createElement('canvas'), { width: sw, height: sh });
|
|
55
|
+
const ctx = out.getContext('2d');
|
|
56
|
+
if (!ctx)
|
|
57
|
+
throw new Error('Helix.camera: 2D canvas context unavailable');
|
|
58
|
+
ctx.drawImage(source, sx, sy, sw, sh, 0, 0, sw, sh);
|
|
59
|
+
return canvasToBlob(out, type, quality);
|
|
60
|
+
}
|
|
61
|
+
function canvasToBlob(canvas, type, quality) {
|
|
62
|
+
// OffscreenCanvas exposes convertToBlob; HTMLCanvasElement exposes toBlob.
|
|
63
|
+
const offscreen = canvas;
|
|
64
|
+
if (typeof offscreen.convertToBlob === 'function') {
|
|
65
|
+
return offscreen.convertToBlob({ type, quality });
|
|
66
|
+
}
|
|
67
|
+
const el = canvas;
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
el.toBlob((blob) => blob ? resolve(blob) : reject(new Error('Helix.camera: toBlob returned null')), type, quality);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=camera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,EAAE;AACF,iFAAiF;AACjF,iFAAiF;AACjF,iFAAiF;AACjF,EAAE;AACF,6EAA6E;AAC7E,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAa9E,mFAAmF;AACnF,MAAM,YAAY,GAA6D;IAC7E,QAAQ,EAAE,CAAC,GAAG,CAAC;IACf,SAAS,EAAE,CAAC,GAAG,CAAC;CACjB,CAAC;AAEF,8EAA8E;AAC9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C;AAC/D,CAAC;AAED,SAAS,YAAY,CACnB,MAA2C,EAC3C,IAAY,EACZ,OAAe;IAEf,2EAA2E;IAC3E,MAAM,SAAS,GAAG,MAEjB,CAAC;IACF,IAAI,OAAO,SAAS,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;QAClD,OAAO,SAAS,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACpD,CAAC;IACD,MAAM,EAAE,GAAG,MAA2B,CAAC;IACvC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,EAAE,CAAC,MAAM,CACP,CAAC,IAAI,EAAE,EAAE,CACP,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,EAChF,IAAI,EACJ,OAAO,CACR,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,135 @@
|
|
|
1
|
-
import { HelixWorldContext, HelixUser } from './protocol';
|
|
2
|
-
|
|
1
|
+
import { HelixInteractionPrompt, HelixNotification, HelixWorldContext, HelixUser, DebugLogEntry, Balance, PurchaseResult, PurchaseContext, InventoryItem, EquippedAvatar, AvatarLoadout, AvatarLoadoutPatch, HelixPresenceActivity, MarketplaceListing, MarketplaceQuery, CameraAspect, SavedPhoto } from './protocol';
|
|
2
|
+
import { HelixMultiplayer } from './multiplayer';
|
|
3
|
+
import { CaptureOptions } from './camera';
|
|
4
|
+
export type { HelixInteractionPrompt, HelixNotification, HelixNotificationKind, HelixPromptState, HelixDeviceFormFactor, HelixWorldContext, HelixSession, HelixUser, DebugLogEntry, DebugLogLevel, Balance, PurchaseResult, PurchaseStatus, PurchaseContext, InventoryItem, EquippedAvatar, AvatarLoadout, AvatarLoadoutPatch, HelixPresenceActivity, MarketplaceListing, MarketplaceQuery, CameraAspect, SavedPhoto, } from './protocol';
|
|
5
|
+
export type { CaptureOptions, CropRect } from './camera';
|
|
6
|
+
export { cropRectForAspect, captureCanvas } from './camera';
|
|
7
|
+
export type { HelixRoom, JoinRoomOptions, ReplicaInput } from './multiplayer';
|
|
8
|
+
export * from './multiplayer-contract';
|
|
3
9
|
export type HelixInitResult = {
|
|
4
10
|
embedded: boolean;
|
|
5
11
|
world: HelixWorldContext | null;
|
|
6
12
|
user: HelixUser | null;
|
|
7
13
|
};
|
|
8
14
|
type AuthListener = (user: HelixUser | null) => void;
|
|
15
|
+
type AnalyticsEventName = 'world_entered' | 'world_loaded' | 'world_load_failed' | 'world_exited' | 'world_heartbeat' | 'instance_joined' | 'instance_left' | 'creator_product_viewed' | 'client_error_seen' | 'api_error_seen';
|
|
16
|
+
type AnalyticsTrackInput = {
|
|
17
|
+
eventId?: string;
|
|
18
|
+
instanceId?: string | null;
|
|
19
|
+
itemId?: string | null;
|
|
20
|
+
inviteId?: string | null;
|
|
21
|
+
referrer?: string | null;
|
|
22
|
+
properties?: Record<string, string | number | boolean | null | undefined>;
|
|
23
|
+
};
|
|
9
24
|
declare class HelixSdk {
|
|
10
25
|
private shellOrigin;
|
|
11
26
|
private session;
|
|
12
27
|
private world;
|
|
13
28
|
private initialized;
|
|
14
29
|
private listeners;
|
|
30
|
+
private debugEnabled;
|
|
31
|
+
private debugRing;
|
|
32
|
+
private debugListeners;
|
|
33
|
+
private consoleHooked;
|
|
15
34
|
private pendingLogins;
|
|
35
|
+
private pendingRequests;
|
|
36
|
+
private balanceListeners;
|
|
37
|
+
private inventoryListeners;
|
|
38
|
+
private avatarListeners;
|
|
16
39
|
init(): Promise<HelixInitResult>;
|
|
40
|
+
readonly multiplayer: HelixMultiplayer;
|
|
41
|
+
readonly debug: {
|
|
42
|
+
enabled: () => boolean;
|
|
43
|
+
log: (...args: unknown[]) => void;
|
|
44
|
+
onLog: (cb: (entry: DebugLogEntry) => void) => (() => void);
|
|
45
|
+
recent: () => DebugLogEntry[];
|
|
46
|
+
};
|
|
17
47
|
readonly auth: {
|
|
18
48
|
getUser: () => Promise<HelixUser | null>;
|
|
19
49
|
isAuthenticated: () => boolean;
|
|
20
50
|
requestLogin: () => Promise<HelixUser>;
|
|
21
51
|
onAuthChanged: (listener: AuthListener) => (() => void);
|
|
22
52
|
};
|
|
53
|
+
readonly notify: {
|
|
54
|
+
show: (notification: HelixNotification) => boolean;
|
|
55
|
+
success: (title: string, message?: string) => boolean;
|
|
56
|
+
failure: (title: string, message?: string) => boolean;
|
|
57
|
+
notification: (title: string, message?: string) => boolean;
|
|
58
|
+
message: (title: string, message?: string) => boolean;
|
|
59
|
+
};
|
|
60
|
+
readonly prompts: {
|
|
61
|
+
set: (prompt: HelixInteractionPrompt) => boolean;
|
|
62
|
+
clear: (promptId?: string) => boolean;
|
|
63
|
+
};
|
|
64
|
+
readonly device: {
|
|
65
|
+
openTablet: () => boolean;
|
|
66
|
+
openPhone: () => boolean;
|
|
67
|
+
};
|
|
23
68
|
getSessionToken(): string | null;
|
|
69
|
+
readonly wallet: {
|
|
70
|
+
getBalance: () => Promise<Balance>;
|
|
71
|
+
onBalanceChanged: (cb: (b: Balance) => void) => (() => void);
|
|
72
|
+
};
|
|
73
|
+
readonly marketplace: {
|
|
74
|
+
purchaseItem: (itemId: string) => Promise<PurchaseResult>;
|
|
75
|
+
purchaseProduct: (productId: string) => Promise<PurchaseResult>;
|
|
76
|
+
getListings: (query?: MarketplaceQuery) => Promise<MarketplaceListing[]>;
|
|
77
|
+
getPurchaseContext: (ref: string) => Promise<PurchaseContext | null>;
|
|
78
|
+
};
|
|
79
|
+
readonly analytics: {
|
|
80
|
+
track: (eventName: AnalyticsEventName, input?: AnalyticsTrackInput) => Promise<void>;
|
|
81
|
+
};
|
|
82
|
+
readonly inventory: {
|
|
83
|
+
hasItem: (itemId: string) => Promise<boolean>;
|
|
84
|
+
getQuantity: (itemId: string) => Promise<number>;
|
|
85
|
+
getMyItems: () => Promise<InventoryItem[]>;
|
|
86
|
+
equipItem: (itemId: string) => Promise<void>;
|
|
87
|
+
onInventoryChanged: (cb: () => void) => (() => void);
|
|
88
|
+
};
|
|
89
|
+
readonly dataStore: {
|
|
90
|
+
get: <T = unknown>(key: string) => Promise<T | null>;
|
|
91
|
+
set: <T = unknown>(key: string, value: T) => Promise<void>;
|
|
92
|
+
delete: (key: string) => Promise<void>;
|
|
93
|
+
list: (prefix?: string) => Promise<string[]>;
|
|
94
|
+
};
|
|
95
|
+
readonly camera: {
|
|
96
|
+
available: () => boolean;
|
|
97
|
+
capture: (canvas: HTMLCanvasElement, opts?: CaptureOptions) => Promise<Blob>;
|
|
98
|
+
savePhoto: (image: Blob | ArrayBuffer | Uint8Array, meta?: {
|
|
99
|
+
caption?: string;
|
|
100
|
+
aspect?: CameraAspect;
|
|
101
|
+
contentType?: string;
|
|
102
|
+
}) => Promise<SavedPhoto | null>;
|
|
103
|
+
};
|
|
104
|
+
readonly avatar: {
|
|
105
|
+
openCreator: () => Promise<boolean>;
|
|
106
|
+
getLoadout: () => Promise<AvatarLoadout | null>;
|
|
107
|
+
updateLoadout: (patch: AvatarLoadoutPatch) => Promise<AvatarLoadout | null>;
|
|
108
|
+
getEquipped: () => Promise<EquippedAvatar | null>;
|
|
109
|
+
onAvatarChanged: (cb: () => void) => (() => void);
|
|
110
|
+
};
|
|
111
|
+
readonly presence: {
|
|
112
|
+
setActivity: (activity: HelixPresenceActivity) => Promise<boolean>;
|
|
113
|
+
clearActivity: () => Promise<boolean>;
|
|
114
|
+
};
|
|
115
|
+
private purchase;
|
|
116
|
+
private trackAnalytics;
|
|
117
|
+
private safeAnalyticsProperties;
|
|
118
|
+
private openDevice;
|
|
119
|
+
private onKeyDown;
|
|
120
|
+
private request;
|
|
121
|
+
private newId;
|
|
122
|
+
private fetchAvatarLoadout;
|
|
123
|
+
private emitAvatarChanged;
|
|
24
124
|
private snapshot;
|
|
25
125
|
private assertInitialized;
|
|
26
126
|
private waitForInit;
|
|
27
127
|
private onMessage;
|
|
28
128
|
private setSession;
|
|
129
|
+
private enableDebug;
|
|
130
|
+
private hookConsole;
|
|
131
|
+
private captureLog;
|
|
29
132
|
private post;
|
|
133
|
+
private postToShell;
|
|
30
134
|
}
|
|
31
135
|
export declare const Helix: HelixSdk;
|