-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
300 lines (270 loc) · 12.6 KB
/
index.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
<title>Whatsapp API</title>
<style type="text/css">
.preloader {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 9999;
background-color: #fff;
}
.preloader .loading {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
font: 14px arial;
}
.client {
position: relative;
display: inline-block;
}
.hide {
display: none;
}
#qrcode {
padding: 10px;
}
.modal {
position: fixed;
top: 110px;
bottom: 0;
left: 0;
z-index: 10040;
overflow: auto;
overflow-y: auto;
}
</style>
</head>
<body>
<header>
<div class="navbar navbar-dark bg-dark box-shadow">
<div class="container d-flex justify-content-between">
<a href="/" class="navbar-brand d-flex align-items-center">
<img src="https://upload.wikimedia.org/wikipedia/commons/6/6b/WhatsApp.svg" width="25" height="25">
<strong>Whatsapp API</strong>
</a>
<div class="pull-right">
<strong class="text-light mr-3">Support by CODINGNESIA</strong>
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#modalLogout">Logout</button>
</div>
</div>
</div>
</header>
<!-- Modal Logout -->
<div class="modal fade" id="modalLogout" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">LOGOUT</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Apakah anda yakin akan keluar ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
<a href="/logout">
<button type="button" class="btn btn-primary">Logout</button>
</a>
</div>
</div>
</div>
</div>
<!-- Modal Disconnect -->
<div class="modal fade" id="modalDisconnect" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Disconnect</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p class="body-disconnect"></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">Batal</button>
<button class="btn btn-danger btn-sm dis-client-btn">Disconnect</button>
</div>
</div>
</div>
</div>
<div class="container justify-content-between mt-4">
<div id="app">
<div class="form-container row">
<div class="col-md-6">
<form id="form">
<div class="form-group mb-3">
<label for="client-id">ID</label>
<input type="text" class="form-control" id="client-id" placeholder="Masukkan ID" required>
</div>
<div class="form-group mb-3">
<label for="client-description">Deskripsi</label>
<textarea class="form-control" id="client-description" placeholder="Masukkan Deskripsi" required></textarea>
</div>
<button type="submit" class="btn btn-success btn-submit">Tambah Client</button>
</form>
</div>
</div>
<hr>
<div class="row mb-3">
<div class="col-md-6">
<div class="mb-3">
<label>Client</label>
<select name="client_lists" id="client_lists" class="form-control">
<option>Pilih Client</option>
</select>
</div>
<button type="button" class="btn btn-danger btn-sm disconnect" data-toggle="modal" data-target="#modalDisconnect">Disconnect</button>
</div>
</div>
<div class="row">
<div class="client-container">
<div class="card client hide col-sm-3 mb-3">
<div class="card-header">
<h3 class="title"></h3>
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item overflow-auto" style="height: 75px; font-size: 14px;">
<p class="description"></p>
</li>
<li class="list-group-item">
<div class="text-center">
<div class="spinner-border" id="preload" role="status">
<span class="sr-only"></span>
</div>
</div>
<img src="" alt="QR Code" id="qrcode">
</li>
<li class="list-group-item overflow-auto mb-3" style="height: 175px; font-size: 14px;" tabindex="1">
<h5>Logs:</h5>
<ul class="logs"></ul>
</li>
</ul>
</div>
</div>
<!-- <div class="client hide">
<h3 class="title"></h3>
<p class="description"></p>
<img src="" alt="QR Code" id="qrcode">
<h3>Logs:</h3>
<ul class="logs"></ul>
</div> -->
</div>
</div>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<!--
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script src="http://code.jquery.com/jquery-2.2.1.min.js"></script>
<script>
$(document).ready(function(){
$(".preloader").fadeOut();
})
</script>
<script>
$(document).ready(function() {
var socket = io();
// Kantor
// var socket = io.connect('http://localhost:8000/', { path: '/socket.io' });
// var socket = io.connect('http://192.168.10.24:8000/', { path: '/socket.io' });
// var socket = io.connect('http://146504109984.ip-dynamic.com:8000/', { path: '/socket.io' });
// Ketika button tambah diklik
$('#form').submit(function() {
var clientId = $('#client-id').val();
var clientDescription = $('#client-description').val();
var template = $('.client').first().clone()
.removeClass('hide')
.addClass(clientId);
template.find('.title').html(clientId);
template.find('.description').html(clientDescription);
$('.client-container').append(template);
socket.emit('create-session', {
id: clientId,
description: clientDescription
});
});
socket.on('init', function(data) {
$('.client-container .client').not(':first').remove();
console.log(data);
for (var i = 0; i < data.length; i++) {
var session = data[i];
var clientId = session.id;
var clientDescription = session.description;
var template = $('.client').first().clone()
.removeClass('hide')
.addClass(clientId);
template.find('.title').html(clientId);
template.find('.description').html(clientDescription);
$('.client-container').append(template);
if (session.ready) {
$(`.client.${session.id} #qrcode`).attr('src', 'https://icon-library.com/images/15fa0a9d9d.png');
$(`.client.${session.id} #qrcode`).attr('width', '248');
$(`.client.${session.id} #preload`).hide();
$(`.client.${session.id} .logs`).append($('<li>').text('Whatsapp is ready!'));
} else {
$(`.client.${session.id} .logs`).append($('<li>').text('Connecting...'));
$(`.client.${session.id} #qrcode`).hide();
$(`.client.${session.id} #preload`).show();
}
$("#client_lists").append('<option value='+data[i].id+'>'+data[i].id+'</option>');
}
});
socket.on('remove-session', function(id) {
$(`.client.${id}`).remove();
window.location = '/';
});
socket.on('message', function(data) {
$(`.client.${data.id} .logs`).append($('<li>').text(data.text));
});
socket.on('qr', function(data) {
$(`.client.${data.id} #preload`).hide();
$(`.client.${data.id} #preload`).fadeOut();
$(`.client.${data.id} #qrcode`).attr('src', data.src);
$(`.client.${data.id} #qrcode`).show();
});
socket.on('ready', function(data) {
$(`.client.${data.id} #qrcode`).attr('src', 'https://icon-library.com/images/15fa0a9d9d.png');
$(`.client.${data.id} #qrcode`).attr('width', '248');
$(`.client.${data.id} #qrcode`).show();
window.location = '/';
});
socket.on('authenticated', function(data) {
$(`.client.${data.id} #qrcode`).show();
});
$('.disconnect').click(function() {
var clientId = $('#client_lists').val();
var bodyDisconnect = "Apakah anda akan disconnect ID "+clientId+" ?"
$(".body-disconnect").text(bodyDisconnect);
});
$('.dis-client-btn').click(function() {
var clientId = $('#client_lists').val();
socket.emit('disconnected-session', {
id: clientId
});
window.location = '/';
});
});
</script>
</body>
</html>