@chat21/chat21-web-widget 5.1.34 → 5.2.1

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.
Files changed (191) hide show
  1. package/.angular-mcp-cache/package.json +1 -0
  2. package/.cursor/angular18-accessibility-auditor-skill.md +442 -0
  3. package/.cursor/mcp.json +15 -0
  4. package/.github/workflows/playwright.yml +27 -0
  5. package/CHANGELOG.md +25 -0
  6. package/Dockerfile +4 -5
  7. package/README.md +1 -1
  8. package/angular.json +21 -3
  9. package/docs/ACCESSIBILITY-STATEMENT.md +388 -0
  10. package/docs/TILEDESK_WIDGET_ACCESSIBILITY_ALIGNMENT.md +60 -0
  11. package/docs/TILEDESK_WIDGET_ACCESSIBILITY_STATEMENT_COMPLETE.md +386 -0
  12. package/env.sample +3 -2
  13. package/mocks/voice-websocket-mock/server.cjs +245 -0
  14. package/package.json +10 -3
  15. package/playwright.config.ts +41 -0
  16. package/src/app/app.component.html +2 -2
  17. package/src/app/app.component.scss +25 -14
  18. package/src/app/app.component.spec.ts +21 -6
  19. package/src/app/app.module.ts +13 -0
  20. package/src/app/component/conversation-detail/conversation/conversation.component.html +25 -11
  21. package/src/app/component/conversation-detail/conversation/conversation.component.scss +38 -0
  22. package/src/app/component/conversation-detail/conversation/conversation.component.spec.ts +644 -75
  23. package/src/app/component/conversation-detail/conversation/conversation.component.ts +70 -2
  24. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.html +25 -13
  25. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.spec.ts +123 -5
  26. package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.ts +1 -0
  27. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.html +23 -10
  28. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.scss +18 -0
  29. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +241 -149
  30. package/src/app/component/conversation-detail/conversation-content/conversation-content.component.ts +8 -5
  31. package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.spec.ts +53 -3
  32. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.html +203 -110
  33. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.scss +212 -1
  34. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.spec.ts +458 -78
  35. package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +288 -76
  36. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.html +113 -53
  37. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.scss +12 -4
  38. package/src/app/component/conversation-detail/conversation-header/conversation-header.component.spec.ts +274 -29
  39. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.html +23 -9
  40. package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.spec.ts +80 -8
  41. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.html +29 -23
  42. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.spec.ts +185 -16
  43. package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts +34 -14
  44. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.html +46 -0
  45. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.scss +83 -0
  46. package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.ts +192 -0
  47. package/src/app/component/error-alert/error-alert.component.spec.ts +65 -5
  48. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.html +16 -7
  49. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.scss +21 -0
  50. package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.spec.ts +89 -7
  51. package/src/app/component/form/form-builder/form-builder.component.html +1 -1
  52. package/src/app/component/form/form-builder/form-builder.component.spec.ts +163 -21
  53. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.html +8 -4
  54. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.scss +10 -5
  55. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.spec.ts +90 -16
  56. package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.ts +26 -0
  57. package/src/app/component/form/inputs/form-label/form-label.component.spec.ts +45 -11
  58. package/src/app/component/form/inputs/form-radio-button/form-radio-button.component.spec.ts +24 -6
  59. package/src/app/component/form/inputs/form-select/form-select.component.spec.ts +14 -5
  60. package/src/app/component/form/inputs/form-text/form-text.component.html +14 -12
  61. package/src/app/component/form/inputs/form-text/form-text.component.scss +11 -1
  62. package/src/app/component/form/inputs/form-text/form-text.component.spec.ts +113 -17
  63. package/src/app/component/form/inputs/form-text/form-text.component.ts +35 -3
  64. package/src/app/component/form/inputs/form-textarea/form-textarea.component.html +13 -11
  65. package/src/app/component/form/inputs/form-textarea/form-textarea.component.scss +6 -5
  66. package/src/app/component/form/inputs/form-textarea/form-textarea.component.spec.ts +149 -13
  67. package/src/app/component/form/inputs/form-textarea/form-textarea.component.ts +26 -0
  68. package/src/app/component/form/prechat-form/prechat-form.component.html +14 -11
  69. package/src/app/component/form/prechat-form/prechat-form.component.spec.ts +102 -10
  70. package/src/app/component/form/prechat-form/prechat-form.component.ts +8 -1
  71. package/src/app/component/form/prechat-form-test-mock.ts +35 -0
  72. package/src/app/component/home/home.component.html +38 -31
  73. package/src/app/component/home/home.component.scss +4 -2
  74. package/src/app/component/home/home.component.spec.ts +226 -11
  75. package/src/app/component/home-conversations/home-conversations.component.html +30 -26
  76. package/src/app/component/home-conversations/home-conversations.component.scss +3 -0
  77. package/src/app/component/home-conversations/home-conversations.component.spec.ts +212 -36
  78. package/src/app/component/last-message/last-message.component.html +15 -9
  79. package/src/app/component/last-message/last-message.component.scss +16 -2
  80. package/src/app/component/last-message/last-message.component.spec.ts +204 -23
  81. package/src/app/component/launcher-button/launcher-button.component.html +8 -13
  82. package/src/app/component/launcher-button/launcher-button.component.spec.ts +104 -8
  83. package/src/app/component/list-all-conversations/list-all-conversations.component.html +12 -17
  84. package/src/app/component/list-all-conversations/list-all-conversations.component.scss +2 -0
  85. package/src/app/component/list-conversations/list-conversations.component.html +22 -22
  86. package/src/app/component/menu-options/menu-options.component.html +30 -20
  87. package/src/app/component/menu-options/menu-options.component.spec.ts +125 -9
  88. package/src/app/component/message/audio/audio.component.html +13 -15
  89. package/src/app/component/message/audio/audio.component.spec.ts +140 -5
  90. package/src/app/component/message/audio/audio.component.ts +1 -5
  91. package/src/app/component/message/audio-sync/audio-sync.component.html +18 -0
  92. package/src/app/component/message/audio-sync/audio-sync.component.scss +65 -0
  93. package/src/app/component/message/audio-sync/audio-sync.component.spec.ts +112 -0
  94. package/src/app/component/message/audio-sync/audio-sync.component.ts +714 -0
  95. package/src/app/component/message/avatar/avatar.component.html +2 -2
  96. package/src/app/component/message/avatar/avatar.component.spec.ts +99 -7
  97. package/src/app/component/message/bubble-message/bubble-message.component.html +41 -51
  98. package/src/app/component/message/bubble-message/bubble-message.component.scss +54 -1
  99. package/src/app/component/message/bubble-message/bubble-message.component.spec.ts +147 -57
  100. package/src/app/component/message/bubble-message/bubble-message.component.ts +95 -13
  101. package/src/app/component/message/buttons/action-button/action-button.component.html +3 -4
  102. package/src/app/component/message/buttons/action-button/action-button.component.spec.ts +49 -5
  103. package/src/app/component/message/buttons/link-button/link-button.component.scss +5 -8
  104. package/src/app/component/message/buttons/link-button/link-button.component.spec.ts +50 -5
  105. package/src/app/component/message/buttons/text-button/text-button.component.spec.ts +44 -5
  106. package/src/app/component/message/carousel/carousel.component.html +29 -16
  107. package/src/app/component/message/carousel/carousel.component.scss +20 -8
  108. package/src/app/component/message/carousel/carousel.component.spec.ts +80 -3
  109. package/src/app/component/message/carousel/carousel.component.ts +16 -0
  110. package/src/app/component/message/frame/frame.component.html +9 -4
  111. package/src/app/component/message/frame/frame.component.spec.ts +34 -15
  112. package/src/app/component/message/frame/frame.component.ts +7 -2
  113. package/src/app/component/message/html/html.component.html +1 -1
  114. package/src/app/component/message/html/html.component.scss +1 -1
  115. package/src/app/component/message/html/html.component.spec.ts +24 -7
  116. package/src/app/component/message/image/image.component.html +12 -10
  117. package/src/app/component/message/image/image.component.scss +16 -0
  118. package/src/app/component/message/image/image.component.spec.ts +101 -15
  119. package/src/app/component/message/image/image.component.ts +90 -51
  120. package/src/app/component/message/info-message/info-message.component.spec.ts +26 -14
  121. package/src/app/component/message/json-sources/json-sources.component.html +6 -5
  122. package/src/app/component/message/json-sources/json-sources.component.scss +26 -18
  123. package/src/app/component/message/json-sources/json-sources.component.ts +41 -0
  124. package/src/app/component/message/like-unlike/like-unlike.component.html +7 -9
  125. package/src/app/component/message/like-unlike/like-unlike.component.spec.ts +31 -3
  126. package/src/app/component/message/return-receipt/return-receipt.component.spec.ts +38 -17
  127. package/src/app/component/message/text/text.component.html +3 -3
  128. package/src/app/component/message/text/text.component.scss +80 -86
  129. package/src/app/component/message/text/text.component.spec.ts +106 -13
  130. package/src/app/component/message-attachment/message-attachment.component.spec.ts +134 -13
  131. package/src/app/component/selection-department/selection-department.component.html +21 -23
  132. package/src/app/component/selection-department/selection-department.component.spec.ts +159 -14
  133. package/src/app/component/selection-department/selection-department.component.ts +8 -1
  134. package/src/app/component/send-button/send-button.component.html +5 -13
  135. package/src/app/component/send-button/send-button.component.spec.ts +2 -2
  136. package/src/app/component/star-rating-widget/star-rating-widget.component.html +51 -81
  137. package/src/app/directives/tooltip.directive.spec.ts +8 -4
  138. package/src/app/modals/confirm-close/confirm-close.component.html +20 -8
  139. package/src/app/modals/confirm-close/confirm-close.component.scss +3 -0
  140. package/src/app/modals/confirm-close/confirm-close.component.spec.ts +13 -4
  141. package/src/app/modals/confirm-close/confirm-close.component.ts +8 -1
  142. package/src/app/pipe/html-entites-encode.pipe.spec.ts +35 -2
  143. package/src/app/pipe/marked.pipe.spec.ts +38 -2
  144. package/src/app/pipe/marked.pipe.ts +51 -41
  145. package/src/app/providers/app-config.service.ts +4 -2
  146. package/src/app/providers/brand.service.spec.ts +23 -2
  147. package/src/app/providers/brand.service.ts +1 -1
  148. package/src/app/providers/global-settings.service.spec.ts +1009 -14
  149. package/src/app/providers/global-settings.service.ts +40 -2
  150. package/src/app/providers/json-sources-parser.service.ts +13 -1
  151. package/src/app/providers/translator.service.ts +24 -7
  152. package/src/app/providers/tts-audio-playback-coordinator.service.spec.ts +116 -0
  153. package/src/app/providers/tts-audio-playback-coordinator.service.ts +122 -0
  154. package/src/app/providers/voice/STT&TTS/openai-voice.config.ts +12 -0
  155. package/src/app/providers/voice/STT&TTS/openai-voice.provider.ts +156 -0
  156. package/src/app/providers/voice/STT&TTS/speech-provider.abstract.ts +39 -0
  157. package/src/app/providers/voice/audio.types.ts +40 -0
  158. package/src/app/providers/voice/vad.service.spec.ts +28 -0
  159. package/src/app/providers/voice/vad.service.ts +70 -0
  160. package/src/app/providers/voice/voice-streaming.service.spec.ts +23 -0
  161. package/src/app/providers/voice/voice-streaming.service.ts +702 -0
  162. package/src/app/providers/voice/voice-streaming.types.ts +112 -0
  163. package/src/app/providers/voice/voice.service.spec.ts +227 -0
  164. package/src/app/providers/voice/voice.service.ts +969 -0
  165. package/src/app/sass/_variables.scss +2 -0
  166. package/src/app/sass/animations.scss +19 -1
  167. package/src/app/shims/onnxruntime-web-wasm.ts +4 -0
  168. package/src/app/utils/globals.ts +14 -0
  169. package/src/app/utils/utils-resources.ts +1 -1
  170. package/src/assets/i18n/en.json +128 -100
  171. package/src/assets/i18n/es.json +128 -100
  172. package/src/assets/i18n/fr.json +128 -100
  173. package/src/assets/i18n/it.json +128 -98
  174. package/src/assets/onnx/ort-wasm-simd-threaded.mjs +59 -0
  175. package/src/assets/onnx/ort-wasm-simd-threaded.wasm +0 -0
  176. package/src/assets/sounds/keyboard.mp3 +0 -0
  177. package/src/assets/vad/silero_vad_legacy.onnx +0 -0
  178. package/src/assets/vad/vad.worklet.bundle.min.js +1 -0
  179. package/src/chat21-core/models/message.ts +2 -1
  180. package/src/chat21-core/providers/chat-manager.spec.ts +72 -0
  181. package/src/chat21-core/providers/firebase/firebase-conversation-handler.ts +3 -2
  182. package/src/chat21-core/providers/firebase/firebase-init-service.ts +5 -5
  183. package/src/chat21-core/providers/mqtt/mqtt-conversation-handler.ts +12 -0
  184. package/src/chat21-core/providers/scripts/script.service.spec.ts +12 -2
  185. package/src/chat21-core/utils/utils-message.ts +7 -0
  186. package/src/widget-config-template.json +3 -1
  187. package/src/widget-config.json +28 -27
  188. package/tests/widget-form-rich.spec.ts +67 -0
  189. package/tests/widget-index-dev-settings.spec.ts +52 -0
  190. package/tests/widget-twp-iframe.spec.ts +39 -0
  191. package/tsconfig.json +5 -0
