@roboflow/inference-sdk 0.1.7 → 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/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +392 -211
- package/dist/index.es.js.map +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/inference-api.d.ts +26 -0
- package/dist/inference-api.d.ts.map +1 -1
- package/dist/video-upload.d.ts +30 -0
- package/dist/video-upload.d.ts.map +1 -0
- package/dist/webrtc-types.d.ts +44 -0
- package/dist/webrtc-types.d.ts.map +1 -0
- package/dist/webrtc.d.ts +148 -8
- package/dist/webrtc.d.ts.map +1 -1
- package/package.json +4 -3
package/dist/webrtc.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Connector, WebRTCParams } from "./inference-api";
|
|
2
|
+
import { WebRTCOutputData } from "./webrtc-types";
|
|
3
|
+
export type { WebRTCVideoMetadata, WebRTCOutputData } from "./webrtc-types";
|
|
4
|
+
export { FileUploader } from "./video-upload";
|
|
2
5
|
/**
|
|
3
6
|
* Reassembles chunked binary messages from the datachannel
|
|
4
7
|
*/
|
|
@@ -29,24 +32,33 @@ export interface UseStreamParams {
|
|
|
29
32
|
source: MediaStream;
|
|
30
33
|
connector: Connector;
|
|
31
34
|
wrtcParams: WebRTCParams;
|
|
32
|
-
onData?: (data:
|
|
35
|
+
onData?: (data: WebRTCOutputData) => void;
|
|
33
36
|
options?: UseStreamOptions;
|
|
34
37
|
}
|
|
35
38
|
/**
|
|
36
39
|
* WebRTC Connection object
|
|
37
40
|
*
|
|
38
|
-
* Represents an active WebRTC connection to Roboflow for streaming inference
|
|
41
|
+
* Represents an active WebRTC connection to Roboflow for streaming inference
|
|
42
|
+
* or file-based batch processing.
|
|
39
43
|
*/
|
|
40
44
|
export declare class RFWebRTCConnection {
|
|
41
45
|
private pc;
|
|
42
|
-
private _localStream
|
|
46
|
+
private _localStream?;
|
|
43
47
|
private remoteStreamPromise;
|
|
44
48
|
private pipelineId;
|
|
45
49
|
private apiKey;
|
|
46
50
|
private dataChannel;
|
|
47
51
|
private reassembler;
|
|
52
|
+
private uploadChannel?;
|
|
53
|
+
private uploader?;
|
|
54
|
+
private onComplete?;
|
|
48
55
|
/** @private */
|
|
49
|
-
constructor(pc: RTCPeerConnection,
|
|
56
|
+
constructor(pc: RTCPeerConnection, remoteStreamPromise: Promise<MediaStream>, pipelineId: string | null, apiKey: string | null, dataChannel: RTCDataChannel, options?: {
|
|
57
|
+
localStream?: MediaStream;
|
|
58
|
+
uploadChannel?: RTCDataChannel;
|
|
59
|
+
onData?: (data: any) => void;
|
|
60
|
+
onComplete?: () => void;
|
|
61
|
+
});
|
|
50
62
|
/**
|
|
51
63
|
* Get the remote stream (processed video from Roboflow)
|
|
52
64
|
*
|
|
@@ -63,21 +75,23 @@ export declare class RFWebRTCConnection {
|
|
|
63
75
|
/**
|
|
64
76
|
* Get the local stream (original camera)
|
|
65
77
|
*
|
|
66
|
-
* @returns The local MediaStream
|
|
78
|
+
* @returns The local MediaStream, or undefined if using file upload mode
|
|
67
79
|
*
|
|
68
80
|
* @example
|
|
69
81
|
* ```typescript
|
|
70
82
|
* const conn = await useStream({ ... });
|
|
71
83
|
* const localStream = conn.localStream();
|
|
72
|
-
*
|
|
84
|
+
* if (localStream) {
|
|
85
|
+
* videoElement.srcObject = localStream;
|
|
86
|
+
* }
|
|
73
87
|
* ```
|
|
74
88
|
*/
|
|
75
|
-
localStream(): MediaStream;
|
|
89
|
+
localStream(): MediaStream | undefined;
|
|
76
90
|
/**
|
|
77
91
|
* Cleanup and close connection
|
|
78
92
|
*
|
|
79
93
|
* Terminates the pipeline on Roboflow, closes the peer connection,
|
|
80
|
-
* and stops the local media stream.
|
|
94
|
+
* and stops the local media stream (if applicable).
|
|
81
95
|
*
|
|
82
96
|
* @returns Promise that resolves when cleanup is complete
|
|
83
97
|
*
|
|
@@ -89,6 +103,26 @@ export declare class RFWebRTCConnection {
|
|
|
89
103
|
* ```
|
|
90
104
|
*/
|
|
91
105
|
cleanup(): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Start uploading a file through the connection
|
|
108
|
+
*
|
|
109
|
+
* @param file - The file to upload
|
|
110
|
+
* @param onProgress - Optional callback for progress updates (bytesUploaded, totalBytes)
|
|
111
|
+
* @returns Promise that resolves when upload is complete
|
|
112
|
+
* @throws Error if no upload channel is available
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* await connection.startUpload(videoFile, (uploaded, total) => {
|
|
117
|
+
* console.log(`Upload progress: ${(uploaded / total * 100).toFixed(1)}%`);
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
startUpload(file: File, onProgress?: (bytesUploaded: number, totalBytes: number) => void): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Cancel any ongoing file upload
|
|
124
|
+
*/
|
|
125
|
+
cancelUpload(): void;
|
|
92
126
|
/**
|
|
93
127
|
* Reconfigure pipeline outputs at runtime
|
|
94
128
|
*
|
|
@@ -168,4 +202,110 @@ export declare class RFWebRTCConnection {
|
|
|
168
202
|
* ```
|
|
169
203
|
*/
|
|
170
204
|
export declare function useStream({ source, connector, wrtcParams, onData, options }: UseStreamParams): Promise<RFWebRTCConnection>;
|
|
205
|
+
/**
|
|
206
|
+
* Parameters for useVideoFile function
|
|
207
|
+
*/
|
|
208
|
+
export interface UseVideoFileParams {
|
|
209
|
+
/** The video file to upload */
|
|
210
|
+
file: File;
|
|
211
|
+
/** Connector for WebRTC signaling */
|
|
212
|
+
connector: Connector;
|
|
213
|
+
/** WebRTC parameters for the workflow */
|
|
214
|
+
wrtcParams: WebRTCParams;
|
|
215
|
+
/** Callback for inference results */
|
|
216
|
+
onData?: (data: WebRTCOutputData) => void;
|
|
217
|
+
/** Callback for upload progress */
|
|
218
|
+
onUploadProgress?: (bytesUploaded: number, totalBytes: number) => void;
|
|
219
|
+
/** Callback when processing completes (datachannel closes) */
|
|
220
|
+
onComplete?: () => void;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Upload a video file for batch inference processing
|
|
224
|
+
*
|
|
225
|
+
* Creates a WebRTC connection to Roboflow for uploading a video file
|
|
226
|
+
* and receiving inference results. The file is uploaded via datachannel
|
|
227
|
+
* with intelligent backpressure handling.
|
|
228
|
+
*
|
|
229
|
+
* @param params - Connection parameters
|
|
230
|
+
* @returns Promise resolving to RFWebRTCConnection
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* import { connectors, webrtc } from './index.ts';
|
|
235
|
+
*
|
|
236
|
+
* const connector = connectors.withApiKey("your-api-key");
|
|
237
|
+
* const connection = await webrtc.useVideoFile({
|
|
238
|
+
* file: videoFile,
|
|
239
|
+
* connector,
|
|
240
|
+
* wrtcParams: {
|
|
241
|
+
* workflowSpec: { ... },
|
|
242
|
+
* imageInputName: "image",
|
|
243
|
+
* dataOutputNames: ["predictions"]
|
|
244
|
+
* },
|
|
245
|
+
* onData: (data) => {
|
|
246
|
+
* console.log("Inference results:", data);
|
|
247
|
+
* if (data.processing_complete) {
|
|
248
|
+
* console.log("Processing complete!");
|
|
249
|
+
* }
|
|
250
|
+
* },
|
|
251
|
+
* onUploadProgress: (uploaded, total) => {
|
|
252
|
+
* console.log(`Upload: ${(uploaded / total * 100).toFixed(1)}%`);
|
|
253
|
+
* }
|
|
254
|
+
* });
|
|
255
|
+
*
|
|
256
|
+
* // When done
|
|
257
|
+
* await connection.cleanup();
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
export declare function useVideoFile({ file, connector, wrtcParams, onData, onUploadProgress, onComplete }: UseVideoFileParams): Promise<RFWebRTCConnection>;
|
|
261
|
+
/**
|
|
262
|
+
* Parameters for useRtspStream function
|
|
263
|
+
*/
|
|
264
|
+
export interface UseRtspStreamParams {
|
|
265
|
+
/** RTSP URL for server-side video capture (e.g., "rtsp://camera.local/stream") */
|
|
266
|
+
rtspUrl: string;
|
|
267
|
+
/** Connector for WebRTC signaling */
|
|
268
|
+
connector: Connector;
|
|
269
|
+
/** WebRTC parameters for the workflow */
|
|
270
|
+
wrtcParams: WebRTCParams;
|
|
271
|
+
/** Callback for inference results */
|
|
272
|
+
onData?: (data: WebRTCOutputData) => void;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Connect to an RTSP stream for inference processing
|
|
276
|
+
*
|
|
277
|
+
* Creates a WebRTC connection where the server captures video from an RTSP URL
|
|
278
|
+
* and sends processed video back to the client. This is a receive-only mode -
|
|
279
|
+
* no video is sent from the browser to the server.
|
|
280
|
+
*
|
|
281
|
+
* @param params - Connection parameters
|
|
282
|
+
* @returns Promise resolving to RFWebRTCConnection
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* import { connectors, webrtc } from './index.ts';
|
|
287
|
+
*
|
|
288
|
+
* const connector = connectors.withApiKey("your-api-key");
|
|
289
|
+
* const connection = await webrtc.useRtspStream({
|
|
290
|
+
* rtspUrl: "rtsp://camera.local/stream",
|
|
291
|
+
* connector,
|
|
292
|
+
* wrtcParams: {
|
|
293
|
+
* workflowSpec: { ... },
|
|
294
|
+
* imageInputName: "image",
|
|
295
|
+
* dataOutputNames: ["predictions"]
|
|
296
|
+
* },
|
|
297
|
+
* onData: (data) => {
|
|
298
|
+
* console.log("Inference results:", data);
|
|
299
|
+
* }
|
|
300
|
+
* });
|
|
301
|
+
*
|
|
302
|
+
* // Get processed video stream from server
|
|
303
|
+
* const remoteStream = await connection.remoteStream();
|
|
304
|
+
* videoElement.srcObject = remoteStream;
|
|
305
|
+
*
|
|
306
|
+
* // When done
|
|
307
|
+
* await connection.cleanup();
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
310
|
+
export declare function useRtspStream({ rtspUrl, connector, wrtcParams, onData }: UseRtspStreamParams): Promise<RFWebRTCConnection>;
|
|
171
311
|
//# sourceMappingURL=webrtc.d.ts.map
|
package/dist/webrtc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webrtc.d.ts","sourceRoot":"","sources":["../src/webrtc.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,SAAS,EAAE,YAAY,EAAsB,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"webrtc.d.ts","sourceRoot":"","sources":["../src/webrtc.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,SAAS,EAAE,YAAY,EAAsB,MAAM,iBAAiB,CAAC;AAEnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlD,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAQ9C;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,aAAa,CAGN;IAEf;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,UAAU,GAAG,IAAI;IAqC9G;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAE,CAQxI;AAED,MAAM,WAAW,gBAAgB;IAC/B,6BAA6B,CAAC,EAAE,OAAO,CAAC;CACzC;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE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C,SAAS,EAAE,SAAS,CAAC;IACrB,yCAAyC;IACzC,UAAU,EAAE,YAAY,CAAC;IACzB,qCAAqC;IACrC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAO,EACP,SAAS,EACT,UAAU,EACV,MAAM,EACP,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAYnD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roboflow/inference-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Lightweight client for Roboflow's hosted inference API with WebRTC streaming support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"roboflow",
|
|
@@ -25,11 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"dev": "vite",
|
|
28
|
-
"build": "vite build",
|
|
28
|
+
"build": "tsc --noEmit && vite build",
|
|
29
29
|
"preview": "vite preview",
|
|
30
30
|
"clean": "rm -rf dist",
|
|
31
31
|
"test": "vitest run",
|
|
32
|
-
"test:watch": "vitest"
|
|
32
|
+
"test:watch": "vitest",
|
|
33
|
+
"typecheck": "tsc --noEmit"
|
|
33
34
|
},
|
|
34
35
|
"author": "Roboflow",
|
|
35
36
|
"license": "ISC",
|