-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwidgetcontent.html
More file actions
191 lines (168 loc) · 6.7 KB
/
widgetcontent.html
File metadata and controls
191 lines (168 loc) · 6.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="public/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WebTrit Widget</title>
<link rel="stylesheet" href="src/styles/widget.css">
<script>
window.startCall = async function () {
window.connectedSuccessfully = false;
if (window.webTritSignaling) {
await window.webTritSignaling.connect();
} else {
parent.window.postMessage("start_call", "*");
}
};
window.endCall = function () {
window.connectedSuccessfully = true;
if (window.webTritSignaling) {
window.webTritSignaling.hangup();
} else {
parent.window.postMessage("end_call", "*");
}
parent.window.postMessage("removetheiframe_success", "*");
};
window.onTimeTrigger = function () {
if (window.stopTrigger || !window.connectTime) return;
let statusLabel = document.getElementById('timingcontainer');
const difference = new Date() - window.connectTime;
const inSeconds = Math.floor(difference / 1000);
const seconds = inSeconds % 60;
const minutes = (inSeconds - seconds) / 60;
statusLabel.innerText = (minutes + '').padStart(2, '0') + ':' + (seconds + '').padStart(2, '0');
setTimeout(window.onTimeTrigger, 1000);
};
window.enableDialButtons = function (enable) {
let dialButtons = document.getElementsByClassName('number-pad-item');
for (const el of dialButtons) {
if (enable) {
if (el.classList.contains('pad-disable')) {
el.classList.remove('pad-disable');
}
if (!el.classList.contains('pad-enable')) {
el.classList.add('pad-enable');
}
} else {
if (el.classList.contains('pad-enable')) {
el.classList.remove('pad-enable');
}
if (!el.classList.contains('pad-disable')) {
el.classList.add('pad-disable');
}
}
}
};
window.updateStatusCallback = function (status) {
let statusLabel = document.getElementById('timingcontainer');
if (statusLabel) {
switch (status) {
case 'Accepted':
statusLabel.innerText = 'Accepted...';
break;
case 'Disconnected':
statusLabel.innerText = 'Disconnected...';
break;
case 'Registered':
statusLabel.innerText = 'Registered...';
break;
case 'Changed':
statusLabel.innerText = 'Changed...';
break;
case 'Error':
statusLabel.innerText = 'Error';
break;
case 'Start':
statusLabel.innerText = 'Start...';
break;
default:
statusLabel.innerText = status + '...';
break;
}
}
if (status === 'Connected' || status === 'Accepted') {
window.connectedSuccessfully = true;
window.connectTime = new Date();
window.stopTrigger = false;
window.enableDialButtons(true);
setTimeout(window.onTimeTrigger, 1000);
}
if (status === 'Disconnected') {
window.stopTrigger = true;
parent.window.postMessage(window.connectedSuccessfully
? "removetheiframe_success"
: "removetheiframe_failure", "*");
}
};
window.sendDtmf = function (ch) {
if (!window.connectedSuccessfully) return;
let charsLabel = document.getElementById('typedNumberContainer');
charsLabel.innerText += ch;
if (window.webTritSignaling) {
window.webTritSignaling?.sendDtmf(ch);
} else {
parent.window.postMessage(ch, "*");
}
}
window.clickDialButton = function (event) {
if (event.target.classList.contains('pad-disable')) {
return;
}
const ch = event.target.innerText;
window.sendDtmf(ch);
};
window.addEventListener('load', () => {
window.startCall();
});
window.muteAudio = function () {
if (window.muted === undefined) {
window.muted = false;
}
window.muted = !window.muted;
if (window.webTritSignaling) {
window.webTritSignaling.muteAudio(!window.muted);
} else {
parent.window.postMessage(!window.muted ? "mute_audio" : "unmute_audio", "*");
}
let microphoneIcon = document.getElementById('microphoneicon');
if (microphoneIcon) {
const svg = microphoneIcon.firstElementChild;
svg.src = window.muted ? '/src/assets/muted.svg' : '/src/assets/microphone.svg';
}
};
const receiveMessage = function (event) {
if (event.data && event.data.type === "status_update" && event.data.data) {
window.updateStatusCallback(event.data.data);
}
};
window.addEventListener("message", receiveMessage, false);
</script>
</head>
<body style="margin: 0; overflow: hidden;">
<div class="main-content-container">
<div class="logo-icon-container">
<img src="/src/assets/webtrit.png" class="logo-icon">
</div>
<div class="header-container">
Call to company contact centre
</div>
<div class="timing-container" id="timingcontainer"></div>
<div class="typed-number-container">
<span id="typedNumberContainer" class="numbers-input-text"></span>
</div>
<div class="action-buttons-container">
<div class="action-button central" onclick="window.endCall();">
<div>
<img src="/src/assets/call.svg">
</div>
</div>
<div class="action-button" onclick="window.muteAudio();">
<div id="microphoneicon">
<img src="/src/assets/microphone.svg">
</div>
</div>
</div>
</div>
</body>
</html>