@playabl/sdk 0.1.0 → 0.2.0

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/dist/index.d.ts CHANGED
@@ -79,6 +79,11 @@ interface CameraOptions {
79
79
  }
80
80
  interface CameraResult {
81
81
  blob: Blob;
82
+ /**
83
+ * @deprecated Prefer `URL.createObjectURL(blob)` for playback/display. The
84
+ * Base64 data URL is ~33% larger than the blob and is kept only for
85
+ * backward compatibility; it may be removed in a future major runtime version.
86
+ */
82
87
  dataUrl: string;
83
88
  width: number;
84
89
  height: number;
@@ -89,6 +94,27 @@ interface CameraAPI {
89
94
  capturePhoto(options?: CameraOptions): Promise<CameraResult>;
90
95
  stopStream(): void;
91
96
  }
97
+ interface MicrophoneStreamOptions {
98
+ echoCancellation?: boolean;
99
+ noiseSuppression?: boolean;
100
+ autoGainControl?: boolean;
101
+ }
102
+ interface MicrophoneRecordOptions {
103
+ mimeType?: string;
104
+ audioBitsPerSecond?: number;
105
+ }
106
+ interface MicrophoneResult {
107
+ blob: Blob;
108
+ duration: number;
109
+ mimeType: string;
110
+ }
111
+ interface MicrophoneAPI {
112
+ isSupported(): boolean;
113
+ getStream(options?: MicrophoneStreamOptions): Promise<MediaStream>;
114
+ startRecording(options?: MicrophoneRecordOptions): void;
115
+ stopRecording(): Promise<MicrophoneResult>;
116
+ stopStream(): void;
117
+ }
92
118
  interface GeolocationOptions {
93
119
  enableHighAccuracy?: boolean;
94
120
  timeout?: number;
@@ -179,6 +205,7 @@ interface HapticsAPI {
179
205
  interface PlayablDevice {
180
206
  haptics: HapticsAPI;
181
207
  camera: CameraAPI;
208
+ microphone: MicrophoneAPI;
182
209
  geolocation: GeolocationAPI;
183
210
  fileSystem: FileSystemAPI;
184
211
  sensors: SensorsAPI;
@@ -246,8 +273,14 @@ declare class PlayablError extends Error {
246
273
  constructor(code: ErrorCode, message?: string, cause?: unknown);
247
274
  }
248
275
  type RuntimeLoader = () => Promise<PlayablSDK>;
276
+ /**
277
+ * Override runtime resolution. `runtimeUrl` imports a specific runtime build
278
+ * directly; `manifestUrl` points at a specific manifest. Both bypass the
279
+ * automatic environment detection — useful for QA or self-hosting.
280
+ */
249
281
  declare function configure(options: {
250
282
  runtimeUrl?: string;
283
+ manifestUrl?: string;
251
284
  }): void;
252
285
  declare const sdk: PlayablSDK;
253
286
 
@@ -256,4 +289,4 @@ declare const __testing: {
256
289
  setRuntimeLoader(loader: RuntimeLoader): void;
257
290
  };
258
291
 
259
- export { type AssetDescriptor, type AssetOverride, type AssetStatus, type AssetType, type AssetsMapping, type BooleanTweak, type CameraAPI, type CameraOptions, type CameraResult, type ColorTweak, type ErrorCode, type FileSystemAPI, type FileSystemOptions, type FileSystemResult, type GeolocationAPI, type GeolocationOptions, type GeolocationResult, type HapticsAPI, type MotionAttitude, type MotionData, type MotionRotation, type MotionVector, type NumberTweak, type OrientationData, type PlayablAssets, type PlayablAudio, type PlayablAudioAutoPauseOptions, type PlayablAudioContext, type PlayablAudioOptions, type PlayablDevice, PlayablError, type PlayablSDK, type PlayablTweaks, type ReadyResult, type SaveResult, type SensorsAPI, type SubmitResult, type TextTweak, type TweakSchema, type TweakSchemaItem, type TweakType, type TweakValue, __testing, configure, sdk as default };
292
+ export { type AssetDescriptor, type AssetOverride, type AssetStatus, type AssetType, type AssetsMapping, type BooleanTweak, type CameraAPI, type CameraOptions, type CameraResult, type ColorTweak, type ErrorCode, type FileSystemAPI, type FileSystemOptions, type FileSystemResult, type GeolocationAPI, type GeolocationOptions, type GeolocationResult, type HapticsAPI, type MicrophoneAPI, type MicrophoneRecordOptions, type MicrophoneResult, type MicrophoneStreamOptions, type MotionAttitude, type MotionData, type MotionRotation, type MotionVector, type NumberTweak, type OrientationData, type PlayablAssets, type PlayablAudio, type PlayablAudioAutoPauseOptions, type PlayablAudioContext, type PlayablAudioOptions, type PlayablDevice, PlayablError, type PlayablSDK, type PlayablTweaks, type ReadyResult, type SaveResult, type SensorsAPI, type SubmitResult, type TextTweak, type TweakSchema, type TweakSchemaItem, type TweakType, type TweakValue, __testing, configure, sdk as default };
package/dist/index.js CHANGED
@@ -1,3 +1,42 @@
1
+ // src/runtime-loader.ts
2
+ var LOG_PREFIX = "[playabl/sdk]";
3
+ var BASE_DOMAIN = "playabl.ai";
4
+ var MANIFEST_PATH = "/Runtime-Script/sdk/v1/version.json";
5
+ var ENV_HOST_RE = /\.(dev|staging)\.playabl\.ai$/;
6
+ var FALLBACK_RUNTIME_URL = "https://cdn.playabl.ai/Runtime-Script/sdk/v1/runtime.js";
7
+ function isEnv(value) {
8
+ return value === "local" || value === "dev" || value === "staging" || value === "prod";
9
+ }
10
+ function detectEnv(hostname = typeof window !== "undefined" ? window.location.hostname : "", search = typeof window !== "undefined" ? window.location.search : "") {
11
+ const forced = new URLSearchParams(search).get("env");
12
+ if (isEnv(forced)) return forced;
13
+ if (hostname === "localhost" || hostname === "127.0.0.1") return "local";
14
+ const match = hostname.match(ENV_HOST_RE);
15
+ return match ? match[1] : "prod";
16
+ }
17
+ function manifestUrlForEnv(env) {
18
+ const cdnHost = env === "prod" ? "cdn" : `cdn-${env}`;
19
+ return `https://${cdnHost}.${BASE_DOMAIN}${MANIFEST_PATH}`;
20
+ }
21
+ async function resolveRuntimeUrl(options = {}) {
22
+ if (options.runtimeUrl) return options.runtimeUrl;
23
+ const env = detectEnv();
24
+ if (!options.manifestUrl && env === "local") return FALLBACK_RUNTIME_URL;
25
+ const manifestUrl = options.manifestUrl ?? manifestUrlForEnv(env);
26
+ try {
27
+ const response = await fetch(manifestUrl, { cache: "no-store" });
28
+ if (!response.ok) throw new Error(`manifest HTTP ${response.status}`);
29
+ const manifest = await response.json();
30
+ if (typeof manifest.runtimeUrl !== "string" || !manifest.runtimeUrl) {
31
+ throw new Error("manifest missing runtimeUrl");
32
+ }
33
+ return manifest.runtimeUrl;
34
+ } catch (error) {
35
+ console.warn(`${LOG_PREFIX} runtime manifest unavailable; using fallback runtime URL`, error);
36
+ return FALLBACK_RUNTIME_URL;
37
+ }
38
+ }
39
+
1
40
  // src/index.ts
2
41
  var PlayablError = class extends Error {
3
42
  code;
@@ -9,17 +48,33 @@ var PlayablError = class extends Error {
9
48
  this.cause = cause;
10
49
  }
11
50
  };
12
- var defaultLoader = () => import(
13
- /* @vite-ignore */
14
- runtimeUrl
15
- ).then((mod) => mod.default);
16
- var runtimeUrl = "https://cdn.playabl.ai/Runtime-Script/sdk/v1/runtime.js";
17
- var runtimeLoader = defaultLoader;
51
+ var explicitRuntimeUrl;
52
+ var explicitManifestUrl;
18
53
  var sdkPromise;
19
54
  var loadedSDK;
55
+ var defaultLoader = async () => {
56
+ const url = await resolveRuntimeUrl({
57
+ runtimeUrl: explicitRuntimeUrl,
58
+ manifestUrl: explicitManifestUrl
59
+ });
60
+ const mod = await import(
61
+ /* @vite-ignore */
62
+ url
63
+ );
64
+ return mod.default;
65
+ };
66
+ var runtimeLoader = defaultLoader;
20
67
  function configure(options) {
21
- if (options.runtimeUrl && options.runtimeUrl !== runtimeUrl) {
22
- runtimeUrl = options.runtimeUrl;
68
+ let changed = false;
69
+ if (options.runtimeUrl !== void 0 && options.runtimeUrl !== explicitRuntimeUrl) {
70
+ explicitRuntimeUrl = options.runtimeUrl;
71
+ changed = true;
72
+ }
73
+ if (options.manifestUrl !== void 0 && options.manifestUrl !== explicitManifestUrl) {
74
+ explicitManifestUrl = options.manifestUrl;
75
+ changed = true;
76
+ }
77
+ if (changed) {
23
78
  sdkPromise = void 0;
24
79
  loadedSDK = void 0;
25
80
  }
@@ -83,6 +138,25 @@ var sdk = {
83
138
  if (runtime) runtime.device.camera.stopStream();
84
139
  }
85
140
  },
141
+ microphone: {
142
+ isSupported: () => {
143
+ const runtime = peekSDK();
144
+ return runtime ? runtime.device.microphone.isSupported() : false;
145
+ },
146
+ getStream: async (options) => (await getSDK()).device.microphone.getStream(options),
147
+ startRecording: (options) => {
148
+ const runtime = peekSDK();
149
+ if (!runtime) {
150
+ throw new Error("Playabl runtime not ready; call sdk.ready() before startRecording()");
151
+ }
152
+ runtime.device.microphone.startRecording(options);
153
+ },
154
+ stopRecording: async () => (await getSDK()).device.microphone.stopRecording(),
155
+ stopStream: () => {
156
+ const runtime = peekSDK();
157
+ if (runtime) runtime.device.microphone.stopStream();
158
+ }
159
+ },
86
160
  geolocation: {
87
161
  isSupported: () => {
88
162
  const runtime = peekSDK();
@@ -166,7 +240,8 @@ var __testing = {
166
240
  resetRuntimeLoader() {
167
241
  sdkPromise = void 0;
168
242
  loadedSDK = void 0;
169
- runtimeUrl = "https://cdn.playabl.ai/Runtime-Script/sdk/v1/runtime.js";
243
+ explicitRuntimeUrl = void 0;
244
+ explicitManifestUrl = void 0;
170
245
  runtimeLoader = defaultLoader;
171
246
  },
172
247
  setRuntimeLoader(loader) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playabl/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",