Skip to content

Commit 7aa01ff

Browse files
CopilotTECH7Fox
andcommitted
Improve type safety for auto_answer extension configuration
Co-authored-by: TECH7Fox <32220029+TECH7Fox@users.noreply.github.com>
1 parent 65a506c commit 7aa01ff

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/sip-call-dialog.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ import { customElement, property, state } from "lit/decorators.js";
33
import { sipCore, CALLSTATE, AUDIO_DEVICE_KIND } from "./sip-core";
44
import { AudioVisualizer } from "./audio-visualizer";
55

6-
interface Extension {
6+
export interface Extension {
77
name: string;
88
extension: string;
99
camera_entity: string | null;
1010
auto_answer?: boolean;
1111
}
1212

13-
enum ButtonType {
13+
export enum ButtonType {
1414
SERVICE_CALL = "service_call",
1515
DTMF = "dtmf"
1616
}
1717

18-
interface Button {
18+
export interface Button {
1919
label: string;
2020
icon: string;
2121
type: ButtonType;
2222
data: any;
2323
}
2424

25-
interface PopupConfig {
25+
export interface PopupConfig {
2626
buttons: Button[];
2727
extensions: { [key: string]: Extension };
2828
large: boolean | undefined;

src/sip-core.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ export interface ICEConfig extends RTCConfiguration {
3939
iceGatheringTimeout?: number;
4040
}
4141

42+
/** Extension configuration for popup */
43+
export interface PopupExtension {
44+
name?: string;
45+
extension?: string;
46+
camera_entity?: string | null;
47+
auto_answer?: boolean;
48+
}
49+
50+
/** Popup configuration interface */
51+
export interface PopupConfig {
52+
buttons?: any[];
53+
extensions?: { [key: string]: PopupExtension };
54+
large?: boolean;
55+
auto_open?: boolean;
56+
hide_header_button?: boolean;
57+
}
58+
4259
/** Configuration for SIP Core */
4360
export interface SIPCoreConfig {
4461
ice_config: ICEConfig;
@@ -51,7 +68,7 @@ export interface SIPCoreConfig {
5168
/** Output configuration */
5269
out: String;
5370
auto_answer: boolean;
54-
popup_config: Object | null;
71+
popup_config: PopupConfig | null;
5572
popup_override_component: string | null;
5673
/**
5774
* Whether to use video in SIP calls.
@@ -536,14 +553,11 @@ export class SIPCore {
536553
let shouldAutoAnswer = this.config.auto_answer; // Default to global setting
537554

538555
// Check if there's an extension-specific auto_answer setting
539-
if (this.config.popup_config && typeof this.config.popup_config === 'object') {
540-
const popupConfig = this.config.popup_config as any;
541-
if (popupConfig.extensions && popupConfig.extensions[callerExtension]) {
542-
const extensionConfig = popupConfig.extensions[callerExtension];
543-
if (extensionConfig.auto_answer !== undefined) {
544-
shouldAutoAnswer = extensionConfig.auto_answer;
545-
console.info(`Using extension-specific auto_answer for ${callerExtension}: ${shouldAutoAnswer}`);
546-
}
556+
if (this.config.popup_config?.extensions?.[callerExtension]) {
557+
const extensionConfig = this.config.popup_config.extensions[callerExtension];
558+
if (typeof extensionConfig.auto_answer === 'boolean') {
559+
shouldAutoAnswer = extensionConfig.auto_answer;
560+
console.info(`Using extension-specific auto_answer for ${callerExtension}: ${shouldAutoAnswer}`);
547561
}
548562
}
549563

0 commit comments

Comments
 (0)