r1-create 1.0.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.
@@ -0,0 +1,396 @@
1
+ "use strict";
2
+ /**
3
+ * Media API module for R1 device
4
+ * Provides access to camera, microphone, and speaker using standard web APIs
5
+ * Optimized for R1 hardware limitations and mobile performance
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.speaker = exports.microphone = exports.camera = exports.MediaUtils = exports.SpeakerAPI = exports.MicrophoneAPI = exports.CameraAPI = void 0;
9
+ /**
10
+ * Camera API for R1 device
11
+ */
12
+ class CameraAPI {
13
+ constructor() {
14
+ this.stream = null;
15
+ this.videoElement = null;
16
+ }
17
+ /**
18
+ * Check if camera is available
19
+ */
20
+ async isAvailable() {
21
+ try {
22
+ const devices = await navigator.mediaDevices.enumerateDevices();
23
+ return devices.some(device => device.kind === 'videoinput');
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ }
29
+ /**
30
+ * Start camera stream
31
+ * @param config Video configuration
32
+ */
33
+ async start(config = {}) {
34
+ try {
35
+ const constraints = {
36
+ video: {
37
+ width: config.width || 240,
38
+ height: config.height || 282,
39
+ frameRate: config.frameRate || 30,
40
+ facingMode: config.facingMode || 'user'
41
+ },
42
+ audio: false
43
+ };
44
+ this.stream = await navigator.mediaDevices.getUserMedia(constraints);
45
+ return this.stream;
46
+ }
47
+ catch (error) {
48
+ throw new Error(`Failed to start camera: ${error}`);
49
+ }
50
+ }
51
+ /**
52
+ * Stop camera stream
53
+ */
54
+ stop() {
55
+ if (this.stream) {
56
+ this.stream.getTracks().forEach(track => track.stop());
57
+ this.stream = null;
58
+ }
59
+ if (this.videoElement) {
60
+ this.videoElement.srcObject = null;
61
+ }
62
+ }
63
+ /**
64
+ * Get camera stream
65
+ */
66
+ getStream() {
67
+ return this.stream;
68
+ }
69
+ /**
70
+ * Create video element with stream
71
+ * @param autoplay Whether to autoplay video
72
+ * @param muted Whether to mute video
73
+ */
74
+ createVideoElement(autoplay = true, muted = true) {
75
+ if (!this.stream) {
76
+ throw new Error('Camera stream not started');
77
+ }
78
+ this.videoElement = document.createElement('video');
79
+ this.videoElement.srcObject = this.stream;
80
+ this.videoElement.autoplay = autoplay;
81
+ this.videoElement.muted = muted;
82
+ this.videoElement.playsInline = true;
83
+ // Optimize for R1 display
84
+ this.videoElement.style.width = '100%';
85
+ this.videoElement.style.height = '100%';
86
+ this.videoElement.style.objectFit = 'cover';
87
+ return this.videoElement;
88
+ }
89
+ /**
90
+ * Capture photo from camera stream
91
+ * @param width Image width (default: 240)
92
+ * @param height Image height (default: 282)
93
+ */
94
+ capturePhoto(width = 240, height = 282) {
95
+ if (!this.videoElement || !this.stream) {
96
+ throw new Error('Camera not started');
97
+ }
98
+ const canvas = document.createElement('canvas');
99
+ canvas.width = width;
100
+ canvas.height = height;
101
+ const context = canvas.getContext('2d');
102
+ if (!context)
103
+ return null;
104
+ context.drawImage(this.videoElement, 0, 0, width, height);
105
+ return canvas.toDataURL('image/jpeg', 0.8);
106
+ }
107
+ /**
108
+ * Switch camera (front/back)
109
+ */
110
+ async switchCamera() {
111
+ if (!this.stream) {
112
+ throw new Error('Camera not started');
113
+ }
114
+ const videoTrack = this.stream.getVideoTracks()[0];
115
+ const currentFacingMode = videoTrack.getSettings().facingMode;
116
+ const newFacingMode = currentFacingMode === 'user' ? 'environment' : 'user';
117
+ this.stop();
118
+ await this.start({ facingMode: newFacingMode });
119
+ }
120
+ }
121
+ exports.CameraAPI = CameraAPI;
122
+ /**
123
+ * Microphone API for R1 device
124
+ */
125
+ class MicrophoneAPI {
126
+ constructor() {
127
+ this.stream = null;
128
+ this.mediaRecorder = null;
129
+ this.recordedChunks = [];
130
+ }
131
+ /**
132
+ * Check if microphone is available
133
+ */
134
+ async isAvailable() {
135
+ try {
136
+ const devices = await navigator.mediaDevices.enumerateDevices();
137
+ return devices.some(device => device.kind === 'audioinput');
138
+ }
139
+ catch {
140
+ return false;
141
+ }
142
+ }
143
+ /**
144
+ * Start microphone stream
145
+ * @param config Audio configuration
146
+ */
147
+ async start(config = {}) {
148
+ try {
149
+ const constraints = {
150
+ audio: {
151
+ sampleRate: config.sampleRate || 44100,
152
+ channelCount: config.channelCount || 1,
153
+ echoCancellation: config.echoCancellation ?? true,
154
+ noiseSuppression: config.noiseSuppression ?? true,
155
+ autoGainControl: config.autoGainControl ?? true
156
+ }
157
+ };
158
+ this.stream = await navigator.mediaDevices.getUserMedia(constraints);
159
+ return this.stream;
160
+ }
161
+ catch (error) {
162
+ throw new Error(`Failed to start microphone: ${error}`);
163
+ }
164
+ }
165
+ /**
166
+ * Stop microphone stream
167
+ */
168
+ stop() {
169
+ if (this.stream) {
170
+ this.stream.getTracks().forEach(track => track.stop());
171
+ this.stream = null;
172
+ }
173
+ if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
174
+ this.mediaRecorder.stop();
175
+ }
176
+ }
177
+ /**
178
+ * Start recording audio
179
+ * @param options Recording options
180
+ */
181
+ async startRecording(options = {}) {
182
+ if (!this.stream) {
183
+ await this.start();
184
+ }
185
+ if (!this.stream) {
186
+ throw new Error('Failed to start microphone stream');
187
+ }
188
+ this.recordedChunks = [];
189
+ this.mediaRecorder = new MediaRecorder(this.stream, {
190
+ mimeType: options.mimeType || 'audio/webm',
191
+ audioBitsPerSecond: options.audioBitsPerSecond || 128000
192
+ });
193
+ this.mediaRecorder.ondataavailable = (event) => {
194
+ if (event.data.size > 0) {
195
+ this.recordedChunks.push(event.data);
196
+ }
197
+ };
198
+ this.mediaRecorder.start();
199
+ }
200
+ /**
201
+ * Stop recording and get audio blob
202
+ */
203
+ async stopRecording() {
204
+ return new Promise((resolve, reject) => {
205
+ if (!this.mediaRecorder) {
206
+ reject(new Error('Recording not started'));
207
+ return;
208
+ }
209
+ this.mediaRecorder.onstop = () => {
210
+ const blob = new Blob(this.recordedChunks, { type: 'audio/webm' });
211
+ resolve(blob);
212
+ };
213
+ this.mediaRecorder.onerror = (event) => {
214
+ reject(new Error('Recording failed'));
215
+ };
216
+ this.mediaRecorder.stop();
217
+ });
218
+ }
219
+ /**
220
+ * Get current recording state
221
+ */
222
+ getRecordingState() {
223
+ return this.mediaRecorder?.state || 'inactive';
224
+ }
225
+ /**
226
+ * Get audio stream
227
+ */
228
+ getStream() {
229
+ return this.stream;
230
+ }
231
+ }
232
+ exports.MicrophoneAPI = MicrophoneAPI;
233
+ /**
234
+ * Speaker API for R1 device
235
+ */
236
+ class SpeakerAPI {
237
+ constructor() {
238
+ this.audioContext = null;
239
+ this.currentAudio = null;
240
+ }
241
+ /**
242
+ * Initialize audio context
243
+ */
244
+ async initializeAudioContext() {
245
+ if (!this.audioContext) {
246
+ this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
247
+ if (this.audioContext.state === 'suspended') {
248
+ await this.audioContext.resume();
249
+ }
250
+ }
251
+ }
252
+ /**
253
+ * Play audio from URL or blob
254
+ * @param source Audio source (URL, blob, or base64)
255
+ * @param volume Volume level (0-1)
256
+ */
257
+ async play(source, volume = 1) {
258
+ await this.initializeAudioContext();
259
+ return new Promise((resolve, reject) => {
260
+ this.currentAudio = new Audio();
261
+ this.currentAudio.volume = Math.max(0, Math.min(1, volume));
262
+ this.currentAudio.onended = () => resolve();
263
+ this.currentAudio.onerror = () => reject(new Error('Audio playback failed'));
264
+ if (source instanceof Blob) {
265
+ this.currentAudio.src = URL.createObjectURL(source);
266
+ }
267
+ else {
268
+ this.currentAudio.src = source;
269
+ }
270
+ this.currentAudio.play().catch(reject);
271
+ });
272
+ }
273
+ /**
274
+ * Stop current audio playback
275
+ */
276
+ stop() {
277
+ if (this.currentAudio) {
278
+ this.currentAudio.pause();
279
+ this.currentAudio.currentTime = 0;
280
+ if (this.currentAudio.src.startsWith('blob:')) {
281
+ URL.revokeObjectURL(this.currentAudio.src);
282
+ }
283
+ }
284
+ }
285
+ /**
286
+ * Set volume for current audio
287
+ * @param volume Volume level (0-1)
288
+ */
289
+ setVolume(volume) {
290
+ if (this.currentAudio) {
291
+ this.currentAudio.volume = Math.max(0, Math.min(1, volume));
292
+ }
293
+ }
294
+ /**
295
+ * Generate and play tone
296
+ * @param frequency Frequency in Hz
297
+ * @param duration Duration in milliseconds
298
+ * @param volume Volume level (0-1)
299
+ */
300
+ async playTone(frequency, duration, volume = 0.5) {
301
+ await this.initializeAudioContext();
302
+ if (!this.audioContext)
303
+ return;
304
+ const oscillator = this.audioContext.createOscillator();
305
+ const gainNode = this.audioContext.createGain();
306
+ oscillator.connect(gainNode);
307
+ gainNode.connect(this.audioContext.destination);
308
+ oscillator.frequency.setValueAtTime(frequency, this.audioContext.currentTime);
309
+ gainNode.gain.setValueAtTime(volume, this.audioContext.currentTime);
310
+ oscillator.start();
311
+ oscillator.stop(this.audioContext.currentTime + duration / 1000);
312
+ return new Promise(resolve => {
313
+ oscillator.onended = () => resolve();
314
+ });
315
+ }
316
+ /**
317
+ * Check if audio is currently playing
318
+ */
319
+ isPlaying() {
320
+ return this.currentAudio ? !this.currentAudio.paused : false;
321
+ }
322
+ }
323
+ exports.SpeakerAPI = SpeakerAPI;
324
+ /**
325
+ * Media device utilities
326
+ */
327
+ class MediaUtils {
328
+ /**
329
+ * Get available media devices
330
+ */
331
+ static async getDevices() {
332
+ try {
333
+ const devices = await navigator.mediaDevices.enumerateDevices();
334
+ return devices.map(device => ({
335
+ deviceId: device.deviceId,
336
+ kind: device.kind,
337
+ label: device.label,
338
+ groupId: device.groupId
339
+ }));
340
+ }
341
+ catch {
342
+ return [];
343
+ }
344
+ }
345
+ /**
346
+ * Check if specific media type is supported
347
+ * @param type Media type to check
348
+ */
349
+ static async isSupported(type) {
350
+ switch (type) {
351
+ case 'camera':
352
+ return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
353
+ case 'microphone':
354
+ return !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
355
+ case 'speaker':
356
+ return !!(window.AudioContext || window.webkitAudioContext);
357
+ default:
358
+ return false;
359
+ }
360
+ }
361
+ /**
362
+ * Convert blob to base64 string
363
+ * @param blob Blob to convert
364
+ */
365
+ static blobToBase64(blob) {
366
+ return new Promise((resolve, reject) => {
367
+ const reader = new FileReader();
368
+ reader.onload = () => {
369
+ const result = reader.result;
370
+ resolve(result.split(',')[1]); // Remove data URL prefix
371
+ };
372
+ reader.onerror = reject;
373
+ reader.readAsDataURL(blob);
374
+ });
375
+ }
376
+ /**
377
+ * Convert base64 string to blob
378
+ * @param base64 Base64 string
379
+ * @param mimeType MIME type
380
+ */
381
+ static base64ToBlob(base64, mimeType) {
382
+ const byteCharacters = atob(base64);
383
+ const byteNumbers = new Array(byteCharacters.length);
384
+ for (let i = 0; i < byteCharacters.length; i++) {
385
+ byteNumbers[i] = byteCharacters.charCodeAt(i);
386
+ }
387
+ const byteArray = new Uint8Array(byteNumbers);
388
+ return new Blob([byteArray], { type: mimeType });
389
+ }
390
+ }
391
+ exports.MediaUtils = MediaUtils;
392
+ // Export singleton instances
393
+ exports.camera = new CameraAPI();
394
+ exports.microphone = new MicrophoneAPI();
395
+ exports.speaker = new SpeakerAPI();
396
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/media/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAmCH;;GAEG;AACH,MAAa,SAAS;IAAtB;QACU,WAAM,GAAuB,IAAI,CAAC;QAClC,iBAAY,GAA4B,IAAI,CAAC;IAsHvD,CAAC;IApHC;;OAEG;IACH,KAAK,CAAC,WAAW;QACf,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,YAAY,CAAC,gBAAgB,EAAE,CAAC;YAChE,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;QAC9D,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED;;;OAGG;I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AAI,UAAU,CAAC,WAAW,CAAC,CAAC;QAC9C,OAAO,IAAI,IAAI,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnD,CAAC;CACF;AAnED,gCAmEC;AAED,6BAA6B;AAChB,QAAA,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;AACzB,QAAA,UAAU,GAAG,IAAI,aAAa,EAAE,CAAC;AACjC,QAAA,OAAO,GAAG,IAAI,UAAU,EAAE,CAAC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Storage API module for R1 plugin data persistence
3
+ * Provides both plain and secure storage with automatic Base64 encoding
4
+ */
5
+ import type { StorageAPI } from '../types';
6
+ /**
7
+ * Utility functions for Base64 encoding/decoding
8
+ */
9
+ export declare class Base64Utils {
10
+ /**
11
+ * Encode data to Base64 string
12
+ * @param data Data to encode (string or object)
13
+ */
14
+ static encode(data: any): string;
15
+ /**
16
+ * Decode Base64 string to data
17
+ * @param encoded Base64 encoded string
18
+ * @param parseJson Whether to parse as JSON (default: true)
19
+ */
20
+ static decode<T = any>(encoded: string, parseJson?: boolean): T;
21
+ /**
22
+ * Safely decode Base64 string, returns null if invalid
23
+ * @param encoded Base64 encoded string
24
+ * @param parseJson Whether to parse as JSON (default: true)
25
+ */
26
+ static safeDecode<T = any>(encoded: string | null, parseJson?: boolean): T | null;
27
+ }
28
+ /**
29
+ * Enhanced storage wrapper with automatic Base64 encoding and JSON support
30
+ */
31
+ declare class StorageWrapper implements StorageAPI {
32
+ private storage;
33
+ constructor(storage: StorageAPI);
34
+ /**
35
+ * Store data with automatic Base64 encoding
36
+ * @param key Storage key
37
+ * @param value Data to store (will be JSON stringified and Base64 encoded)
38
+ */
39
+ setItem(key: string, value: any): Promise<void>;
40
+ /**
41
+ * Retrieve and decode data
42
+ * @param key Storage key
43
+ * @param parseJson Whether to parse as JSON (default: true)
44
+ */
45
+ getItem<T = any>(key: string, parseJson?: boolean): Promise<T | null>;
46
+ /**
47
+ * Remove item from storage
48
+ * @param key Storage key
49
+ */
50
+ removeItem(key: string): Promise<void>;
51
+ /**
52
+ * Clear all storage
53
+ */
54
+ clear(): Promise<void>;
55
+ /**
56
+ * Store raw Base64 data (for manual encoding)
57
+ * @param key Storage key
58
+ * @param base64Value Base64 encoded string
59
+ */
60
+ setRaw(key: string, base64Value: string): Promise<void>;
61
+ /**
62
+ * Get raw Base64 data (without decoding)
63
+ * @param key Storage key
64
+ */
65
+ getRaw(key: string): Promise<string | null>;
66
+ }
67
+ /**
68
+ * Enhanced Creation Storage with Base64 utilities
69
+ */
70
+ export declare class R1Storage {
71
+ private _plain?;
72
+ private _secure?;
73
+ /**
74
+ * Plain storage (unencrypted, Base64 encoded)
75
+ */
76
+ get plain(): StorageWrapper;
77
+ /**
78
+ * Secure storage (hardware-encrypted, Base64 encoded)
79
+ * Requires Android M or higher
80
+ */
81
+ get secure(): StorageWrapper;
82
+ /**
83
+ * Check if storage is available
84
+ */
85
+ static isAvailable(): boolean;
86
+ /**
87
+ * Check if secure storage is available
88
+ */
89
+ static isSecureAvailable(): boolean;
90
+ /**
91
+ * Utility to store user preferences with type safety
92
+ * @param prefs User preferences object
93
+ * @param useSecure Whether to use secure storage (default: false)
94
+ */
95
+ setPreferences<T extends Record<string, any>>(prefs: T, useSecure?: boolean): Promise<void>;
96
+ /**
97
+ * Utility to get user preferences with type safety
98
+ * @param useSecure Whether to use secure storage (default: false)
99
+ */
100
+ getPreferences<T extends Record<string, any>>(useSecure?: boolean): Promise<T | null>;
101
+ /**
102
+ * Utility to store sensitive data (API keys, tokens, etc.)
103
+ * @param key Storage key
104
+ * @param value Sensitive data
105
+ */
106
+ setSecret(key: string, value: string): Promise<void>;
107
+ /**
108
+ * Utility to get sensitive data
109
+ * @param key Storage key
110
+ */
111
+ getSecret(key: string): Promise<string | null>;
112
+ }
113
+ export declare const storage: R1Storage;
114
+ export {};
115
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+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