44 DEFAULT_ANAM_METRICS_BASE_URL ,
55 ErrorCode ,
66 setErrorMetricsBaseUrl ,
7+ setCurrentSessionInfo ,
78} from './lib/ClientError' ;
89import {
910 CoreApiRestClient ,
@@ -34,6 +35,7 @@ export default class AnamClient {
3435 private inputAudioState : InputAudioState = { isMuted : false } ;
3536
3637 private sessionId : string | null = null ;
38+ private organizationId : string | null = null ;
3739
3840 private streamingClient : StreamingClient | null = null ;
3941 private apiClient : CoreApiRestClient ;
@@ -111,6 +113,9 @@ export default class AnamClient {
111113 // Validate persona configuration based on session token
112114 if ( sessionToken ) {
113115 const decodedToken = this . decodeJwt ( sessionToken ) ;
116+ this . organizationId = decodedToken . accountId ;
117+ setCurrentSessionInfo ( this . sessionId , this . organizationId ) ;
118+
114119 const tokenType = decodedToken . type ?. toLowerCase ( ) ;
115120
116121 if ( tokenType === 'legacy' ) {
@@ -218,11 +223,15 @@ export default class AnamClient {
218223 'Failed to initialize streaming client' ,
219224 ErrorCode . CLIENT_ERROR_CODE_SERVER_ERROR ,
220225 500 ,
221- { cause : error instanceof Error ? error . message : String ( error ) } ,
226+ {
227+ cause : error instanceof Error ? error . message : String ( error ) ,
228+ sessionId,
229+ } ,
222230 ) ;
223231 }
224232
225233 this . sessionId = sessionId ;
234+ setCurrentSessionInfo ( this . sessionId , this . organizationId ) ;
226235 return sessionId ;
227236 }
228237
@@ -290,6 +299,16 @@ export default class AnamClient {
290299 videoElementId : string ,
291300 audioElementId : string ,
292301 userProvidedAudioStream ?: MediaStream ,
302+ ) : Promise < void > {
303+ console . warn (
304+ 'AnamClient: streamToVideoAndAudioElements is deprecated. Please use streamToVideoElement instead.' ,
305+ ) ;
306+ await this . streamToVideoElement ( videoElementId , userProvidedAudioStream ) ;
307+ }
308+
309+ public async streamToVideoElement (
310+ videoElementId : string ,
311+ userProvidedAudioStream ?: MediaStream ,
293312 ) : Promise < void > {
294313 if ( this . clientOptions ?. disableInputAudio && userProvidedAudioStream ) {
295314 console . warn (
@@ -309,6 +328,7 @@ export default class AnamClient {
309328 500 ,
310329 {
311330 cause : error instanceof Error ? error . message : String ( error ) ,
331+ sessionId : this . sessionId ,
312332 } ,
313333 ) ;
314334 }
@@ -321,10 +341,7 @@ export default class AnamClient {
321341 throw new Error ( 'Failed to stream: streaming client is not available' ) ;
322342 }
323343
324- this . streamingClient . setMediaStreamTargetsById (
325- videoElementId ,
326- audioElementId ,
327- ) ;
344+ this . streamingClient . setMediaStreamTargetById ( videoElementId ) ;
328345 this . streamingClient . startConnection ( ) ;
329346 }
330347
@@ -356,6 +373,7 @@ export default class AnamClient {
356373 this . streamingClient . stopConnection ( ) ;
357374 this . streamingClient = null ;
358375 this . sessionId = null ;
376+ setCurrentSessionInfo ( null , this . organizationId ) ;
359377 this . _isStreaming = false ;
360378 }
361379 }
0 commit comments