@@ -1,23 +1,158 @@
1
1
  import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
3
+ import { CustomLogger } from 'src/chat21-core/providers/logger/customLogger';
4
+ import { NGXLogger } from 'ngx-logger';
2
5
 
3
6
  import { AudioComponent } from './audio.component';
4
7
 
5
- describe('AudioTrackComponent', () => {
8
+ describe('AudioComponent', () => {
6
9
  let component: AudioComponent;
7
10
  let fixture: ComponentFixture<AudioComponent>;
11
+ const ngxlogger = jasmine.createSpyObj('NGXLogger', ['log', 'trace', 'debug', 'warn', 'error', 'info']);
12
+ const customLogger = new CustomLogger(ngxlogger);
13
+ const arrayBuf = new ArrayBuffer(64);
14
+
15
+ const fakeBuffer = {
16
+ duration: 90,
17
+ getChannelData: () => new Float32Array(4000),
18
+ } as unknown as AudioBuffer;
8
19
 
9
20
  beforeEach(async () => {
21
+ LoggerInstance.setInstance(customLogger);
22
+ spyOn(window, 'fetch').and.returnValue(
23
+ Promise.resolve({
24
+ arrayBuffer: () => Promise.resolve(arrayBuf),
25
+ } as Response),
26
+ );
27
+ spyOn(AudioContext.prototype, 'decodeAudioData').and.returnValue(Promise.resolve(fakeBuffer));
28
+
10
29
  await TestBed.configureTestingModule({
11
- declarations: [ AudioComponent ]
30
+ declarations: [AudioComponent],
12
31
  })
13
- .compileComponents();
32
+ .overrideComponent(AudioComponent, {
33
+ set: {
34
+ template: `
35
+ <div class="audio-container">
36
+ <div class="audio-track"></div>
37
+ <div class="audio-player-custom">
38
+ <audio #audioElement></audio>
39
+ <canvas #canvasElement width="120" height="32"></canvas>
40
+ </div>
41
+ </div>`,
42
+ },
43
+ })
44
+ .compileComponents();
14
45
 
15
46
  fixture = TestBed.createComponent(AudioComponent);
16
47
  component = fixture.componentInstance;
17
- fixture.detectChanges();
48
+ component.stylesMap = new Map<string, string>([
49
+ ['bubbleSentBackground', 'rgba(10, 20, 30, 1)'],
50
+ ['bubbleSentTextColor', '#112233'],
51
+ ]);
52
+ component.color = '#000000';
18
53
  });
19
54
 
20
- it('should create', () => {
55
+ it('should create', async () => {
56
+ const blob = new Blob([new Uint8Array(arrayBuf.byteLength)], { type: 'audio/wav' });
57
+ component.audioBlob = blob;
58
+ fixture.detectChanges();
59
+ await fixture.whenStable();
60
+ fixture.detectChanges();
21
61
  expect(component).toBeTruthy();
22
62
  });
63
+
64
+ it('formatTime should pad seconds under 10', () => {
65
+ expect(component.formatTime(0)).toBe('0:00');
66
+ expect(component.formatTime(9)).toBe('0:09');
67
+ expect(component.formatTime(70)).toBe('1:10');
68
+ });
69
+
70
+ it('extractFirstColor should parse first rgba from gradient string', () => {
71
+ expect(component.extractFirstColor('linear-gradient(rgba(1, 2, 3, 0.5), red)')).toBe('rgba(1, 2, 3, 0.5)');
72
+ expect(component.extractFirstColor('no-color')).toBeNull();
73
+ });
74
+
75
+ it('drawWaveform should return early when canvas context missing', () => {
76
+ const canvas = document.createElement('canvas');
77
+ spyOn(canvas, 'getContext').and.returnValue(null);
78
+ (component as any).waveformCanvas = { nativeElement: canvas };
79
+ (component as any).audioBuffer = fakeBuffer;
80
+ (component as any).audioDuration = 10;
81
+ (component as any).audioElement = {
82
+ nativeElement: { currentTime: 0, paused: true },
83
+ };
84
+ expect(() => component.drawWaveform(fakeBuffer)).not.toThrow();
85
+ });
86
+
87
+ it('drawWaveform should render bars when context exists', () => {
88
+ const fillRect = jasmine.createSpy('fillRect');
89
+ const clearRect = jasmine.createSpy('clearRect');
90
+ const canvas = document.createElement('canvas');
91
+ canvas.width = 200;
92
+ canvas.height = 40;
93
+ spyOn(canvas, 'getContext').and.returnValue({ fillRect, clearRect } as any);
94
+ (component as any).waveformCanvas = { nativeElement: canvas };
95
+ (component as any).audioElement = {
96
+ nativeElement: { currentTime: 0, paused: true },
97
+ };
98
+ (component as any).audioDuration = 10;
99
+ component.drawWaveform(fakeBuffer);
100
+ expect(clearRect).toHaveBeenCalled();
101
+ expect(fillRect).toHaveBeenCalled();
102
+ });
103
+
104
+ it('ngAfterViewInit with blob should wire object URL and CSS vars', async () => {
105
+ const blob = new Blob([new Uint8Array(128)], { type: 'audio/wav' });
106
+ component.audioBlob = blob;
107
+ spyOn(URL, 'createObjectURL').and.returnValue('blob:mock-audio');
108
+ fixture.detectChanges();
109
+ await fixture.whenStable();
110
+ fixture.detectChanges();
111
+ expect(component.rawAudioUrl).toBe('blob:mock-audio');
112
+ expect(URL.createObjectURL).toHaveBeenCalledWith(blob);
113
+ });
114
+
115
+ it('ngAfterViewInit with metadata.src should fetch and decode', async () => {
116
+ component.audioBlob = null;
117
+ component.metadata = { src: 'blob:from-meta' };
118
+ fixture.detectChanges();
119
+ await fixture.whenStable();
120
+ fixture.detectChanges();
121
+ expect(window.fetch).toHaveBeenCalled();
122
+ expect(component.audioDuration).toBe(90);
123
+ });
124
+
125
+ it('playPauseAudio should toggle play state when buffer ready', () => {
126
+ spyOn(window, 'requestAnimationFrame').and.stub();
127
+ (component as any).audioBuffer = fakeBuffer;
128
+ (component as any).audioDuration = 10;
129
+ const play = jasmine.createSpy('play').and.returnValue(Promise.resolve());
130
+ const pause = jasmine.createSpy('pause');
131
+ const canvas = document.createElement('canvas');
132
+ canvas.width = 120;
133
+ canvas.height = 32;
134
+ spyOn(canvas, 'getContext').and.returnValue({
135
+ fillRect: jasmine.createSpy(),
136
+ clearRect: jasmine.createSpy(),
137
+ } as any);
138
+ (component as any).waveformCanvas = { nativeElement: canvas };
139
+ (component as any).audioElement = {
140
+ nativeElement: { paused: true, currentTime: 0, play, pause, ontimeupdate: null as any, onended: null as any },
141
+ };
142
+ (component as any).audioContext = { resume: jasmine.createSpy().and.returnValue(Promise.resolve()) };
143
+
144
+ component.playPauseAudio();
145
+ expect(play).toHaveBeenCalled();
146
+ expect(component.isPlaying).toBe(true);
147
+
148
+ (component as any).audioElement.nativeElement.paused = false;
149
+ component.playPauseAudio();
150
+ expect(pause).toHaveBeenCalled();
151
+ });
152
+
153
+ it('getAudioDuration should set audioDuration from decoded buffer', async () => {
154
+ component.metadata = { src: 'blob:x' };
155
+ await component.getAudioDuration();
156
+ expect(component.audioDuration).toBe(90);
157
+ });
23
158
  });
@@ -18,6 +18,7 @@ export class AudioComponent implements AfterViewInit {
18
18
  @Input() metadata: any | null = null;
19
19
  @Input() color: string;
20
20
  @Input() stylesMap: Map<string, string>;
21
+ @Input() translationMap: Map<string, string>;
21
22
 
22
23
  audioUrl: SafeUrl | null = null;
23
24
  rawAudioUrl: string | null = null;
@@ -154,15 +155,10 @@ export class AudioComponent implements AfterViewInit {
154
155
  // });
155
156
 
156
157
  const response = await fetch(this.rawAudioUrl!);
157
- this.logger.debug('getAudioDuration: response ---> ', response)
158
158
  const arrayBuffer = await response.arrayBuffer();
159
- this.logger.debug('getAudioDuration: arrayBuffer ---> ', arrayBuffer)
160
159
  const audioContext = new (window.AudioContext || (window as any).webkitAudioContext)();
161
- this.logger.debug('getAudioDuration: audioContext ---> ', audioContext)
162
160
  const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
163
- this.logger.debug('getAudioDuration: audioBuffer ---> ', audioBuffer)
164
161
  this.audioDuration = audioBuffer.duration;
165
- this.logger.debug('getAudioDuration: audioDuration ---> ', this.audioDuration)
166
162
 
167
163
  }
168
164
 
@@ -0,0 +1,18 @@
1
+ <div class="lyrics-container">
2
+
3
+ <audio
4
+ #audioPlayer
5
+ (timeupdate)="onTimeUpdate()"
6
+ style="display:none">
7
+ </audio>
8
+
9
+ <p class="lyrics message_innerhtml marked" #transcriptBox [style.color]="color">
10
+ <span
11
+ *ngFor="let w of words; let i = index; trackBy: trackByIndex"
12
+ class="word"
13
+ [ngClass]="w.state">
14
+ {{ w.text }}
15
+ </span>
16
+ </p>
17
+
18
+ </div>
@@ -0,0 +1,65 @@
1
+ :host {
2
+ display: block;
3
+ font-size: var(--font-size-bubble-message, 14px);
4
+ }
5
+
6
+ /* Allineato a text.component.scss (.message_innerhtml, p) */
7
+ .message_innerhtml {
8
+ margin: 0;
9
+
10
+ &.marked {
11
+ padding: 12px 16px;
12
+ margin-block-start: 0em !important;
13
+ margin-block-end: 0em !important;
14
+ }
15
+ }
16
+
17
+ .lyrics {
18
+ font-size: inherit;
19
+ margin: 0;
20
+ // line-height: 1.4em;
21
+ font-style: normal;
22
+ letter-spacing: normal;
23
+ font-stretch: normal;
24
+ font-variant: normal;
25
+ font-weight: 300;
26
+ overflow: hidden;
27
+
28
+ display: flex;
29
+ flex-wrap: wrap;
30
+ gap: 6px;
31
+ /* Colore bubble: da [style.color] / @Input() color — ereditato dalle .word */
32
+ }
33
+
34
+ /* base word */
35
+ .word {
36
+ transition:
37
+ transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
38
+ color 0.3s ease,
39
+ opacity 0.3s ease,
40
+ filter 0.3s ease;
41
+
42
+ will-change: transform;
43
+ }
44
+
45
+ /* FUTURE */
46
+ .word.future {
47
+ opacity: 0;
48
+ transform: scale(0.98);
49
+ }
50
+
51
+ /* PAST: stesso colore del testo bubble (@Input color sul <p>) */
52
+ .word.past {
53
+ opacity: 1;
54
+ color: inherit;
55
+ transform: scale(1);
56
+ }
57
+
58
+ /* ACTIVE (solo momentaneo, tipo “karaoke flash”) */
59
+ .word.active {
60
+ opacity: 1;
61
+ color: #00c3ff;
62
+ font-weight: 700;
63
+ transform: scale(1.18);
64
+ text-shadow: 0 0 10px rgba(0, 195, 255, 0.35);
65
+ }
@@ -0,0 +1,112 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
3
+ import { Subject } from 'rxjs';
4
+
5
+ import { AudioSyncComponent } from './audio-sync.component';
6
+ import { TtsAudioPlaybackCoordinator } from 'src/app/providers/tts-audio-playback-coordinator.service';
7
+ import { VoiceService } from 'src/app/providers/voice/voice.service';
8
+ import { Globals } from 'src/app/utils/globals';
9
+
10
+ describe('AudioSyncComponent', () => {
11
+ let component: AudioSyncComponent;
12
+ let fixture: ComponentFixture<AudioSyncComponent>;
13
+ let voiceService: {
14
+ proxyTtsStreamUrl: string | null;
15
+ proxyTtsUrl: string | null;
16
+ speechStart$: ReturnType<Subject<void>['asObservable']>;
17
+ };
18
+
19
+ beforeEach(async () => {
20
+ const speechStartSource = new Subject<void>();
21
+ const cancelAllSource = new Subject<void>();
22
+ const stopAllSource = new Subject<void>();
23
+ const preemptSource = new Subject<string>();
24
+
25
+ voiceService = {
26
+ proxyTtsStreamUrl: 'https://speech.example.com/api/tts/stream',
27
+ proxyTtsUrl: 'https://speech.example.com/api/tts',
28
+ speechStart$: speechStartSource.asObservable(),
29
+ };
30
+
31
+ await TestBed.configureTestingModule({
32
+ declarations: [AudioSyncComponent],
33
+ imports: [CommonModule],
34
+ providers: [
35
+ {
36
+ provide: TtsAudioPlaybackCoordinator,
37
+ useValue: {
38
+ requestStart: (_ownerId: string, start: () => void) => start(),
39
+ releaseIfCurrent: jasmine.createSpy('releaseIfCurrent'),
40
+ release: jasmine.createSpy('release'),
41
+ stopAllPlayback$: stopAllSource.asObservable(),
42
+ preemptPlayback$: preemptSource.asObservable(),
43
+ cancelAll$: cancelAllSource.asObservable(),
44
+ },
45
+ },
46
+ { provide: Globals, useValue: { tiledeskToken: 'JWT test-token', jwt: '' } },
47
+ { provide: VoiceService, useValue: voiceService },
48
+ ],
49
+ }).compileComponents();
50
+
51
+ fixture = TestBed.createComponent(AudioSyncComponent);
52
+ component = fixture.componentInstance;
53
+ fixture.detectChanges();
54
+ });
55
+
56
+ it('should create', () => {
57
+ expect(component).toBeTruthy();
58
+ });
59
+
60
+ it('starts TTS playback from the proxy streaming endpoint first', () => {
61
+ component.message = {
62
+ uid: 'm1',
63
+ type: 'tts',
64
+ text: 'hello',
65
+ metadata: {},
66
+ isJustRecived: true,
67
+ } as any;
68
+ const audio = document.createElement('audio');
69
+ const startStreaming = spyOn(component as any, 'startStreamingFromEndpoint').and.stub();
70
+
71
+ (component as any).startPlayback(audio);
72
+
73
+ expect(startStreaming).toHaveBeenCalledWith(
74
+ audio,
75
+ 'https://speech.example.com/api/tts/stream',
76
+ 'https://speech.example.com/api/tts',
77
+ undefined,
78
+ );
79
+ });
80
+
81
+ it('requests browser-compatible MP3 for proxy REST TTS by default', () => {
82
+ component.message = {
83
+ uid: 'm1',
84
+ type: 'tts',
85
+ text: 'hello',
86
+ metadata: {},
87
+ } as any;
88
+
89
+ const body = (component as any).buildTtsRequestBody({});
90
+
91
+ expect(body).toEqual({
92
+ text: 'hello',
93
+ outputFormat: 'mp3_44100_128',
94
+ });
95
+ });
96
+
97
+ it('does not override an explicit TTS outputFormat from message voice settings', () => {
98
+ component.message = {
99
+ uid: 'm1',
100
+ type: 'tts',
101
+ text: 'hello',
102
+ metadata: {},
103
+ } as any;
104
+
105
+ const body = (component as any).buildTtsRequestBody({ outputFormat: 'pcm_16000' });
106
+
107
+ expect(body).toEqual({
108
+ text: 'hello',
109
+ outputFormat: 'pcm_16000',
110
+ });
111
+ });
112
+ });