@dataclouder/ngx-agent-cards 0.1.79 → 0.1.83

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.
@@ -3330,16 +3330,39 @@ const BACKGROUND_SERVICE_TOKEN = new InjectionToken('BACKGROUND_SERVICE_TOKEN');
3330
3330
 
3331
3331
  class VideoPlayerService {
3332
3332
  constructor() {
3333
+ this.conversationFlowStateService = inject(ConversationFlowStateService);
3333
3334
  this.isRewinding = false;
3334
3335
  this.videoQueue = [];
3335
3336
  this.defaultVideoUrl = null;
3336
3337
  this.playAndRewindedSource = new Subject();
3337
3338
  this.playAndRewinded$ = this.playAndRewindedSource.asObservable();
3339
+ this.agentCard = signal(undefined, ...(ngDevMode ? [{ debugName: "agentCard" }] : []));
3340
+ console.log(' CONSTRUCTOR FOR VIDEO PLAYER...');
3338
3341
  this.playAndRewindedSubscription = this.playAndRewinded$.subscribe(() => {
3339
3342
  this.playNextInQueue();
3340
3343
  });
3344
+ this.moodSubscription = this.conversationFlowStateService.moodUpdated$.subscribe((mood) => {
3345
+ console.log('CHANGING MOOD.. ', mood);
3346
+ const card = this.agentCard();
3347
+ if (mood && card?.assets?.motions) {
3348
+ const motionUrl = card.assets.motions.find((m) => m.metadata?.moodState === mood)?.url;
3349
+ if (motionUrl) {
3350
+ this.addVideosToQueue([motionUrl]);
3351
+ this.playAndRewind();
3352
+ }
3353
+ }
3354
+ });
3355
+ }
3356
+ setAgentCard(card) {
3357
+ this.agentCard.set(card);
3358
+ if (card.assets?.motion?.url) {
3359
+ this.setVideoSource(card.assets.motion.url);
3360
+ }
3341
3361
  }
3342
3362
  initializePlayer(videoPlayer) {
3363
+ if (this.player) {
3364
+ this.player.destroy();
3365
+ }
3343
3366
  this.player = new Plyr.default(videoPlayer.nativeElement, {
3344
3367
  controls: [],
3345
3368
  });
@@ -3364,7 +3387,14 @@ class VideoPlayerService {
3364
3387
  startConversation(defaultVideo) {
3365
3388
  if (defaultVideo) {
3366
3389
  this.defaultVideoUrl = defaultVideo;
3367
- // this.setVideoSource(defaultVideo);
3390
+ }
3391
+ else {
3392
+ this.defaultVideoUrl = this.agentCard()?.assets?.motion?.url || null;
3393
+ }
3394
+ const introMotion = this.agentCard()?.assets?.motions?.find((m) => m.metadata?.event === 'intro');
3395
+ if (introMotion?.url) {
3396
+ this.addVideosToQueue([introMotion.url]);
3397
+ this.playAndRewind();
3368
3398
  }
3369
3399
  }
3370
3400
  playVideo() {
@@ -3404,6 +3434,7 @@ class VideoPlayerService {
3404
3434
  }
3405
3435
  }
3406
3436
  addVideosToQueue(videoUrls) {
3437
+ console.log('ADING VIDEOS TO QUEUE, ', videoUrls);
3407
3438
  this.videoQueue.push(...videoUrls);
3408
3439
  }
3409
3440
  destroyPlayer() {
@@ -3424,11 +3455,15 @@ class VideoPlayerService {
3424
3455
  this.isRewinding = false;
3425
3456
  this.videoQueue = [];
3426
3457
  this.defaultVideoUrl = null;
3458
+ this.agentCard.set(undefined);
3427
3459
  }
3428
3460
  ngOnDestroy() {
3429
3461
  if (this.playAndRewindedSubscription) {
3430
3462
  this.playAndRewindedSubscription.unsubscribe();
3431
3463
  }
3464
+ if (this.moodSubscription) {
3465
+ this.moodSubscription.unsubscribe();
3466
+ }
3432
3467
  }
3433
3468
  playNextInQueue() {
3434
3469
  if (this.videoQueue.length > 0) {
@@ -7191,16 +7226,6 @@ class DcAgentCardDetailsComponent {
7191
7226
  this.onStartConversation = output();
7192
7227
  this.agentCard = signal(undefined, ...(ngDevMode ? [{ debugName: "agentCard" }] : []));
7193
7228
  this.showInfoLayer = signal(false, ...(ngDevMode ? [{ debugName: "showInfoLayer" }] : []));
7194
- this.moodSubscription = this.conversationFlowStateService.moodUpdated$.subscribe((mood) => {
7195
- const card = this.agentCard();
7196
- if (mood && card?.assets?.motions) {
7197
- const motionUrl = card.assets.motions.find((m) => m.metadata?.moodState === mood)?.url;
7198
- if (motionUrl) {
7199
- this.videoPlayerService.addVideosToQueue([motionUrl]);
7200
- this.videoPlayerService.playAndRewind();
7201
- }
7202
- }
7203
- });
7204
7229
  effect(() => {
7205
7230
  const isConversationActive = this.chatMonitorService.isConversationActive();
7206
7231
  if (isConversationActive) {
@@ -7211,7 +7236,6 @@ class DcAgentCardDetailsComponent {
7211
7236
  ngOnDestroy() {
7212
7237
  this.videoPlayerService.cleanUp();
7213
7238
  this.chatMonitorService.setBackground(undefined);
7214
- this.moodSubscription?.unsubscribe();
7215
7239
  }
7216
7240
  ngAfterViewInit() {
7217
7241
  if (this.videoPlayer) {
@@ -7236,9 +7260,7 @@ class DcAgentCardDetailsComponent {
7236
7260
  card.conversationSettings = {};
7237
7261
  }
7238
7262
  this.agentCard.set(card);
7239
- if (card.assets?.motion?.url) {
7240
- this.videoPlayerService.setVideoSource(card.assets.motion.url);
7241
- }
7263
+ this.videoPlayerService.setAgentCard(card);
7242
7264
  if (card.assets.banner?.url) {
7243
7265
  this.chatMonitorService.setBackground(card.assets.banner.url);
7244
7266
  }
@@ -7274,13 +7296,7 @@ class DcAgentCardDetailsComponent {
7274
7296
  return [locale.replace('_', '-'), ...newVoiceParts].join('-');
7275
7297
  }
7276
7298
  startConversation() {
7277
- const defaultVideoUrl = this.agentCard()?.assets?.motion?.url;
7278
- this.videoPlayerService.startConversation(defaultVideoUrl);
7279
- const introMotion = this.agentCard()?.assets?.motions?.find((m) => m.metadata?.event === 'intro');
7280
- if (introMotion?.url) {
7281
- this.videoPlayerService.addVideosToQueue([introMotion.url]);
7282
- this.videoPlayerService.playAndRewind();
7283
- }
7299
+ this.videoPlayerService.startConversation();
7284
7300
  const targetLang = this.userService.getTargetLanguage();
7285
7301
  const translation = this.agentCard()?.characterCard?.data?.langTranslation?.[targetLang];
7286
7302
  if (this.agentCard()?.lang === targetLang) {