whio-api-sdk 1.0.196-beta-staging → 1.0.198-beta-staging
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/WEBSOCKET_AUDIO_STREAMING.md +258 -0
- package/dist/src/sdk/modules/websocket.module.d.ts +73 -0
- package/dist/src/sdk/modules/websocket.module.js +253 -0
- package/dist/src/sdk/sdk.d.ts +10 -0
- package/dist/src/sdk/sdk.js +27 -0
- package/dist/src/sdk/types/common.types.d.ts +9 -0
- package/dist/src/sdk/types/common.types.js +9 -1
- package/dist/src/sdk/types/index.d.ts +1 -0
- package/dist/src/sdk/types/index.js +1 -0
- package/dist/src/sdk/types/session.types.d.ts +3 -0
- package/dist/src/sdk/types/websocket.types.d.ts +50 -0
- package/dist/src/sdk/types/websocket.types.js +2 -0
- package/examples/websocket-audio-streaming.ts +204 -0
- package/package.json +2 -1
- package/src/sdk/modules/websocket.module.ts +325 -0
- package/src/sdk/sdk.ts +36 -0
- package/src/sdk/types/common.types.ts +11 -0
- package/src/sdk/types/index.ts +1 -0
- package/src/sdk/types/session.types.ts +3 -0
- package/src/sdk/types/websocket.types.ts +48 -0
- package/test-websocket.mjs +96 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Common types used across the SDK
|
|
2
|
+
import { WebSocketConfig } from './websocket.types';
|
|
2
3
|
|
|
3
4
|
export interface SDKConfig {
|
|
4
5
|
baseUrl?: string;
|
|
@@ -7,6 +8,7 @@ export interface SDKConfig {
|
|
|
7
8
|
setItem: (key: string, value: string) => void | Promise<void>;
|
|
8
9
|
removeItem: (key: string) => void | Promise<void>;
|
|
9
10
|
};
|
|
11
|
+
websocket?: WebSocketConfig;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
// Role type
|
|
@@ -24,3 +26,12 @@ export enum RoleType {
|
|
|
24
26
|
TRIAL = 'TRIAL',
|
|
25
27
|
PAID = 'PAID',
|
|
26
28
|
}
|
|
29
|
+
|
|
30
|
+
// Enum for session summary status to match API
|
|
31
|
+
export enum SummaryStatus {
|
|
32
|
+
NONE = 'NONE',
|
|
33
|
+
READY = 'READY',
|
|
34
|
+
GENERATING = 'GENERATING',
|
|
35
|
+
GENERATED = 'GENERATED',
|
|
36
|
+
FAILED = 'FAILED',
|
|
37
|
+
}
|
package/src/sdk/types/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { User } from './user.types';
|
|
2
2
|
import { Template, TranscriptionSummary } from './template.types';
|
|
3
3
|
import { AudioFile } from './audio.types';
|
|
4
|
+
import { SummaryStatus } from './common.types';
|
|
4
5
|
|
|
5
6
|
// Session types
|
|
6
7
|
export interface Session {
|
|
@@ -14,6 +15,7 @@ export interface Session {
|
|
|
14
15
|
templateName?: string;
|
|
15
16
|
summary?: string;
|
|
16
17
|
sessionName?: string;
|
|
18
|
+
summaryStatus: SummaryStatus;
|
|
17
19
|
createdAt: string;
|
|
18
20
|
updatedAt: string;
|
|
19
21
|
templateId: string;
|
|
@@ -59,5 +61,6 @@ export interface UpdateSessionDto {
|
|
|
59
61
|
templateName?: string;
|
|
60
62
|
summary?: string;
|
|
61
63
|
sessionName?: string;
|
|
64
|
+
summaryStatus?: SummaryStatus;
|
|
62
65
|
primaryTranscriptionSummaryId?: string;
|
|
63
66
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// WebSocket related types
|
|
2
|
+
|
|
3
|
+
export interface AudioChunkPayload {
|
|
4
|
+
sessionId: string;
|
|
5
|
+
audioChunk: number[] | number[][];
|
|
6
|
+
flag: 'end' | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface WebSocketConfig {
|
|
10
|
+
autoConnect?: boolean;
|
|
11
|
+
reconnectAttempts?: number;
|
|
12
|
+
reconnectDelay?: number;
|
|
13
|
+
maxReconnectDelay?: number;
|
|
14
|
+
namespace?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface WebSocketConnectionStats {
|
|
18
|
+
isConnected: boolean;
|
|
19
|
+
reconnectAttempts: number;
|
|
20
|
+
lastConnectedAt?: Date;
|
|
21
|
+
lastDisconnectedAt?: Date;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AudioStreamingOptions {
|
|
25
|
+
bufferSize?: number;
|
|
26
|
+
autoTranscribe?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// WebSocket events
|
|
30
|
+
export interface WebSocketEvents {
|
|
31
|
+
connected: (data: { message: string; userId: string; timestamp: string }) => void;
|
|
32
|
+
disconnected: (reason: string) => void;
|
|
33
|
+
'audio-chunk-received': (data: {
|
|
34
|
+
sessionId: string;
|
|
35
|
+
chunkCount: number;
|
|
36
|
+
timestamp: string;
|
|
37
|
+
}) => void;
|
|
38
|
+
'transcription-queued': (data: {
|
|
39
|
+
sessionId: string;
|
|
40
|
+
message: string;
|
|
41
|
+
timestamp: string;
|
|
42
|
+
}) => void;
|
|
43
|
+
'audio-error': (error: { error: string }) => void;
|
|
44
|
+
'transcription-error': (error: { sessionId: string; error: string }) => void;
|
|
45
|
+
'connection-error': (error: Error) => void;
|
|
46
|
+
'reconnecting': (attemptNumber: number) => void;
|
|
47
|
+
'reconnect-failed': () => void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ApiSDK } from './dist/sdk/sdk.js';
|
|
2
|
+
|
|
3
|
+
// Simple test to verify WebSocket functionality
|
|
4
|
+
async function testWebSocketIntegration() {
|
|
5
|
+
console.log('Testing WebSocket integration...');
|
|
6
|
+
|
|
7
|
+
const sdk = new ApiSDK({
|
|
8
|
+
baseUrl: 'http://localhost:3000/api',
|
|
9
|
+
storage: {
|
|
10
|
+
getItem: (key) => null, // Simple in-memory storage for testing
|
|
11
|
+
setItem: (key, value) => {},
|
|
12
|
+
removeItem: (key) => {}
|
|
13
|
+
},
|
|
14
|
+
websocket: {
|
|
15
|
+
autoConnect: false, // Don't auto-connect for this test
|
|
16
|
+
reconnectAttempts: 3,
|
|
17
|
+
reconnectDelay: 1000,
|
|
18
|
+
maxReconnectDelay: 5000
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Test WebSocket module availability
|
|
23
|
+
console.log('✓ WebSocket module available:', !!sdk.websocket);
|
|
24
|
+
console.log('✓ WebSocket connection methods available:', {
|
|
25
|
+
connect: typeof sdk.connectWebSocket === 'function',
|
|
26
|
+
disconnect: typeof sdk.disconnectWebSocket === 'function',
|
|
27
|
+
isConnected: typeof sdk.isWebSocketConnected === 'function'
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Test audio streaming methods
|
|
31
|
+
console.log('✓ Audio streaming methods available:', {
|
|
32
|
+
streamAudioChunk: typeof sdk.streamAudioChunk === 'function',
|
|
33
|
+
streamAudioChunks: typeof sdk.streamAudioChunks === 'function'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Test event handling
|
|
37
|
+
console.log('✓ Event handling methods available:', {
|
|
38
|
+
on: typeof sdk.onWebSocketEvent === 'function',
|
|
39
|
+
off: typeof sdk.offWebSocketEvent === 'function'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Test connection stats
|
|
43
|
+
const stats = sdk.getWebSocketStats();
|
|
44
|
+
console.log('✓ Connection stats:', {
|
|
45
|
+
isConnected: stats.isConnected,
|
|
46
|
+
reconnectAttempts: stats.reconnectAttempts
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Test event listeners (without actually connecting)
|
|
50
|
+
let eventFired = false;
|
|
51
|
+
sdk.onWebSocketEvent('connected', (data) => {
|
|
52
|
+
eventFired = true;
|
|
53
|
+
console.log('Connected event fired:', data);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log('✓ Event listener registered successfully');
|
|
57
|
+
|
|
58
|
+
// Test error handling for streaming without connection
|
|
59
|
+
try {
|
|
60
|
+
sdk.streamAudioChunk('test-session', [0.1, 0.2, 0.3], false);
|
|
61
|
+
console.log('✗ Should have thrown error for streaming without connection');
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.log('✓ Correctly throws error when streaming without connection:', error.message);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log('\n🎉 All WebSocket integration tests passed!');
|
|
67
|
+
console.log('\nUsage example:');
|
|
68
|
+
console.log(`
|
|
69
|
+
// Initialize SDK with WebSocket support
|
|
70
|
+
const sdk = new ApiSDK({
|
|
71
|
+
baseUrl: 'https://your-api.com/api',
|
|
72
|
+
storage: localStorage, // or your storage implementation
|
|
73
|
+
websocket: {
|
|
74
|
+
autoConnect: true,
|
|
75
|
+
reconnectAttempts: -1 // infinite
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Listen for events
|
|
80
|
+
sdk.onWebSocketEvent('connected', (data) => {
|
|
81
|
+
console.log('WebSocket connected:', data);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
sdk.onWebSocketEvent('audio-chunk-received', (data) => {
|
|
85
|
+
console.log('Audio chunk processed:', data);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Stream audio data
|
|
89
|
+
sdk.streamAudioChunk('session-id', audioFloatArray, false);
|
|
90
|
+
|
|
91
|
+
// Or stream multiple chunks
|
|
92
|
+
await sdk.streamAudioChunks('session-id', [chunk1, chunk2, chunk3]);
|
|
93
|
+
`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
testWebSocketIntegration().catch(console.error);
|