@chat21/chat21-web-widget 5.1.32-rc9 → 5.1.33-rc11
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/.angular-mcp-cache/package.json +1 -0
- package/.cursor/angular18-accessibility-auditor-skill.md +442 -0
- package/.cursor/mcp.json +15 -0
- package/.github/workflows/playwright.yml +27 -0
- package/.playwright-mcp/console-2026-05-08T15-31-09-000Z.log +17 -0
- package/.playwright-mcp/console-2026-05-08T15-32-19-412Z.log +89 -0
- package/.playwright-mcp/console-2026-05-08T16-18-48-424Z.log +133 -0
- package/.playwright-mcp/console-2026-05-11T12-54-06-869Z.log +13 -0
- package/.playwright-mcp/console-2026-05-11T12-54-56-229Z.log +147 -0
- package/.playwright-mcp/console-2026-05-11T12-55-47-174Z.log +183 -0
- package/.playwright-mcp/console-2026-05-11T15-34-03-590Z.log +210 -0
- package/.playwright-mcp/console-2026-05-12T15-07-31-880Z.log +118 -0
- package/.playwright-mcp/page-2026-05-08T15-32-19-900Z.yml +851 -0
- package/.playwright-mcp/page-2026-05-08T15-32-47-264Z.yml +857 -0
- package/.playwright-mcp/page-2026-05-08T15-33-17-089Z.yml +1110 -0
- package/.playwright-mcp/page-2026-05-08T15-33-23-486Z.yml +1069 -0
- package/.playwright-mcp/page-2026-05-08T15-33-45-390Z.yml +1076 -0
- package/.playwright-mcp/page-2026-05-08T15-33-52-666Z.yml +1072 -0
- package/.playwright-mcp/page-2026-05-08T15-34-01-338Z.yml +1085 -0
- package/.playwright-mcp/page-2026-05-08T15-34-07-227Z.yml +1072 -0
- package/.playwright-mcp/page-2026-05-08T15-34-13-875Z.yml +1072 -0
- package/.playwright-mcp/page-2026-05-08T15-34-21-885Z.yml +1109 -0
- package/.playwright-mcp/page-2026-05-08T15-34-32-755Z.yml +1109 -0
- package/.playwright-mcp/page-2026-05-08T15-35-09-607Z.yml +1119 -0
- package/.playwright-mcp/page-2026-05-08T15-35-14-242Z.yml +1109 -0
- package/.playwright-mcp/page-2026-05-08T16-18-48-671Z.yml +44 -0
- package/.playwright-mcp/page-2026-05-08T16-18-52-753Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-19-13-919Z.yml +68 -0
- package/.playwright-mcp/page-2026-05-08T16-19-17-977Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-19-25-733Z.yml +120 -0
- package/.playwright-mcp/page-2026-05-08T16-19-29-252Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-19-39-269Z.yml +80 -0
- package/.playwright-mcp/page-2026-05-08T16-19-43-915Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-20-04-407Z.yml +81 -0
- package/.playwright-mcp/page-2026-05-08T16-20-08-984Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-20-32-397Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-20-58-658Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-21-12-320Z.yml +86 -0
- package/.playwright-mcp/page-2026-05-08T16-21-39-154Z.yml +91 -0
- package/.playwright-mcp/page-2026-05-08T16-21-45-420Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-22-21-062Z.yml +0 -0
- package/.playwright-mcp/page-2026-05-08T16-22-58-232Z.yml +91 -0
- package/.playwright-mcp/page-2026-05-08T16-23-36-520Z.yml +0 -0
- package/.playwright-mcp/page-2026-05-08T16-23-46-805Z.yml +100 -0
- package/.playwright-mcp/page-2026-05-08T16-23-55-169Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-24-26-574Z.yml +91 -0
- package/.playwright-mcp/page-2026-05-08T16-25-34-414Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-25-59-831Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-26-21-809Z.yml +91 -0
- package/.playwright-mcp/page-2026-05-08T16-26-47-443Z.yml +105 -0
- package/.playwright-mcp/page-2026-05-08T16-26-56-136Z.png +0 -0
- package/.playwright-mcp/page-2026-05-08T16-27-59-610Z.yml +48 -0
- package/.playwright-mcp/page-2026-05-11T12-54-07-180Z.yml +44 -0
- package/.playwright-mcp/page-2026-05-11T12-54-56-946Z.yml +4 -0
- package/.playwright-mcp/page-2026-05-11T12-55-47-503Z.yml +24 -0
- package/.playwright-mcp/page-2026-05-11T12-56-00-766Z.yml +28 -0
- package/.playwright-mcp/page-2026-05-11T12-56-06-438Z.yml +90 -0
- package/.playwright-mcp/page-2026-05-11T12-57-56-838Z.yml +106 -0
- package/.playwright-mcp/page-2026-05-11T12-58-00-124Z.yml +106 -0
- package/.playwright-mcp/page-2026-05-11T12-59-08-836Z.yml +61 -0
- package/.playwright-mcp/page-2026-05-11T12-59-12-088Z.yml +61 -0
- package/.playwright-mcp/page-2026-05-11T12-59-26-215Z.yml +69 -0
- package/.playwright-mcp/page-2026-05-11T12-59-29-519Z.yml +69 -0
- package/.playwright-mcp/page-2026-05-11T12-59-37-309Z.yml +0 -0
- package/.playwright-mcp/page-2026-05-11T12-59-39-968Z.yml +79 -0
- package/.playwright-mcp/page-2026-05-11T12-59-45-983Z.yml +78 -0
- package/.playwright-mcp/page-2026-05-11T12-59-49-951Z.yml +78 -0
- package/.playwright-mcp/page-2026-05-11T15-34-04-515Z.yml +0 -0
- package/.playwright-mcp/page-2026-05-12T15-07-32-171Z.yml +44 -0
- package/.playwright-mcp/page-2026-05-12T15-08-09-820Z.yml +119 -0
- package/CHANGELOG.md +61 -4
- package/angular.json +20 -3
- package/deploy_amazon_beta.sh +7 -17
- package/deploy_amazon_prod.sh +41 -0
- package/docs/TILEDESK_WIDGET_ACCESSIBILITY_STATEMENT_COMPLETE.md +379 -0
- package/env.sample +3 -2
- package/mocks/voice-websocket-mock/server.cjs +245 -0
- package/package.json +7 -3
- package/playwright.config.ts +41 -0
- package/src/app/app.component.html +2 -2
- package/src/app/app.component.scss +25 -14
- package/src/app/app.component.spec.ts +21 -6
- package/src/app/app.module.ts +4 -0
- package/src/app/component/conversation-detail/conversation/conversation.component.html +19 -11
- package/src/app/component/conversation-detail/conversation/conversation.component.scss +28 -0
- package/src/app/component/conversation-detail/conversation/conversation.component.spec.ts +644 -75
- package/src/app/component/conversation-detail/conversation/conversation.component.ts +63 -17
- package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.html +25 -13
- package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.spec.ts +123 -5
- package/src/app/component/conversation-detail/conversation-audio-recorder/conversation-audio-recorder.component.ts +1 -0
- package/src/app/component/conversation-detail/conversation-content/conversation-content.component.html +17 -7
- package/src/app/component/conversation-detail/conversation-content/conversation-content.component.scss +15 -3
- package/src/app/component/conversation-detail/conversation-content/conversation-content.component.spec.ts +242 -149
- package/src/app/component/conversation-detail/conversation-content/conversation-content.component.ts +7 -6
- package/src/app/component/conversation-detail/conversation-emojii/conversation-emojii.component.spec.ts +53 -3
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component copy.html +172 -0
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.html +112 -61
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.scss +133 -16
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.spec.ts +452 -78
- package/src/app/component/conversation-detail/conversation-footer/conversation-footer.component.ts +198 -84
- package/src/app/component/conversation-detail/conversation-header/conversation-header.component.html +113 -53
- package/src/app/component/conversation-detail/conversation-header/conversation-header.component.scss +12 -4
- package/src/app/component/conversation-detail/conversation-header/conversation-header.component.spec.ts +274 -29
- package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.html +23 -9
- package/src/app/component/conversation-detail/conversation-internal-frame/conversation-internal-frame.component.spec.ts +80 -8
- package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.html +29 -23
- package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.spec.ts +185 -16
- package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts +34 -14
- package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.html +46 -18
- package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.scss +60 -2
- package/src/app/component/conversation-detail/stream-audio-spectrum/stream-audio-spectrum.component.ts +135 -5
- package/src/app/component/error-alert/error-alert.component.spec.ts +65 -5
- package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.html +16 -7
- package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.scss +21 -0
- package/src/app/component/eyeeye-catcher-card/eyeeye-catcher-card.component.spec.ts +89 -7
- package/src/app/component/form/form-builder/form-builder.component.html +1 -1
- package/src/app/component/form/form-builder/form-builder.component.spec.ts +163 -21
- package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.html +8 -4
- package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.scss +10 -5
- package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.spec.ts +90 -16
- package/src/app/component/form/inputs/form-checkbox/form-checkbox.component.ts +26 -0
- package/src/app/component/form/inputs/form-label/form-label.component.spec.ts +45 -11
- package/src/app/component/form/inputs/form-radio-button/form-radio-button.component.spec.ts +24 -6
- package/src/app/component/form/inputs/form-select/form-select.component.spec.ts +14 -5
- package/src/app/component/form/inputs/form-text/form-text.component.html +14 -12
- package/src/app/component/form/inputs/form-text/form-text.component.scss +11 -1
- package/src/app/component/form/inputs/form-text/form-text.component.spec.ts +113 -17
- package/src/app/component/form/inputs/form-text/form-text.component.ts +35 -3
- package/src/app/component/form/inputs/form-textarea/form-textarea.component.html +13 -11
- package/src/app/component/form/inputs/form-textarea/form-textarea.component.scss +6 -5
- package/src/app/component/form/inputs/form-textarea/form-textarea.component.spec.ts +149 -13
- package/src/app/component/form/inputs/form-textarea/form-textarea.component.ts +26 -0
- package/src/app/component/form/prechat-form/prechat-form.component.html +14 -11
- package/src/app/component/form/prechat-form/prechat-form.component.spec.ts +102 -10
- package/src/app/component/form/prechat-form/prechat-form.component.ts +8 -1
- package/src/app/component/form/prechat-form-test-mock.ts +35 -0
- package/src/app/component/home/home.component.html +38 -31
- package/src/app/component/home/home.component.scss +4 -2
- package/src/app/component/home/home.component.spec.ts +226 -11
- package/src/app/component/home-conversations/home-conversations.component.html +30 -26
- package/src/app/component/home-conversations/home-conversations.component.scss +3 -0
- package/src/app/component/home-conversations/home-conversations.component.spec.ts +212 -36
- package/src/app/component/last-message/last-message.component.html +15 -9
- package/src/app/component/last-message/last-message.component.scss +16 -2
- package/src/app/component/last-message/last-message.component.spec.ts +204 -23
- package/src/app/component/launcher-button/launcher-button.component.html +8 -13
- package/src/app/component/launcher-button/launcher-button.component.spec.ts +104 -8
- package/src/app/component/list-all-conversations/list-all-conversations.component.html +12 -17
- package/src/app/component/list-all-conversations/list-all-conversations.component.scss +2 -0
- package/src/app/component/list-conversations/list-conversations.component.html +22 -22
- package/src/app/component/menu-options/menu-options.component.html +30 -20
- package/src/app/component/menu-options/menu-options.component.spec.ts +125 -9
- package/src/app/component/message/audio/audio.component.html +13 -15
- package/src/app/component/message/audio/audio.component.spec.ts +140 -5
- package/src/app/component/message/audio/audio.component.ts +1 -0
- package/src/app/component/message/audio-sync/audio-sync.component.scss +1 -0
- package/src/app/component/message/audio-sync/audio-sync.component.spec.ts +81 -1
- package/src/app/component/message/audio-sync/audio-sync.component.ts +133 -86
- package/src/app/component/message/avatar/avatar.component.html +2 -2
- package/src/app/component/message/avatar/avatar.component.spec.ts +99 -7
- package/src/app/component/message/bubble-message/bubble-message.component.html +39 -52
- package/src/app/component/message/bubble-message/bubble-message.component.scss +59 -1
- package/src/app/component/message/bubble-message/bubble-message.component.spec.ts +154 -57
- package/src/app/component/message/bubble-message/bubble-message.component.ts +152 -110
- package/src/app/component/message/buttons/action-button/action-button.component.html +3 -4
- package/src/app/component/message/buttons/action-button/action-button.component.spec.ts +49 -5
- package/src/app/component/message/buttons/link-button/link-button.component.scss +5 -8
- package/src/app/component/message/buttons/link-button/link-button.component.spec.ts +50 -5
- package/src/app/component/message/buttons/text-button/text-button.component.spec.ts +44 -5
- package/src/app/component/message/carousel/carousel.component.html +29 -16
- package/src/app/component/message/carousel/carousel.component.scss +20 -8
- package/src/app/component/message/carousel/carousel.component.spec.ts +80 -3
- package/src/app/component/message/carousel/carousel.component.ts +16 -0
- package/src/app/component/message/frame/frame.component.html +9 -4
- package/src/app/component/message/frame/frame.component.spec.ts +34 -15
- package/src/app/component/message/frame/frame.component.ts +7 -2
- package/src/app/component/message/html/html.component.html +1 -1
- package/src/app/component/message/html/html.component.scss +1 -1
- package/src/app/component/message/html/html.component.spec.ts +24 -7
- package/src/app/component/message/image/image.component.html +12 -10
- package/src/app/component/message/image/image.component.scss +16 -0
- package/src/app/component/message/image/image.component.spec.ts +101 -15
- package/src/app/component/message/image/image.component.ts +90 -51
- package/src/app/component/message/info-message/info-message.component.spec.ts +26 -14
- package/src/app/component/message/json-sources/json-sources.component.html +38 -0
- package/src/app/component/message/json-sources/json-sources.component.scss +201 -0
- package/src/app/component/message/json-sources/json-sources.component.ts +89 -0
- package/src/app/component/message/like-unlike/like-unlike.component.html +7 -9
- package/src/app/component/message/like-unlike/like-unlike.component.spec.ts +31 -3
- package/src/app/component/message/return-receipt/return-receipt.component.spec.ts +38 -17
- package/src/app/component/message/text/text.component.html +3 -3
- package/src/app/component/message/text/text.component.scss +80 -86
- package/src/app/component/message/text/text.component.spec.ts +106 -13
- package/src/app/component/message-attachment/message-attachment.component.spec.ts +134 -13
- package/src/app/component/selection-department/selection-department.component.html +21 -23
- package/src/app/component/selection-department/selection-department.component.spec.ts +159 -14
- package/src/app/component/selection-department/selection-department.component.ts +8 -1
- package/src/app/component/send-button/send-button.component.html +5 -13
- package/src/app/component/send-button/send-button.component.spec.ts +2 -2
- package/src/app/component/star-rating-widget/star-rating-widget.component.html +51 -81
- package/src/app/directives/tooltip.directive.spec.ts +8 -4
- package/src/app/modals/confirm-close/confirm-close.component.html +20 -8
- package/src/app/modals/confirm-close/confirm-close.component.scss +3 -0
- package/src/app/modals/confirm-close/confirm-close.component.spec.ts +13 -4
- package/src/app/modals/confirm-close/confirm-close.component.ts +8 -1
- package/src/app/pipe/html-entites-encode.pipe.spec.ts +35 -2
- package/src/app/pipe/marked.pipe.spec.ts +38 -2
- package/src/app/pipe/marked.pipe.ts +51 -41
- package/src/app/providers/app-config.service.ts +4 -2
- package/src/app/providers/brand.service.spec.ts +23 -2
- package/src/app/providers/brand.service.ts +1 -1
- package/src/app/providers/global-settings.service.spec.ts +1009 -14
- package/src/app/providers/global-settings.service.ts +59 -2
- package/src/app/providers/json-sources-parser.service.ts +175 -0
- package/src/app/providers/translator.service.ts +24 -6
- package/src/app/providers/tts-audio-playback-coordinator.service.spec.ts +117 -0
- package/src/app/providers/tts-audio-playback-coordinator.service.ts +39 -16
- package/src/app/providers/url-preview.service.ts +82 -0
- package/src/app/providers/voice/audio.types.ts +6 -0
- package/src/app/providers/voice/voice-streaming.service.spec.ts +23 -0
- package/src/app/providers/voice/voice-streaming.service.ts +702 -0
- package/src/app/providers/voice/voice-streaming.types.ts +112 -0
- package/src/app/providers/voice/voice.service.spec.ts +170 -3
- package/src/app/providers/voice/voice.service.ts +691 -17
- package/src/app/sass/_variables.scss +1 -1
- package/src/app/sass/animations.scss +19 -1
- package/src/app/utils/globals.ts +14 -0
- package/src/app/utils/json-sources-utils.ts +27 -0
- package/src/app/utils/url-utils.ts +98 -0
- package/src/app/utils/utils-resources.ts +1 -1
- package/src/assets/i18n/en.json +106 -100
- package/src/assets/i18n/es.json +107 -101
- package/src/assets/i18n/fr.json +107 -101
- package/src/assets/i18n/it.json +107 -99
- package/src/assets/sounds/keyboard.mp3 +0 -0
- package/src/assets/twp/index-dev.html +18 -0
- package/src/assets/twp/tiledesk_widget_files/widget-css-override-example.css +14 -0
- package/src/chat21-core/providers/chat-manager.spec.ts +72 -0
- package/src/chat21-core/providers/scripts/script.service.spec.ts +12 -2
- package/src/chat21-core/utils/constants.ts +4 -0
- package/src/chat21-core/utils/utils-message.ts +23 -1
- package/src/widget-config-template.json +3 -1
- package/src/widget-config.json +28 -27
- package/tests/widget-form-rich.spec.ts +67 -0
- package/tests/widget-index-dev-settings.spec.ts +52 -0
- package/tests/widget-twp-iframe.spec.ts +39 -0
|
@@ -1,38 +1,207 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { waitForAsync, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
1
|
+
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
|
2
|
+
import { FormsModule } from '@angular/forms';
|
|
3
|
+
import { By } from '@angular/platform-browser';
|
|
5
4
|
|
|
5
|
+
import { MIN_WIDTH_IMAGES } from 'src/app/utils/constants';
|
|
6
6
|
import { ConversationPreviewComponent } from './conversation-preview.component';
|
|
7
|
-
import { LogLevel } from 'src/chat21-core/utils/constants';
|
|
8
|
-
import { NGXLogger } from 'ngx-logger';
|
|
9
7
|
import { CustomLogger } from 'src/chat21-core/providers/logger/customLogger';
|
|
10
|
-
|
|
8
|
+
import { LoggerInstance } from 'src/chat21-core/providers/logger/loggerInstance';
|
|
9
|
+
import { NGXLogger } from 'ngx-logger';
|
|
11
10
|
|
|
12
11
|
describe('ConversationPreviewComponent', () => {
|
|
13
12
|
let component: ConversationPreviewComponent;
|
|
14
13
|
let fixture: ComponentFixture<ConversationPreviewComponent>;
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const ngxlogger = jasmine.createSpyObj('NGXLogger', ['log', 'trace', 'debug', 'warn', 'error', 'info']);
|
|
15
|
+
const customLogger = new CustomLogger(ngxlogger);
|
|
16
|
+
|
|
17
|
+
const imageAttachment = (name = 'a.png') => ({
|
|
18
|
+
file: new File(['x'], name, { type: 'image/png' }),
|
|
19
|
+
metadata: { width: 400, height: 200, type: 'image/png', uid: 'u1', src: 'blob:mock' },
|
|
20
|
+
});
|
|
17
21
|
|
|
18
22
|
beforeEach(waitForAsync(() => {
|
|
23
|
+
LoggerInstance.setInstance(customLogger);
|
|
19
24
|
TestBed.configureTestingModule({
|
|
20
|
-
declarations: [
|
|
21
|
-
|
|
22
|
-
})
|
|
25
|
+
declarations: [ConversationPreviewComponent],
|
|
26
|
+
imports: [FormsModule],
|
|
27
|
+
})
|
|
28
|
+
.overrideComponent(ConversationPreviewComponent, {
|
|
29
|
+
set: {
|
|
30
|
+
template: `
|
|
31
|
+
<div #scrollMe id="c21-contentScroll-preview" style="height:39%">preview</div>
|
|
32
|
+
<textarea id="chat21-main-message-context-preview" [(ngModel)]="textInputTextArea"></textarea>
|
|
33
|
+
`,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
.compileComponents();
|
|
23
37
|
}));
|
|
24
38
|
|
|
25
39
|
beforeEach(() => {
|
|
26
40
|
fixture = TestBed.createComponent(ConversationPreviewComponent);
|
|
27
41
|
component = fixture.componentInstance;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
component['
|
|
42
|
+
component.attachments = [imageAttachment()] as any;
|
|
43
|
+
component.baseLocation = '';
|
|
44
|
+
component.translationMap = new Map([['LABEL_PLACEHOLDER', 'Placeholder']]);
|
|
45
|
+
component.stylesMap = new Map([['themeColor', '#000']]);
|
|
46
|
+
component.textInputTextArea = '';
|
|
31
47
|
fixture.detectChanges();
|
|
32
48
|
});
|
|
33
49
|
|
|
34
50
|
it('should create', () => {
|
|
35
|
-
console.log('ConversationPreviewComponent --->', component)
|
|
36
51
|
expect(component).toBeTruthy();
|
|
37
52
|
});
|
|
53
|
+
|
|
54
|
+
describe('getMetadataSize', () => {
|
|
55
|
+
it('should scale wide images to preview max width', () => {
|
|
56
|
+
const s = component.getMetadataSize({ width: 500, height: 100 });
|
|
57
|
+
expect(s.width).toBe(230);
|
|
58
|
+
expect(s.height).toBeCloseTo(46, 5);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should bump very narrow images to MIN_WIDTH_IMAGES', () => {
|
|
62
|
+
const s = component.getMetadataSize({ width: 40, height: 80 });
|
|
63
|
+
expect(s.width).toBe(MIN_WIDTH_IMAGES);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should cap tall images by max preview height', () => {
|
|
67
|
+
const s = component.getMetadataSize({ width: 100, height: 400 });
|
|
68
|
+
expect(s.height).toBe(150);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should default undefined metadata then cap tall square to preview max height', () => {
|
|
72
|
+
const s = component.getMetadataSize({});
|
|
73
|
+
// Both sides start at 230; height branch caps at 150 and scales width to match aspect ratio.
|
|
74
|
+
expect(s.height).toBe(150);
|
|
75
|
+
expect(s.width).toBe(150);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('readAsDataURL', () => {
|
|
80
|
+
it('should set fileSelected for raster images', () => {
|
|
81
|
+
component.fileSelected = undefined as any;
|
|
82
|
+
component.readAsDataURL(imageAttachment());
|
|
83
|
+
expect(component.fileSelected).toBeDefined();
|
|
84
|
+
expect(component.sizeImage).toBeDefined();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should sanitize SVG src', () => {
|
|
88
|
+
const svg = {
|
|
89
|
+
file: new File(['<svg/>'], 'a.svg', { type: 'image/svg+xml' }),
|
|
90
|
+
metadata: { width: 10, height: 10, type: 'image/svg+xml', uid: 's1', src: 'data:image/svg+xml;base64,PHN2Zy8+' },
|
|
91
|
+
};
|
|
92
|
+
component.fileSelected = undefined as any;
|
|
93
|
+
component.readAsDataURL(svg);
|
|
94
|
+
expect(component.fileSelected).toBeDefined();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('should route non-image files to createFile', () => {
|
|
98
|
+
spyOn(component, 'createFile').and.returnValue(Promise.resolve());
|
|
99
|
+
const pdf = {
|
|
100
|
+
file: new File(['%PDF'], 'doc.pdf', { type: 'application/pdf' }),
|
|
101
|
+
metadata: { uid: 'p1', type: 'application/pdf' },
|
|
102
|
+
};
|
|
103
|
+
component.readAsDataURL(pdf);
|
|
104
|
+
expect(component.createFile).toHaveBeenCalledWith(pdf);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('createFile', () => {
|
|
109
|
+
it('should request placeholder asset from baseLocation', async () => {
|
|
110
|
+
const blob = new Blob(['x'], { type: 'image/png' });
|
|
111
|
+
spyOn(window, 'fetch').and.returnValue(Promise.resolve({ blob: () => Promise.resolve(blob) } as Response));
|
|
112
|
+
component.baseLocation = 'https://app.test';
|
|
113
|
+
const att = {
|
|
114
|
+
file: new File(['z'], 'note.txt', { type: 'text/plain' }),
|
|
115
|
+
metadata: { uid: 'f1', type: 'text/plain' },
|
|
116
|
+
};
|
|
117
|
+
await component.createFile(att);
|
|
118
|
+
expect(window.fetch).toHaveBeenCalledWith('https://app.test/assets/images/file-alt-solid.png');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('keyboard and actions', () => {
|
|
123
|
+
it('onkeydown Escape should close modal', () => {
|
|
124
|
+
spyOn(component.onCloseModalPreview, 'emit');
|
|
125
|
+
component.onkeydown({ which: 27, keyCode: 27 } as KeyboardEvent);
|
|
126
|
+
expect(component.onCloseModalPreview.emit).toHaveBeenCalled();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('onkeydown Enter with text should emit send and restore', () => {
|
|
130
|
+
spyOn(component.onSendAttachment, 'emit');
|
|
131
|
+
spyOn(component as any, 'restoreTextArea');
|
|
132
|
+
const ta = fixture.debugElement.query(By.css('#chat21-main-message-context-preview')).nativeElement as HTMLTextAreaElement;
|
|
133
|
+
ta.value = ' caption ';
|
|
134
|
+
const ev = new KeyboardEvent('keydown', { key: 'Enter', keyCode: 13 });
|
|
135
|
+
spyOn(ev, 'preventDefault');
|
|
136
|
+
component.onkeydown(ev);
|
|
137
|
+
expect(ev.preventDefault).toHaveBeenCalled();
|
|
138
|
+
expect(component.onSendAttachment.emit).toHaveBeenCalledWith(' caption ');
|
|
139
|
+
expect((component as any).restoreTextArea).toHaveBeenCalled();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('onkeydown Enter with only whitespace should not emit', () => {
|
|
143
|
+
spyOn(component.onSendAttachment, 'emit');
|
|
144
|
+
const ta = fixture.debugElement.query(By.css('#chat21-main-message-context-preview')).nativeElement as HTMLTextAreaElement;
|
|
145
|
+
ta.value = ' ';
|
|
146
|
+
component.onkeydown({ which: 13, keyCode: 13, preventDefault: () => {} } as any);
|
|
147
|
+
expect(component.onSendAttachment.emit).not.toHaveBeenCalled();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('onClickClose should emit', () => {
|
|
151
|
+
spyOn(component.onCloseModalPreview, 'emit');
|
|
152
|
+
component.onClickClose();
|
|
153
|
+
expect(component.onCloseModalPreview.emit).toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('onSendPressed should emit current model text', () => {
|
|
157
|
+
spyOn(component.onSendAttachment, 'emit');
|
|
158
|
+
component.textInputTextArea = 'hi';
|
|
159
|
+
component.onSendPressed(new Event('click'));
|
|
160
|
+
expect(component.onSendAttachment.emit).toHaveBeenCalledWith('hi');
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('textarea sizing', () => {
|
|
165
|
+
it('onTextAreaChange should call resize helpers', () => {
|
|
166
|
+
spyOn(component, 'resizeInputField');
|
|
167
|
+
spyOn(component, 'resizeModalHeight');
|
|
168
|
+
component.onTextAreaChange();
|
|
169
|
+
expect(component.resizeInputField).toHaveBeenCalled();
|
|
170
|
+
expect(component.resizeModalHeight).toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('resizeInputField should grow with multiline content', () => {
|
|
174
|
+
const ta = fixture.debugElement.query(By.css('#chat21-main-message-context-preview')).nativeElement as HTMLTextAreaElement;
|
|
175
|
+
ta.value = 'a\nb\nc';
|
|
176
|
+
ta.style.height = '20px';
|
|
177
|
+
Object.defineProperty(ta, 'scrollHeight', { configurable: true, value: 80 });
|
|
178
|
+
Object.defineProperty(ta, 'offsetHeight', { configurable: true, value: 20 });
|
|
179
|
+
component.resizeInputField();
|
|
180
|
+
expect(parseInt(ta.style.height, 10)).toBeGreaterThan(20);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('resizeModalHeight should adjust host when textarea grows', () => {
|
|
184
|
+
const ta = fixture.debugElement.query(By.css('#chat21-main-message-context-preview')).nativeElement as HTMLTextAreaElement;
|
|
185
|
+
ta.style.height = '40px';
|
|
186
|
+
component.scrollMe = { nativeElement: { style: { height: '' } } } as any;
|
|
187
|
+
component.resizeModalHeight();
|
|
188
|
+
expect((component.scrollMe.nativeElement.style.height as string).length).toBeGreaterThan(0);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
describe('onImageRenderedFN', () => {
|
|
193
|
+
it('should clear pending load flag', () => {
|
|
194
|
+
component.isFilePendingToLoad = true;
|
|
195
|
+
component.onImageRenderedFN({});
|
|
196
|
+
expect(component.isFilePendingToLoad).toBe(false);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe('onPaste', () => {
|
|
201
|
+
it('should call resizeInputField', () => {
|
|
202
|
+
spyOn(component, 'resizeInputField');
|
|
203
|
+
component.onPaste(new ClipboardEvent('paste'));
|
|
204
|
+
expect(component.resizeInputField).toHaveBeenCalled();
|
|
205
|
+
});
|
|
206
|
+
});
|
|
38
207
|
});
|
package/src/app/component/conversation-detail/conversation-preview/conversation-preview.component.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
|
|
1
|
+
import { Component, ElementRef, EventEmitter, HostListener, Input, OnInit, Output, ViewChild } from '@angular/core';
|
|
2
2
|
import { DomSanitizer } from '@angular/platform-browser';
|
|
3
3
|
import { MIN_WIDTH_IMAGES } from 'src/app/utils/constants';
|
|
4
4
|
import { LoggerService } from 'src/chat21-core/providers/abstract/logger.service';
|
|
@@ -244,27 +244,47 @@ export class ConversationPreviewComponent implements OnInit {
|
|
|
244
244
|
this.setFocusOnId('chat21-main-message-context-preview');
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
247
|
+
/**
|
|
248
|
+
* Single keyboard handler for the preview textarea:
|
|
249
|
+
* - Enter (no modifier) -> send the attachment with the typed message
|
|
250
|
+
* - Shift / Alt / Ctrl / Meta + Enter -> insert a newline (default browser behavior)
|
|
251
|
+
* - Escape -> close the preview modal
|
|
252
|
+
* Tab navigation is handled by CDK cdkTrapFocus on the dialog wrapper.
|
|
253
|
+
* @param event
|
|
254
|
+
*/
|
|
255
|
+
onkeydown(event: KeyboardEvent) {
|
|
251
256
|
const keyCode = event.which || event.keyCode;
|
|
252
|
-
|
|
253
|
-
if (keyCode ===
|
|
257
|
+
|
|
258
|
+
if (keyCode === 27) { // Esc
|
|
259
|
+
this.onClickClose();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (keyCode === 13) { // ENTER
|
|
264
|
+
const hasModifier = event.metaKey || event.shiftKey || event.altKey || event.ctrlKey;
|
|
265
|
+
if (hasModifier) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
event.preventDefault();
|
|
270
|
+
const target = document.getElementById('chat21-main-message-context-preview') as HTMLInputElement;
|
|
271
|
+
if (target) {
|
|
272
|
+
this.textInputTextArea = target.value;
|
|
273
|
+
}
|
|
254
274
|
if (this.textInputTextArea && this.textInputTextArea.trim() !== '') {
|
|
255
275
|
this.onSendAttachment.emit(this.textInputTextArea);
|
|
256
276
|
this.restoreTextArea();
|
|
257
277
|
}
|
|
258
|
-
|
|
259
|
-
event.preventDefault();
|
|
278
|
+
return;
|
|
260
279
|
}
|
|
261
280
|
}
|
|
262
281
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
282
|
+
/** Component-level Esc handler to close the modal even when focus is not on the textarea. */
|
|
283
|
+
@HostListener('keydown.escape', ['$event'])
|
|
284
|
+
onHostEscape(event: KeyboardEvent){
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
event.stopPropagation();
|
|
287
|
+
this.onClickClose();
|
|
268
288
|
}
|
|
269
289
|
|
|
270
290
|
onPaste(event){
|
|
@@ -1,18 +1,46 @@
|
|
|
1
|
-
<
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
<ng-container [ngSwitch]="mode">
|
|
2
|
+
<!-- ALERT: spectrum line (fills streamAudioAlert width) -->
|
|
3
|
+
<div *ngSwitchCase="'alert'" class="stream-audio-spectrum" [ngStyle]="accentColor ? { color: accentColor } : null">
|
|
4
|
+
<svg class="stream-audio-spectrum__svg" viewBox="0 0 100 32" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
|
5
|
+
<defs>
|
|
6
|
+
<linearGradient [attr.id]="gradientId" x1="0" y1="16" x2="100" y2="16" gradientUnits="userSpaceOnUse">
|
|
7
|
+
<stop offset="0%" stop-color="currentColor" stop-opacity="0.45"/>
|
|
8
|
+
<stop offset="50%" stop-color="currentColor" stop-opacity="1"/>
|
|
9
|
+
<stop offset="100%" stop-color="currentColor" stop-opacity="0.45"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
</defs>
|
|
12
|
+
<path class="stream-audio-spectrum__line"
|
|
13
|
+
[attr.d]="spectrumLinePath"
|
|
14
|
+
fill="none"
|
|
15
|
+
[attr.stroke]="'url(#' + gradientId + ')'"
|
|
16
|
+
stroke-width="2.4"
|
|
17
|
+
stroke-linecap="round"
|
|
18
|
+
stroke-linejoin="round"/>
|
|
19
|
+
</svg>
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<!-- BUTTON: inactive icon / expanded pill content -->
|
|
23
|
+
<ng-container *ngSwitchCase="'button'">
|
|
24
|
+
<span class="stream-audio-button__icon" *ngIf="!active" aria-hidden="true">
|
|
25
|
+
<svg role="img" xmlns="http://www.w3.org/2000/svg" width="26" height="26" viewBox="0 0 23 23" aria-labelledby="altIconTitle">
|
|
26
|
+
<rect x="0" y="7.5" height="6px" fill-opacity="1" width="2px" rx="0.75" ry="0.75"></rect>
|
|
27
|
+
<rect x="4" y="5.5" height="10px" fill-opacity="1" width="2px" rx="0.75" ry="0.75"></rect>
|
|
28
|
+
<rect x="8" y="2.5" height="16px" fill-opacity="1" width="2px" rx="0.75" ry="0.75"></rect>
|
|
29
|
+
<rect x="12" y="5.5" height="10px" fill-opacity="1" width="2px" rx="0.75" ry="0.75"></rect>
|
|
30
|
+
<rect x="16" y="2.5" height="16px" fill-opacity="1" width="2px" rx="0.75" ry="0.75"></rect>
|
|
31
|
+
<rect x="20" y="7.5" height="6px" fill-opacity="1" width="2px" rx="0.75" ry="0.75"></rect>
|
|
32
|
+
<title id="altIconTitle">{{ translationMap.get('STREAM_AUDIO') }}</title>
|
|
33
|
+
</svg>
|
|
34
|
+
</span>
|
|
35
|
+
|
|
36
|
+
<span class="stream-audio-button__expanded" *ngIf="active">
|
|
37
|
+
<span class="stream-audio-button__bars" aria-hidden="true">
|
|
38
|
+
<span class="bar" [style.transform]="'scaleY(' + barScales[0] + ')'"></span>
|
|
39
|
+
<span class="bar" [style.transform]="'scaleY(' + barScales[1] + ')'"></span>
|
|
40
|
+
<span class="bar" [style.transform]="'scaleY(' + barScales[2] + ')'"></span>
|
|
41
|
+
<span class="bar" [style.transform]="'scaleY(' + barScales[3] + ')'"></span>
|
|
42
|
+
</span>
|
|
43
|
+
<span class="stream-audio-button__label">{{ translationMap.get('CLOSE') }}</span>
|
|
44
|
+
</span>
|
|
45
|
+
</ng-container>
|
|
46
|
+
</ng-container>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
:host {
|
|
2
|
-
display:
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
3
5
|
width: 100%;
|
|
4
|
-
flex: 1 1 auto;
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
.stream-audio-spectrum {
|
|
@@ -23,3 +24,60 @@
|
|
|
23
24
|
pointer-events: none;
|
|
24
25
|
filter: drop-shadow(0 0 1px color-mix(in srgb, currentColor 35%, transparent));
|
|
25
26
|
}
|
|
27
|
+
|
|
28
|
+
/* ===========================
|
|
29
|
+
* BUTTON (pill content)
|
|
30
|
+
* =========================== */
|
|
31
|
+
.stream-audio-button__icon {
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
width: 100%;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.stream-audio-button__icon svg {
|
|
39
|
+
width: 20px;
|
|
40
|
+
height: 20px;
|
|
41
|
+
display: block;
|
|
42
|
+
rect {
|
|
43
|
+
fill: var(--icon-fill-color);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.stream-audio-button__expanded {
|
|
48
|
+
display: inline-flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
justify-content: center;
|
|
51
|
+
gap: 12px;
|
|
52
|
+
width: 100%;
|
|
53
|
+
user-select: none;
|
|
54
|
+
color: var(--icon-fill-color);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.stream-audio-button__label {
|
|
58
|
+
font-size: 14px;
|
|
59
|
+
line-height: 1;
|
|
60
|
+
font-weight: 500;
|
|
61
|
+
letter-spacing: 0.2px;
|
|
62
|
+
white-space: nowrap;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.stream-audio-button__bars {
|
|
66
|
+
display: inline-flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
gap: 3px;
|
|
70
|
+
width: 26px;
|
|
71
|
+
height: 18px;
|
|
72
|
+
transform-origin: center;
|
|
73
|
+
margin: 0;
|
|
74
|
+
line-height: 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.stream-audio-button__bars .bar {
|
|
78
|
+
width: 3px;
|
|
79
|
+
height: 100%;
|
|
80
|
+
border-radius: 2px;
|
|
81
|
+
background: var(--icon-fill-color);
|
|
82
|
+
transform-origin: center;
|
|
83
|
+
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
|
1
|
+
import { Component, Input, OnChanges, OnDestroy, OnInit, Optional, SimpleChanges } from '@angular/core';
|
|
2
|
+
import { Subscription } from 'rxjs';
|
|
3
|
+
import { VoiceService } from 'src/app/providers/voice/voice.service';
|
|
4
|
+
|
|
5
|
+
export type StreamAudioSpectrumMode = 'alert' | 'button';
|
|
2
6
|
|
|
3
7
|
/**
|
|
4
8
|
* Icona stream: cerchio con linea orizzontale tipo spettro, reattiva al volume del microfono.
|
|
@@ -18,19 +22,63 @@ export class StreamAudioSpectrumComponent implements OnInit, OnChanges {
|
|
|
18
22
|
/** Colore tema (stroke / gradient); opzionale. */
|
|
19
23
|
@Input() accentColor?: string;
|
|
20
24
|
|
|
25
|
+
/** UI variant. `alert` = spectrum line (in #streamAudioAlert). `button` = icon / pill with bars + label. */
|
|
26
|
+
@Input() mode: StreamAudioSpectrumMode = 'alert';
|
|
27
|
+
/** For `mode="button"`: whether the stream is active (expanded pill). */
|
|
28
|
+
@Input() active = false;
|
|
29
|
+
/** For `mode="button"`: VAD speech flag; if omitted, we fall back to a volume threshold heuristic. */
|
|
30
|
+
@Input() isUserSpeaking?: boolean;
|
|
31
|
+
/** For `mode="button"`: label on the pill. */
|
|
32
|
+
@Input() translationMap: Map< string, string>;
|
|
33
|
+
|
|
34
|
+
// ALERT (spectrum line)
|
|
21
35
|
spectrumLinePath = 'M0,16 L100,16';
|
|
22
36
|
|
|
37
|
+
// BUTTON (bars)
|
|
38
|
+
barScales: [number, number, number, number] = [0.65, 0.65, 0.65, 0.65];
|
|
39
|
+
private rafId: number | null = null;
|
|
40
|
+
private lastSpeaking = false;
|
|
41
|
+
private voiceSpeechStartSub?: Subscription;
|
|
42
|
+
private voiceSpeechEndSub?: Subscription;
|
|
43
|
+
private internalIsUserSpeaking = false;
|
|
44
|
+
|
|
45
|
+
constructor(@Optional() private readonly voiceService: VoiceService | null) {}
|
|
46
|
+
|
|
23
47
|
ngOnInit(): void {
|
|
24
|
-
|
|
48
|
+
// Optional: use VAD speech events to improve idle/speaking detection.
|
|
49
|
+
if (this.voiceService) {
|
|
50
|
+
this.voiceSpeechStartSub = this.voiceService.speechStart$?.subscribe(() => {
|
|
51
|
+
this.internalIsUserSpeaking = true;
|
|
52
|
+
});
|
|
53
|
+
this.voiceSpeechEndSub = this.voiceService.speechEnd$?.subscribe(() => {
|
|
54
|
+
this.internalIsUserSpeaking = false;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.refreshAll();
|
|
25
58
|
}
|
|
26
59
|
|
|
27
60
|
ngOnChanges(changes: SimpleChanges): void {
|
|
28
|
-
if (changes['volume']) {
|
|
29
|
-
this.
|
|
61
|
+
if (changes['volume'] || changes['mode'] || changes['active'] || changes['isUserSpeaking']) {
|
|
62
|
+
this.refreshAll();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
ngOnDestroy(): void {
|
|
67
|
+
this.stopRaf();
|
|
68
|
+
this.voiceSpeechStartSub?.unsubscribe();
|
|
69
|
+
this.voiceSpeechEndSub?.unsubscribe();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private refreshAll(): void {
|
|
73
|
+
if (this.mode === 'alert') {
|
|
74
|
+
this.refreshSpectrumPath();
|
|
75
|
+
this.stopRaf();
|
|
76
|
+
return;
|
|
30
77
|
}
|
|
78
|
+
this.refreshBars();
|
|
31
79
|
}
|
|
32
80
|
|
|
33
|
-
private
|
|
81
|
+
private refreshSpectrumPath(): void {
|
|
34
82
|
const intensity = Math.min(this.volume / 80, 1);
|
|
35
83
|
const t = Date.now() / 175;
|
|
36
84
|
this.spectrumLinePath = this.buildSpectrumLinePath(intensity, t);
|
|
@@ -59,4 +107,86 @@ export class StreamAudioSpectrumComponent implements OnInit, OnChanges {
|
|
|
59
107
|
}
|
|
60
108
|
return parts.join('');
|
|
61
109
|
}
|
|
110
|
+
|
|
111
|
+
private refreshBars(): void {
|
|
112
|
+
if (!this.active) {
|
|
113
|
+
this.stopRaf();
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const speaking = this.computeSpeaking();
|
|
118
|
+
if (!speaking) {
|
|
119
|
+
this.stopRaf();
|
|
120
|
+
this.barScales = [0.65, 0.65, 0.65, 0.65];
|
|
121
|
+
this.lastSpeaking = false;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// speaking: animate bars with volume-driven intensity
|
|
126
|
+
if (!this.lastSpeaking) {
|
|
127
|
+
this.lastSpeaking = true;
|
|
128
|
+
}
|
|
129
|
+
this.startRaf();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private computeSpeaking(): boolean {
|
|
133
|
+
if (typeof this.isUserSpeaking === 'boolean') {
|
|
134
|
+
return this.isUserSpeaking;
|
|
135
|
+
}
|
|
136
|
+
if (this.voiceService) {
|
|
137
|
+
return this.internalIsUserSpeaking;
|
|
138
|
+
}
|
|
139
|
+
// Fallback heuristic: treat as speaking when volume crosses a low threshold.
|
|
140
|
+
return (this.volume || 0) >= 4;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private startRaf(): void {
|
|
144
|
+
if (this.rafId !== null) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const tick = () => {
|
|
148
|
+
if (!this.active) {
|
|
149
|
+
this.stopRaf();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const speaking = this.computeSpeaking();
|
|
153
|
+
if (!speaking) {
|
|
154
|
+
this.stopRaf();
|
|
155
|
+
this.barScales = [0.65, 0.65, 0.65, 0.65];
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const intensity = Math.min((this.volume || 0) / 80, 1);
|
|
160
|
+
const t = performance.now() / 220;
|
|
161
|
+
const targets: [number, number, number, number] = [0.35, 0.35, 0.35, 0.35];
|
|
162
|
+
|
|
163
|
+
for (let i = 0; i < 4; i++) {
|
|
164
|
+
const phase = i * 0.9;
|
|
165
|
+
const w1 = (Math.sin(t * 1.35 + phase) + 1) / 2;
|
|
166
|
+
const w2 = (Math.sin(t * 2.05 + phase * 1.7) + 1) / 2;
|
|
167
|
+
const mix = w1 * 0.62 + w2 * 0.38;
|
|
168
|
+
const s = 0.25 + intensity * (0.25 + 0.95 * mix);
|
|
169
|
+
targets[i as 0 | 1 | 2 | 3] = Math.max(0.35, Math.min(1.2, s));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Smooth toward targets to avoid jitter on rapid volume changes.
|
|
173
|
+
const lerp = (a: number, b: number, k: number) => a + (b - a) * k;
|
|
174
|
+
this.barScales = [
|
|
175
|
+
lerp(this.barScales[0], targets[0], 0.35),
|
|
176
|
+
lerp(this.barScales[1], targets[1], 0.35),
|
|
177
|
+
lerp(this.barScales[2], targets[2], 0.35),
|
|
178
|
+
lerp(this.barScales[3], targets[3], 0.35),
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
this.rafId = requestAnimationFrame(tick);
|
|
182
|
+
};
|
|
183
|
+
this.rafId = requestAnimationFrame(tick);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private stopRaf(): void {
|
|
187
|
+
if (this.rafId !== null) {
|
|
188
|
+
cancelAnimationFrame(this.rafId);
|
|
189
|
+
this.rafId = null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
62
192
|
}
|