Skip to content

Commit a4d6015

Browse files
prettyer fixes (#214)
1 parent 172f95f commit a4d6015

File tree

8 files changed

+56
-27
lines changed

8 files changed

+56
-27
lines changed

packages/data-sdk/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [1.80.0] - 2025-05-22
2+
3+
- Fix Asset loading
4+
15
## [1.79.0] - 2025-05-09
26

37
- Command fixes

packages/data-sdk/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/data-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@formant/data-sdk",
3-
"version": "1.79.0",
3+
"version": "1.80.0",
44
"description": "A library for getting data from Formant",
55
"repository": {
66
"type": "git",

packages/data-sdk/src/AudioPlayer.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class AudioPlayer {
4646
}
4747

4848
const AudioContext =
49+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4950
window.AudioContext || (window as any).webkitAudioContext;
5051

5152
this.audioContext = new AudioContext();
@@ -76,7 +77,7 @@ export class AudioPlayer {
7677
const arrayBuffer = stringToArrayBuffer(data);
7778
try {
7879
await audioContext.decodeAudioData(
79-
arrayBuffer.buffer,
80+
toArrayBuffer(arrayBuffer.buffer),
8081
this.scheduleChunk
8182
);
8283
} catch (error) {
@@ -127,6 +128,7 @@ export class AudioPlayer {
127128
source.buffer = buffer;
128129
source.connect(audioContext.destination);
129130
source.loop = false;
131+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
130132
source.onended = (_: Event) => {
131133
this.chunks.splice(this.chunks.indexOf(source), 1);
132134
if (this.chunks.length === 0) {
@@ -146,3 +148,27 @@ export class AudioPlayer {
146148
);
147149
}
148150
}
151+
152+
function toArrayBuffer(data: ArrayBufferLike): ArrayBuffer {
153+
// (1) If it’s already an ArrayBuffer, just return it.
154+
if (data instanceof ArrayBuffer) {
155+
return data;
156+
}
157+
158+
// (2) If it’s a TypedArray or DataView, pull out the exact bytes.
159+
if (ArrayBuffer.isView(data)) {
160+
const view = data as ArrayBufferView;
161+
const buffer = view.buffer.slice(
162+
view.byteOffset,
163+
view.byteOffset + view.byteLength
164+
);
165+
if (buffer instanceof SharedArrayBuffer) {
166+
return new Uint8Array(data as SharedArrayBuffer).slice().buffer;
167+
}
168+
return buffer;
169+
}
170+
171+
// (3) Otherwise it must be a SharedArrayBuffer — copy it into a new ArrayBuffer.
172+
// We do this by wrapping in a Uint8Array and slicing.
173+
return new Uint8Array(data as SharedArrayBuffer).slice().buffer;
174+
}

packages/data-sdk/src/connector/common/LruCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class LruCache<K, V> {
1010
private cache!: BaseLruCache<string, V>;
1111
private stringify: (_: K) => string;
1212

13-
constructor(private options: CacheOptions<V>) {
13+
constructor(options: CacheOptions<V>) {
1414
this.cache = new BaseLruCache<string, V>({
1515
// if using the dispose callback,
1616
// by default automatically prune expired entries so

packages/data-sdk/src/connector/common/toStringSafe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ import stringify from "fast-json-stable-stringify";
88
* Warning: output is not guaranteed to be a valid JSON string.
99
*/
1010
export function toStringSafe(input: unknown): string {
11-
return stringify(input, { cycles: true });
11+
return stringify(input, { cycles: true });
1212
}
Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
import { errorToString } from "../../common/errorToString";
22

3-
43
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54
const context: Worker = self as any;
65
const previewLength = 1000;
76

8-
addEventListener("message", async event => {
9-
try {
10-
const url: string = event.data;
7+
addEventListener("message", async (event) => {
8+
try {
9+
const url: string = event.data;
1110

12-
try {
13-
const response = await fetch(url, { mode: "cors" });
14-
const payload = await response.text();
11+
try {
12+
const response = await fetch(url, { mode: "cors" });
13+
const payload = await response.text();
1514

16-
context.postMessage({
17-
json: JSON.parse(payload),
18-
preview: payload.substring(0, previewLength),
19-
length: payload.length,
20-
url,
21-
});
22-
} catch (error) {
23-
throw new Error(`Load failed ${errorToString(error)}`);
24-
}
15+
context.postMessage({
16+
json: JSON.parse(payload),
17+
preview: payload.substring(0, previewLength),
18+
length: payload.length,
19+
url,
20+
});
2521
} catch (error) {
26-
context.postMessage({
27-
error: errorToString(error),
28-
url: event?.data?.url,
29-
});
22+
throw new Error(`Load failed ${errorToString(error)}`);
3023
}
24+
} catch (error) {
25+
context.postMessage({
26+
error: errorToString(error),
27+
url: event?.data?.url,
28+
});
29+
}
3130
});

packages/data-sdk/src/model/IPath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { ITransform } from "./ITransform";
33
export interface IPath {
44
worldToLocal: ITransform;
55
poses: ITransform[];
6-
url?: string
6+
url?: string;
77
}

0 commit comments

Comments
 (0)