@hypersoniclabs/helix-sdk 0.1.1 → 0.1.9
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 +954 -2
- package/dist/action-surface.d.ts +182 -0
- package/dist/action-surface.js +1032 -0
- package/dist/action-surface.js.map +1 -0
- package/dist/camera.d.ts +78 -0
- package/dist/camera.js +640 -0
- package/dist/camera.js.map +1 -0
- package/dist/dev-shell/criteria.d.ts +46 -0
- package/dist/dev-shell/criteria.js +98 -0
- package/dist/dev-shell/criteria.js.map +1 -0
- package/dist/dev-shell/index.d.ts +189 -0
- package/dist/dev-shell/index.js +287 -0
- package/dist/dev-shell/index.js.map +1 -0
- package/dist/dev-shell/keys.d.ts +14 -0
- package/dist/dev-shell/keys.js +78 -0
- package/dist/dev-shell/keys.js.map +1 -0
- package/dist/dev-shell/simulator.d.ts +436 -0
- package/dist/dev-shell/simulator.js +1634 -0
- package/dist/dev-shell/simulator.js.map +1 -0
- package/dist/dev-shell/state.d.ts +148 -0
- package/dist/dev-shell/state.js +196 -0
- package/dist/dev-shell/state.js.map +1 -0
- package/dist/device-definition-resolver.d.ts +34 -0
- package/dist/device-definition-resolver.js +172 -0
- package/dist/device-definition-resolver.js.map +1 -0
- package/dist/device-trial.d.ts +3 -0
- package/dist/device-trial.js +132 -0
- package/dist/device-trial.js.map +1 -0
- package/dist/devices.d.ts +228 -0
- package/dist/devices.js +198 -0
- package/dist/devices.js.map +1 -0
- package/dist/dreamerAudio.d.ts +126 -0
- package/dist/dreamerAudio.js +135 -0
- package/dist/dreamerAudio.js.map +1 -0
- package/dist/generated/runtime-contract.d.ts +15529 -0
- package/dist/generated/runtime-contract.js +20470 -0
- package/dist/generated/runtime-contract.js.map +1 -0
- package/dist/index.d.ts +364 -3
- package/dist/index.js +1954 -13
- package/dist/index.js.map +1 -1
- package/dist/interaction-mode.d.ts +172 -0
- package/dist/interaction-mode.js +553 -0
- package/dist/interaction-mode.js.map +1 -0
- package/dist/internal/avatar-pose.d.ts +25 -0
- package/dist/internal/avatar-pose.js +46 -0
- package/dist/internal/avatar-pose.js.map +1 -0
- package/dist/internal/keyed-collection.d.ts +2 -0
- package/dist/internal/keyed-collection.js +12 -0
- package/dist/internal/keyed-collection.js.map +1 -0
- package/dist/internal/vehicle-detach-action.d.ts +2 -0
- package/dist/internal/vehicle-detach-action.js +6 -0
- package/dist/internal/vehicle-detach-action.js.map +1 -0
- package/dist/matchmaking.d.ts +433 -0
- package/dist/matchmaking.js +1487 -0
- package/dist/matchmaking.js.map +1 -0
- package/dist/materials.d.ts +122 -0
- package/dist/materials.js +217 -0
- package/dist/materials.js.map +1 -0
- package/dist/multiplayer-accessors.d.ts +100 -0
- package/dist/multiplayer-accessors.js +200 -0
- package/dist/multiplayer-accessors.js.map +1 -0
- package/dist/multiplayer-contract/avatar-pose.d.ts +112 -0
- package/dist/multiplayer-contract/avatar-pose.js +250 -0
- package/dist/multiplayer-contract/avatar-pose.js.map +1 -0
- package/dist/multiplayer-contract/credential.d.ts +80 -0
- package/dist/multiplayer-contract/credential.js +5 -0
- package/dist/multiplayer-contract/credential.js.map +1 -0
- package/dist/multiplayer-contract/final-rest.d.ts +66 -0
- package/dist/multiplayer-contract/final-rest.js +38 -0
- package/dist/multiplayer-contract/final-rest.js.map +1 -0
- package/dist/multiplayer-contract/index.d.ts +20 -0
- package/dist/multiplayer-contract/index.js +41 -0
- package/dist/multiplayer-contract/index.js.map +1 -0
- package/dist/multiplayer-contract/messages.d.ts +731 -0
- package/dist/multiplayer-contract/messages.js +237 -0
- package/dist/multiplayer-contract/messages.js.map +1 -0
- package/dist/multiplayer-contract/room.d.ts +177 -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 +241 -0
- package/dist/multiplayer-contract/state.js +15 -0
- package/dist/multiplayer-contract/state.js.map +1 -0
- package/dist/multiplayer-final-rest.d.ts +32 -0
- package/dist/multiplayer-final-rest.js +217 -0
- package/dist/multiplayer-final-rest.js.map +1 -0
- package/dist/multiplayer.d.ts +624 -0
- package/dist/multiplayer.js +2503 -0
- package/dist/multiplayer.js.map +1 -0
- package/dist/package.json +3 -0
- package/dist/protocol.d.ts +859 -1
- package/dist/protocol.js +117 -5
- package/dist/protocol.js.map +1 -1
- package/dist/runtime-contract/index.d.ts +15 -0
- package/dist/runtime-contract/index.js +12 -0
- package/dist/runtime-contract/index.js.map +1 -0
- package/dist/server-clock.d.ts +25 -0
- package/dist/server-clock.js +88 -0
- package/dist/server-clock.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/universal-vehicles.d.ts +111 -0
- package/dist/universal-vehicles.js +2 -0
- package/dist/universal-vehicles.js.map +1 -0
- package/dist/vault.d.ts +562 -0
- package/dist/vault.js +365 -0
- package/dist/vault.js.map +1 -0
- package/dist/vehicle-specialty-placement.d.ts +28 -0
- package/dist/vehicle-specialty-placement.js +154 -0
- package/dist/vehicle-specialty-placement.js.map +1 -0
- package/dist/vehicle-specialty-transport.d.ts +78 -0
- package/dist/vehicle-specialty-transport.js +183 -0
- package/dist/vehicle-specialty-transport.js.map +1 -0
- package/dist/voice.d.ts +229 -0
- package/dist/voice.js +1348 -0
- package/dist/voice.js.map +1 -0
- package/generated/runtime-contract/helix-runtime-contract.json +13332 -0
- package/generated/runtime-contract/known-answer.json +20471 -0
- package/generated/runtime-contract/known-answer.schema.json +630 -0
- package/generated/runtime-contract/runtime-contract.schema.json +607 -0
- package/generated/runtime-contract/unreal/HelixRuntimeContract.generated.h +908 -0
- package/package.json +44 -5
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
const MAX_SEEN_EFFECTS = 512;
|
|
2
|
+
const VEHICLE_COMPONENT_ACTION = /^[A-Za-z][A-Za-z0-9._:-]{0,63}$/;
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Binds a checksum-pinned Universal Vehicle specialty module to the normal
|
|
8
|
+
* HELIX room. State is hydrated immediately for late joiners, then assigned a
|
|
9
|
+
* client-local monotonic revision on every distinct authoritative patch.
|
|
10
|
+
*/
|
|
11
|
+
export class VehicleSpecialtyRoomTransport {
|
|
12
|
+
#room;
|
|
13
|
+
#binding;
|
|
14
|
+
#detachActionIds;
|
|
15
|
+
#stateSubscribers = new Set();
|
|
16
|
+
#effectSubscribers = new Set();
|
|
17
|
+
#seenEffects = new Set();
|
|
18
|
+
#roomUnsubscribers = [];
|
|
19
|
+
#revision = 0;
|
|
20
|
+
#fingerprint = '';
|
|
21
|
+
#latest = null;
|
|
22
|
+
#disposed = false;
|
|
23
|
+
constructor(room, binding) {
|
|
24
|
+
this.#room = room;
|
|
25
|
+
this.#binding = {
|
|
26
|
+
...binding,
|
|
27
|
+
stateVars: [...binding.stateVars],
|
|
28
|
+
detachActions: binding.detachActions,
|
|
29
|
+
};
|
|
30
|
+
this.#detachActionIds = Object.freeze(Object.keys(binding.detachActions?.actions ?? {}));
|
|
31
|
+
this.#capture();
|
|
32
|
+
const stateUnsubscribe = room.onStateChange(() => {
|
|
33
|
+
if (!this.#disposed)
|
|
34
|
+
this.#capture();
|
|
35
|
+
});
|
|
36
|
+
const effectUnsubscribe = room.onMessage('moduleEffect', (value) => {
|
|
37
|
+
if (!this.#disposed)
|
|
38
|
+
this.#effect(value);
|
|
39
|
+
});
|
|
40
|
+
if (typeof stateUnsubscribe === 'function')
|
|
41
|
+
this.#roomUnsubscribers.push(stateUnsubscribe);
|
|
42
|
+
if (typeof effectUnsubscribe === 'function')
|
|
43
|
+
this.#roomUnsubscribers.push(effectUnsubscribe);
|
|
44
|
+
}
|
|
45
|
+
invoke(invocation) {
|
|
46
|
+
if (this.#disposed)
|
|
47
|
+
throw new Error('Vehicle specialty transport is disposed');
|
|
48
|
+
const args = {};
|
|
49
|
+
for (const [name, value] of Object.entries(invocation.args)) {
|
|
50
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
51
|
+
args[name] = value;
|
|
52
|
+
}
|
|
53
|
+
this.#room.sendModuleAction({
|
|
54
|
+
identity: {
|
|
55
|
+
...(this.#binding.itemInstanceId ? { itemInstanceId: this.#binding.itemInstanceId } : {}),
|
|
56
|
+
moduleId: this.#binding.moduleId,
|
|
57
|
+
bundleChecksumSha256: this.#binding.bundleChecksumSha256,
|
|
58
|
+
revision: this.#binding.revision,
|
|
59
|
+
},
|
|
60
|
+
action: invocation.functionName,
|
|
61
|
+
args,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** The exact detachable-part action ids admitted by this signed placement. */
|
|
65
|
+
detachActionIds() {
|
|
66
|
+
return [...this.#detachActionIds];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Submit one admitted rigid-part detach intent with constructor-bound package
|
|
70
|
+
* identity. Unknown action ids fail closed without consuming a replay number.
|
|
71
|
+
*/
|
|
72
|
+
invokeDetach(invocation) {
|
|
73
|
+
if (this.#disposed)
|
|
74
|
+
throw new Error('Vehicle specialty transport is disposed');
|
|
75
|
+
if (!this.#binding.entityId || !this.#detachActionIds.includes(invocation.actionId) ||
|
|
76
|
+
typeof this.#room.sendVehicleDetachAction !== 'function')
|
|
77
|
+
return false;
|
|
78
|
+
return this.#room.sendVehicleDetachAction({
|
|
79
|
+
identity: {
|
|
80
|
+
...(this.#binding.itemInstanceId ? { itemInstanceId: this.#binding.itemInstanceId } : {}),
|
|
81
|
+
moduleId: this.#binding.moduleId,
|
|
82
|
+
bundleChecksumSha256: this.#binding.bundleChecksumSha256,
|
|
83
|
+
revision: this.#binding.revision,
|
|
84
|
+
},
|
|
85
|
+
entityId: this.#binding.entityId,
|
|
86
|
+
actionId: invocation.actionId,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Submit one server-authoritative component mutation using only the trusted
|
|
91
|
+
* constructor identity and entity. The room and server resolve live vehicle
|
|
92
|
+
* authority and admit the action against the signed component protocol.
|
|
93
|
+
*/
|
|
94
|
+
invokeComponent(invocation) {
|
|
95
|
+
if (this.#disposed ||
|
|
96
|
+
!this.#binding.entityId ||
|
|
97
|
+
typeof this.#room.sendVehicleComponentAction !== 'function' ||
|
|
98
|
+
!VEHICLE_COMPONENT_ACTION.test(invocation.action) ||
|
|
99
|
+
(invocation.targetBits !== undefined && (!Number.isSafeInteger(invocation.targetBits) ||
|
|
100
|
+
invocation.targetBits < 0 ||
|
|
101
|
+
invocation.targetBits > 0xffff)))
|
|
102
|
+
return false;
|
|
103
|
+
return this.#room.sendVehicleComponentAction({
|
|
104
|
+
identity: {
|
|
105
|
+
...(this.#binding.itemInstanceId ? { itemInstanceId: this.#binding.itemInstanceId } : {}),
|
|
106
|
+
moduleId: this.#binding.moduleId,
|
|
107
|
+
bundleChecksumSha256: this.#binding.bundleChecksumSha256,
|
|
108
|
+
revision: this.#binding.revision,
|
|
109
|
+
},
|
|
110
|
+
entityId: this.#binding.entityId,
|
|
111
|
+
action: invocation.action,
|
|
112
|
+
...(invocation.targetBits === undefined ? {} : { targetBits: invocation.targetBits }),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
subscribeState(subscriber) {
|
|
116
|
+
if (this.#disposed)
|
|
117
|
+
return () => undefined;
|
|
118
|
+
this.#stateSubscribers.add(subscriber);
|
|
119
|
+
if (this.#latest)
|
|
120
|
+
subscriber(this.#latest, { initial: true });
|
|
121
|
+
return () => void this.#stateSubscribers.delete(subscriber);
|
|
122
|
+
}
|
|
123
|
+
subscribeEffect(subscriber) {
|
|
124
|
+
if (this.#disposed)
|
|
125
|
+
return () => undefined;
|
|
126
|
+
this.#effectSubscribers.add(subscriber);
|
|
127
|
+
return () => void this.#effectSubscribers.delete(subscriber);
|
|
128
|
+
}
|
|
129
|
+
snapshot() {
|
|
130
|
+
return this.#latest ? { ...this.#latest, vars: { ...this.#latest.vars } } : null;
|
|
131
|
+
}
|
|
132
|
+
dispose() {
|
|
133
|
+
if (this.#disposed)
|
|
134
|
+
return;
|
|
135
|
+
this.#disposed = true;
|
|
136
|
+
for (const unsubscribe of this.#roomUnsubscribers.splice(0))
|
|
137
|
+
unsubscribe();
|
|
138
|
+
this.#stateSubscribers.clear();
|
|
139
|
+
this.#effectSubscribers.clear();
|
|
140
|
+
this.#seenEffects.clear();
|
|
141
|
+
this.#latest = null;
|
|
142
|
+
}
|
|
143
|
+
#capture() {
|
|
144
|
+
const vars = {};
|
|
145
|
+
const view = this.#room.module(this.#binding.moduleId).vars;
|
|
146
|
+
for (const name of this.#binding.stateVars)
|
|
147
|
+
vars[name] = view.raw(name);
|
|
148
|
+
const fingerprint = JSON.stringify(vars);
|
|
149
|
+
if (fingerprint === this.#fingerprint && this.#latest)
|
|
150
|
+
return;
|
|
151
|
+
this.#fingerprint = fingerprint;
|
|
152
|
+
this.#latest = {
|
|
153
|
+
...(this.#binding.itemInstanceId ? { itemInstanceId: this.#binding.itemInstanceId } : {}),
|
|
154
|
+
moduleId: this.#binding.moduleId,
|
|
155
|
+
bundleChecksumSha256: this.#binding.bundleChecksumSha256,
|
|
156
|
+
revision: ++this.#revision,
|
|
157
|
+
serverTick: this.#room.state.serverTick,
|
|
158
|
+
vars,
|
|
159
|
+
};
|
|
160
|
+
for (const subscriber of this.#stateSubscribers)
|
|
161
|
+
subscriber(this.#latest, { initial: false });
|
|
162
|
+
}
|
|
163
|
+
#effect(value) {
|
|
164
|
+
if (!isRecord(value) || value.moduleId !== this.#binding.moduleId)
|
|
165
|
+
return;
|
|
166
|
+
if (typeof value.commandId !== 'string' || !Number.isSafeInteger(value.index) ||
|
|
167
|
+
typeof value.serverTick !== 'number' || typeof value.event !== 'string' || !isRecord(value.payload))
|
|
168
|
+
return;
|
|
169
|
+
const key = `${value.commandId}:${value.index}`;
|
|
170
|
+
if (this.#seenEffects.has(key))
|
|
171
|
+
return;
|
|
172
|
+
if (this.#seenEffects.size >= MAX_SEEN_EFFECTS) {
|
|
173
|
+
const oldest = this.#seenEffects.values().next().value;
|
|
174
|
+
if (oldest !== undefined)
|
|
175
|
+
this.#seenEffects.delete(oldest);
|
|
176
|
+
}
|
|
177
|
+
this.#seenEffects.add(key);
|
|
178
|
+
const effect = value;
|
|
179
|
+
for (const subscriber of this.#effectSubscribers)
|
|
180
|
+
subscriber(effect);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=vehicle-specialty-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vehicle-specialty-transport.js","sourceRoot":"","sources":["../src/vehicle-specialty-transport.ts"],"names":[],"mappings":"AAsDA,MAAM,gBAAgB,GAAG,GAAG,CAAC;AAC7B,MAAM,wBAAwB,GAAG,iCAAiC,CAAC;AAEnE,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAOD;;;;GAIG;AACH,MAAM,OAAO,6BAA6B;IAC/B,KAAK,CAAuB;IAC5B,QAAQ,CAA8B;IACtC,gBAAgB,CAAoB;IACpC,iBAAiB,GAAG,IAAI,GAAG,EAAmB,CAAC;IAC/C,kBAAkB,GAAG,IAAI,GAAG,EAAoB,CAAC;IACjD,YAAY,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,kBAAkB,GAAsB,EAAE,CAAC;IACpD,SAAS,GAAG,CAAC,CAAC;IACd,YAAY,GAAG,EAAE,CAAC;IAClB,OAAO,GAAyC,IAAI,CAAC;IACrD,SAAS,GAAG,KAAK,CAAC;IAElB,YACE,IAA0B,EAC1B,OAAoC;QAEpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,QAAQ,GAAG;YACd,GAAG,OAAO;YACV,SAAS,EAAE,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;YACjC,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AC1E,IACE,OAAO,KAAK,CAAC,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC;YACzE,OAAO,KAAK,CAAC,UAAU,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC;YACnG,OAAO;QACT,MAAM,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChD,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO;QACvC,IAAI,IAAI,CAAC,YAAY,CAAC,IAAI,IAAI,gBAAgB,EAAE,CAAC;YAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAA2B,CAAC;YAC7E,IAAI,MAAM,KAAK,SAAS;gBAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,KAAsD,CAAC;QACtE,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,kBAAkB;YAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACvE,CAAC;CACF"}
|
package/dist/voice.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { HelixVoiceMicMode, HelixVoiceSettings, HelixVoiceState } from './protocol.js';
|
|
2
|
+
export interface VoiceHost {
|
|
3
|
+
isInitialized(): boolean;
|
|
4
|
+
getToken(): string | null;
|
|
5
|
+
getWorldId(): string | null;
|
|
6
|
+
/** The joined Colyseus room instance id (multiplayer.currentRoomId()) — null before joinRoom. */
|
|
7
|
+
getRoomId(): string | null;
|
|
8
|
+
/** API-base resolution shared with the multiplayer module (configure() pin, else the token's iss). */
|
|
9
|
+
resolveApiBase(token: string | null): string | null;
|
|
10
|
+
/** Shell publish hook (helix:voice-state): every real change, null on leave/teardown. */
|
|
11
|
+
publishVoiceState?(state: HelixVoiceState | null): void;
|
|
12
|
+
/** Shell publish hook (helix:voice-level): live mic meter, ~10 Hz while captured, 0 on release. */
|
|
13
|
+
publishVoiceLevel?(level: number): void;
|
|
14
|
+
}
|
|
15
|
+
export interface JoinVoiceOptions {
|
|
16
|
+
/** Override the paired Colyseus room id. Default: the currently joined multiplayer room. */
|
|
17
|
+
roomId?: string;
|
|
18
|
+
/** Override the platform API base URL (same semantics as JoinRoomOptions.apiBaseUrl). */
|
|
19
|
+
apiBaseUrl?: string;
|
|
20
|
+
/** Same-origin reservation adapter route for a non-World runtime. */
|
|
21
|
+
tokenPath?: string;
|
|
22
|
+
/** Push-to-talk key (KeyboardEvent.key, compared lowercase). Default 'n', matching FiveM's
|
|
23
|
+
* standard push-to-talk control while B remains available for character pointing. */
|
|
24
|
+
pttKey?: string;
|
|
25
|
+
/** Initial exclusive voice channel (equivalent to calling setChannel before join). */
|
|
26
|
+
channel?: string;
|
|
27
|
+
}
|
|
28
|
+
/** A world-space position/direction for spatial voice (three.js and WebAudio share right-handed axes). */
|
|
29
|
+
export type HelixVoiceVec3 = {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
z: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Fixed-size, receiver-local speech features. These are derived from a subscribed playback track,
|
|
36
|
+
* never serialized, and intentionally contain no recoverable PCM or arbitrary channel data.
|
|
37
|
+
*/
|
|
38
|
+
export interface HelixVoiceAudioFeatures {
|
|
39
|
+
/** Root-mean-square energy, normalized to 0..1. */
|
|
40
|
+
rms: number;
|
|
41
|
+
/** Time-domain zero-crossing rate, normalized to 0..1. */
|
|
42
|
+
zeroCrossingRate: number;
|
|
43
|
+
/** Mean spectral energy in fixed speech bands: <350, 350-700, 700-1400, 1400-2800, 2800-5600 Hz. */
|
|
44
|
+
bands: readonly [number, number, number, number, number];
|
|
45
|
+
}
|
|
46
|
+
/** Platform default for KeyboardEvent.key while push-to-talk is active. */
|
|
47
|
+
export declare const DEFAULT_PUSH_TO_TALK_KEY = "n";
|
|
48
|
+
export declare class HelixVoice {
|
|
49
|
+
private readonly host;
|
|
50
|
+
private room;
|
|
51
|
+
private events;
|
|
52
|
+
private connected;
|
|
53
|
+
private micMode;
|
|
54
|
+
private captured;
|
|
55
|
+
private capturePromise;
|
|
56
|
+
private permission;
|
|
57
|
+
private requestedDeviceId;
|
|
58
|
+
private requestedDeviceLabel;
|
|
59
|
+
private activeDeviceId;
|
|
60
|
+
private audioCtx;
|
|
61
|
+
private micStream;
|
|
62
|
+
private micSource;
|
|
63
|
+
private volumeGain;
|
|
64
|
+
private compressor;
|
|
65
|
+
private analyser;
|
|
66
|
+
private analyserBuf;
|
|
67
|
+
private analyserSpectrum;
|
|
68
|
+
private gateGain;
|
|
69
|
+
private muteGain;
|
|
70
|
+
private levelTimer;
|
|
71
|
+
private levelTick;
|
|
72
|
+
private micLevel;
|
|
73
|
+
private gateOpenUntil;
|
|
74
|
+
private micVolume;
|
|
75
|
+
private autoSensitivity;
|
|
76
|
+
private sensitivity;
|
|
77
|
+
private outputVolume;
|
|
78
|
+
private participantBase;
|
|
79
|
+
private channelId;
|
|
80
|
+
private pairing;
|
|
81
|
+
private pendingJoin;
|
|
82
|
+
private joinSeq;
|
|
83
|
+
private mixCtx;
|
|
84
|
+
private spatialTracks;
|
|
85
|
+
private panners;
|
|
86
|
+
private remoteAnalysers;
|
|
87
|
+
private remoteLevelListeners;
|
|
88
|
+
private remoteFeatureListeners;
|
|
89
|
+
private localLevelListeners;
|
|
90
|
+
private localFeatureListeners;
|
|
91
|
+
private localWasAudible;
|
|
92
|
+
private remoteLevelTimer;
|
|
93
|
+
private positions;
|
|
94
|
+
private listenerPose;
|
|
95
|
+
private devices;
|
|
96
|
+
private muted;
|
|
97
|
+
private speaking;
|
|
98
|
+
private audioBlocked;
|
|
99
|
+
private error;
|
|
100
|
+
private available;
|
|
101
|
+
private pttKey;
|
|
102
|
+
private pttHeld;
|
|
103
|
+
private stateSig;
|
|
104
|
+
private audioRoot;
|
|
105
|
+
private unlockInstalled;
|
|
106
|
+
private speakingListeners;
|
|
107
|
+
private participantListeners;
|
|
108
|
+
constructor(host: VoiceHost);
|
|
109
|
+
join(options?: JoinVoiceOptions): Promise<boolean>;
|
|
110
|
+
private connectVoice;
|
|
111
|
+
leave(): Promise<void>;
|
|
112
|
+
detachForRoomSwitch(): Promise<(() => Promise<boolean>) | null>;
|
|
113
|
+
/** The shell-owned settings push (helix:voice-settings) — also callable directly by a world. */
|
|
114
|
+
applySettings(settings: HelixVoiceSettings): Promise<void>;
|
|
115
|
+
/** Outgoing mic gain (0..2, Discord-style 0–200%). Applies live when captured. */
|
|
116
|
+
setMicVolume(volume: number): void;
|
|
117
|
+
/** Incoming voice master gain (0..2, Discord-style 0–200%). Reapplies to every participant live. */
|
|
118
|
+
setOutputVolume(volume: number): void;
|
|
119
|
+
setMicMode(mode: HelixVoiceMicMode): Promise<void>;
|
|
120
|
+
getMicMode(): HelixVoiceMicMode;
|
|
121
|
+
setPttDown(down: boolean): void;
|
|
122
|
+
private captureForPtt;
|
|
123
|
+
setDevice(deviceId: string, label?: string): Promise<void>;
|
|
124
|
+
private swapSource;
|
|
125
|
+
private reconcileDeviceLabel;
|
|
126
|
+
setChannel(channelId: string | null): Promise<void>;
|
|
127
|
+
/** The local player's current exclusive voice channel (null = the ambient space). */
|
|
128
|
+
channel(): string | null;
|
|
129
|
+
/** The channel a remote participant is in (null = ambient; engine render policy reads this). */
|
|
130
|
+
channelOf(userId: string): string | null;
|
|
131
|
+
setPlayerMuted(userId: string, muted: boolean): void;
|
|
132
|
+
mutedUserIds(): string[];
|
|
133
|
+
/** Playback gain for one remote player (engine proximity hook; 0 = silent, 1 = as-sent). */
|
|
134
|
+
setParticipantVolume(userId: string, volume: number): void;
|
|
135
|
+
/**
|
|
136
|
+
* Spatialize one remote player's voice: heard from `position` (world coords) relative to the listener
|
|
137
|
+
* pose. Direction ONLY — loudness still flows through setParticipantVolume × outputVolume. null returns
|
|
138
|
+
* them to center-panned render (the engine passes null for channel — radio/phone — voices). Engine
|
|
139
|
+
* proximity hook, called per-frame; silently no-ops where the client audio hook is unavailable.
|
|
140
|
+
*/
|
|
141
|
+
setParticipantPosition(userId: string, position: HelixVoiceVec3 | null): void;
|
|
142
|
+
/** The listener (camera) pose driving spatial voice. Engine hook, called per-frame. */
|
|
143
|
+
setListenerPose(position: HelixVoiceVec3, forward: HelixVoiceVec3, up?: HelixVoiceVec3): void;
|
|
144
|
+
/** Connected remote voice participants (platform userIds). */
|
|
145
|
+
participantIds(): string[];
|
|
146
|
+
/** Currently speaking userIds (muted-by-me players never appear). Fires on every change. */
|
|
147
|
+
onSpeakingChanged(cb: (userIds: string[]) => void): () => void;
|
|
148
|
+
/** Remote participant set changes (join/leave). Fires with the current userId list. */
|
|
149
|
+
onParticipantsChanged(cb: (userIds: string[]) => void): () => void;
|
|
150
|
+
/**
|
|
151
|
+
* Receiver-local audio energy for presentation such as avatar jaw motion. The callback receives
|
|
152
|
+
* platform userId plus a clamped 0..1 RMS value at at most about 30 Hz. It is intentionally not exposed
|
|
153
|
+
* to the shell protocol or any network transport. Analysis exists only while at least one listener
|
|
154
|
+
* is registered and degrades to silence when LiveKit's WebAudio plugin hook is unavailable.
|
|
155
|
+
*/
|
|
156
|
+
onParticipantAudioLevel(cb: (userId: string, level: number) => void): () => void;
|
|
157
|
+
/**
|
|
158
|
+
* Receiver-local, bounded speech features for replaceable lip-sync solvers. Analysis runs at at
|
|
159
|
+
* most about 30 Hz for at most 32 audible tracks. The five fixed bands and two scalars are ephemeral;
|
|
160
|
+
* raw samples are neither exposed nor retained after each tick.
|
|
161
|
+
*/
|
|
162
|
+
onParticipantAudioFeatures(cb: (userId: string, features: HelixVoiceAudioFeatures) => void): () => void;
|
|
163
|
+
/**
|
|
164
|
+
* The LOCAL speaker's own audio energy, for driving their own avatar's mouth. Nobody plays their
|
|
165
|
+
* own voice back, so `onParticipantAudioLevel` structurally cannot cover this seat.
|
|
166
|
+
*
|
|
167
|
+
* Sampled off the microphone analyser that already drives the meter and the sensitivity gate — no
|
|
168
|
+
* second analyser, no extra timer — and reported only while the room can actually hear you, so a
|
|
169
|
+
* muted or un-held mic leaves the mouth closed. Never networked; nothing is retained.
|
|
170
|
+
*/
|
|
171
|
+
onLocalAudioLevel(cb: (level: number) => void): () => void;
|
|
172
|
+
/**
|
|
173
|
+
* The local speaker's own speech features, in the same fixed shape and units as the receiver-local
|
|
174
|
+
* ones, so one solver serves both seats. Preferred over `onLocalAudioLevel` when consumed.
|
|
175
|
+
*/
|
|
176
|
+
onLocalAudioFeatures(cb: (features: HelixVoiceAudioFeatures) => void): () => void;
|
|
177
|
+
startAudio(): Promise<void>;
|
|
178
|
+
private requestVoiceToken;
|
|
179
|
+
private wireRoomEvents;
|
|
180
|
+
private ensureMic;
|
|
181
|
+
private captureMic;
|
|
182
|
+
private setMicEnabled;
|
|
183
|
+
private shouldTransmit;
|
|
184
|
+
private startLevelLoop;
|
|
185
|
+
/**
|
|
186
|
+
* The local speaker's own face signal, off the same analyser the meter and the gate already use.
|
|
187
|
+
*
|
|
188
|
+
* Gated on what the room can actually HEAR — the publish mute (mode/PTT) times the sensitivity gate
|
|
189
|
+
* — so a muted or un-held microphone leaves the avatar's mouth closed instead of mouthing silently
|
|
190
|
+
* at everyone. The transition to inaudible emits one explicit silent frame and then stops, so a
|
|
191
|
+
* consumer settles at rest rather than freezing on the last syllable.
|
|
192
|
+
*/
|
|
193
|
+
private emitLocalAudio;
|
|
194
|
+
private emitLocalSilence;
|
|
195
|
+
private applyGate;
|
|
196
|
+
private applyMicMode;
|
|
197
|
+
private sameChannel;
|
|
198
|
+
private participantAudible;
|
|
199
|
+
private applyAudibility;
|
|
200
|
+
private applyVolumes;
|
|
201
|
+
private findParticipant;
|
|
202
|
+
private ensurePanner;
|
|
203
|
+
private applyTrackPlugins;
|
|
204
|
+
private ensureRemoteAnalyser;
|
|
205
|
+
private installRemoteAnalysers;
|
|
206
|
+
private startRemoteLevelLoop;
|
|
207
|
+
private emitRemoteLevel;
|
|
208
|
+
private emitRemoteFeatures;
|
|
209
|
+
private stopRemoteLevelAnalysis;
|
|
210
|
+
private applyParticipantPosition;
|
|
211
|
+
private applyListenerPose;
|
|
212
|
+
private refreshDevices;
|
|
213
|
+
private attachInputListeners;
|
|
214
|
+
private detachInputListeners;
|
|
215
|
+
private onKeyDown;
|
|
216
|
+
private onKeyUp;
|
|
217
|
+
private releasePtt;
|
|
218
|
+
private onVisibility;
|
|
219
|
+
private ensureAudioRoot;
|
|
220
|
+
private installUnlock;
|
|
221
|
+
private micSuspended;
|
|
222
|
+
private resumeAudio;
|
|
223
|
+
private kickContext;
|
|
224
|
+
private visibleSpeaking;
|
|
225
|
+
private emitSpeaking;
|
|
226
|
+
private emitParticipants;
|
|
227
|
+
private publishState;
|
|
228
|
+
private teardown;
|
|
229
|
+
}
|