-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathwidget.html
252 lines (223 loc) · 8.67 KB
/
widget.html
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Call-me Click-to-Call Widget</title>
<style>
/* Body styling */
body {
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
/* Images styling */
img {
width: 200px;
cursor: pointer;
display: block;
transition: transform 0.3s ease;
}
img:hover {
transform: scale(1.05);
}
/* iFrame styling */
iframe {
width: 80vw;
height: 80vh;
border: none;
border-radius: 10px;
display: none;
}
/* Exit call button styling */
#exitCallButton {
padding: 10px 20px;
background-color: #ff4d4d;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
position: absolute;
top: 10px;
left: 50%;
transform: translateX(-50%);
display: none;
z-index: 1001;
}
#exitCallButton:hover {
background-color: #e60000;
}
/* Modal styling */
.modal {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
border-radius: 8px;
display: none;
z-index: 1000;
max-width: 400px;
width: 90%;
}
.modal h2 {
font-size: 18px;
margin-bottom: 20px;
}
.modal input {
width: calc(100% - 20px);
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
.modal button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
border-radius: 4px;
margin-right: 10px;
}
.modal button:hover {
background-color: #0056b3;
}
/* Overlay for dimming background */
.overlay {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.5);
display: none;
z-index: 999;
}
/* Responsive design for smaller devices */
@media (max-width: 600px) {
iframe {
width: 100%;
height: 60vh;
}
}
</style>
</head>
<body>
<!-- Main widget click-to-call you can replace it with a button in case... -->
<img id="callImage" src="./widget.png" alt="Click to Call" />
<!-- Exit the call button -->
<button id="exitCallButton">Exit call</button>
<!-- Overlay for background dimming -->
<div class="overlay" id="overlay"></div>
<!-- Modal for selecting action -->
<div class="modal" id="selectModal">
<h2>Select Action</h2>
<button id="joinCallOption">Join Call</button>
<button id="startCallOption">Start Call</button>
</div>
<!-- Modal for joining a call -->
<div class="modal" id="joinModal">
<h2>Enter Username to Join</h2>
<input type="text" id="joinUsername" placeholder="Enter username to join" />
<button id="joinCall">Join Call</button>
</div>
<!-- Modal for starting a call -->
<div class="modal" id="startCallModal">
<h2>Enter Your Display Name</h2>
<input type="text" id="displayUsername" placeholder="Enter your display name" />
<h2>Enter Username to Call</h2>
<input type="text" id="callUsername" placeholder="Enter username to call" />
<button id="startCall">Start Call</button>
</div>
<!-- Video call iframe -->
<iframe id="callIframe" allow="camera; microphone; fullscreen; autoplay"></iframe>
<script>
// Replace with your domain name
const domain = 'cme.mirotalk.com';
// Cache DOM elements at the beginning
const callImage = document.getElementById('callImage');
const exitCallButton = document.getElementById('exitCallButton');
const selectModal = document.getElementById('selectModal');
const joinModal = document.getElementById('joinModal');
const startCallModal = document.getElementById('startCallModal');
const overlay = document.getElementById('overlay');
const joinCallButton = document.getElementById('joinCall');
const startCallButton = document.getElementById('startCall');
const joinCallOption = document.getElementById('joinCallOption');
const startCallOption = document.getElementById('startCallOption');
const joinUsernameInput = document.getElementById('joinUsername');
const displayUsernameInput = document.getElementById('displayUsername');
const callUsernameInput = document.getElementById('callUsername');
const iframe = document.getElementById('callIframe');
// Event listeners
callImage.addEventListener('click', () => {
selectModal.style.display = 'block';
overlay.style.display = 'block';
});
overlay.addEventListener('click', closeModals);
joinCallOption.addEventListener('click', () => {
selectModal.style.display = 'none';
joinModal.style.display = 'block';
joinUsernameInput.focus();
});
startCallOption.addEventListener('click', () => {
selectModal.style.display = 'none';
startCallModal.style.display = 'block';
displayUsernameInput.focus();
});
joinCallButton.addEventListener('click', () => {
const joinUsername = joinUsernameInput.value.trim();
if (!joinUsername) {
alert('Please enter a username to join.');
return;
}
const url = `https://${domain}/join?user=${joinUsername}`;
startIframe(url);
});
startCallButton.addEventListener('click', () => {
const displayUsername = displayUsernameInput.value.trim();
const callUsername = callUsernameInput.value.trim();
if (!displayUsername) {
alert('Please enter a display name.');
return;
}
if (!callUsername) {
alert('Please enter a username to call.');
return;
}
const url = `https://${domain}/join?user=${displayUsername}&call=${callUsername}`;
startIframe(url);
});
exitCallButton.addEventListener('click', endCall);
// Functions
function startIframe(url) {
iframe.src = url;
iframe.style.display = 'block';
closeModals();
callImage.style.display = 'none';
exitCallButton.style.display = 'block';
}
function endCall() {
iframe.style.display = 'none';
iframe.src = ''; // Clear iframe source
callImage.style.display = 'block';
exitCallButton.style.display = 'none';
}
function closeModals() {
selectModal.style.display = 'none';
joinModal.style.display = 'none';
startCallModal.style.display = 'none';
overlay.style.display = 'none';
}
</script>
</body>
</html>