11/**
2- * Base URL for the Roboflow API (used for TURN server configuration)
3- * Can be overridden via environment variable in Node.js environments
2+ * Default base URL for the Roboflow API (used for TURN server configuration)
43 */
5- const RF_API_BASE_URL = typeof process !== "undefined" && process . env ?. RF_API_BASE_URL
4+ const DEFAULT_RF_API_BASE_URL = typeof process !== "undefined" && process . env ?. RF_API_BASE_URL
65 ? process . env . RF_API_BASE_URL
76 : "https://api.roboflow.com" ;
87
@@ -161,21 +160,23 @@ export interface Connector {
161160export class InferenceHTTPClient {
162161 private apiKey : string ;
163162 private serverUrl : string ;
163+ private apiBaseUrl : string ;
164164
165165 /**
166166 * @private
167167 * Use InferenceHTTPClient.init() instead
168168 */
169- private constructor ( apiKey : string , serverUrl : string = "https://serverless.roboflow.com" ) {
169+ private constructor ( apiKey : string , serverUrl : string = "https://serverless.roboflow.com" , apiBaseUrl : string = DEFAULT_RF_API_BASE_URL ) {
170170 this . apiKey = apiKey ;
171171 this . serverUrl = serverUrl ;
172+ this . apiBaseUrl = apiBaseUrl ;
172173 }
173174
174- static init ( { apiKey, serverUrl } : { apiKey : string ; serverUrl ?: string } ) : InferenceHTTPClient {
175+ static init ( { apiKey, serverUrl, apiBaseUrl } : { apiKey : string ; serverUrl ?: string ; apiBaseUrl ?: string } ) : InferenceHTTPClient {
175176 if ( ! apiKey ) {
176177 throw new Error ( "apiKey is required" ) ;
177178 }
178- return new InferenceHTTPClient ( apiKey , serverUrl ) ;
179+ return new InferenceHTTPClient ( apiKey , serverUrl , apiBaseUrl ) ;
179180 }
180181
181182 /**
@@ -336,13 +337,13 @@ export class InferenceHTTPClient {
336337 * ```
337338 */
338339 async fetchTurnConfig ( ) : Promise < RTCIceServerConfig [ ] | null > {
339- // // Only fetch TURN config for Roboflow serverless URLs
340+ // Only fetch TURN config for Roboflow serverless URLs
340341 if ( ! ROBOFLOW_SERVERLESS_URLS . includes ( this . serverUrl ) ) {
341342 return null ;
342343 }
343344 try {
344345 const response = await fetch (
345- `${ RF_API_BASE_URL } /webrtc_turn_config?api_key=${ this . apiKey } ` ,
346+ `${ this . apiBaseUrl } /webrtc_turn_config?api_key=${ this . apiKey } ` ,
346347 {
347348 method : "GET" ,
348349 headers : { "Content-Type" : "application/json" }
@@ -413,8 +414,8 @@ export const connectors = {
413414 * const answer = await connector.connectWrtc(offer, wrtcParams);
414415 * ```
415416 */
416- withApiKey ( apiKey : string , options : { serverUrl ?: string } = { } ) : Connector {
417- const { serverUrl } = options ;
417+ withApiKey ( apiKey : string , options : { serverUrl ?: string ; apiBaseUrl ?: string } = { } ) : Connector {
418+ const { serverUrl, apiBaseUrl } = options ;
418419
419420 // Warn if running in browser context
420421 if ( typeof window !== 'undefined' ) {
@@ -425,7 +426,7 @@ export const connectors = {
425426 ) ;
426427 }
427428
428- const client = InferenceHTTPClient . init ( { apiKey, serverUrl } ) ;
429+ const client = InferenceHTTPClient . init ( { apiKey, serverUrl, apiBaseUrl } ) ;
429430
430431 return {
431432 connectWrtc : async ( offer : WebRTCOffer , wrtcParams : WebRTCParams ) : Promise < WebRTCWorkerResponse > => {
0 commit comments