@ -27,6 +27,15 @@
< div class = "ui container" id = "app" >
< h1 class = "ui header center aligned" > [[ app_name ]]< / h1 >
< div class = "ui success message" v-if = "connected_devices != null" >
< div class = "header" >
Device is connected
< / div >
< p >
Device ID: < b > [[ connected_devices[0].device ]]< / b >
< / p >
< / div >
< div class = "ui horizontal divider" >
App
< / div >
@ -668,6 +677,9 @@
try {
await this.logoutApi()
showSuccessInfo("Logout success")
// fetch devices
this.app_ws.send(JSON.stringify({"code": "FETCH_DEVICES"}))
} catch (err) {
showErrorInfo(err)
}
@ -696,6 +708,8 @@
try {
await this.reconnectApi()
showSuccessInfo("Reconnect success")
// fetch devices
this.app_ws.send(JSON.stringify({"code": "FETCH_DEVICES"}))
} catch (err) {
showErrorInfo(err)
}
@ -1289,9 +1303,11 @@
delimiters: ['[[', ']]'],
data() {
return {
app_ws: null,
app_host: {{ .AppHost }},
app_name: 'Whatsapp API Multi Device ({{ .AppVersion }})',
is_logged_in: false,
connected_devices: null,
type_group: "g.us",
type_user: "s.whatsapp.net"
}
@ -1299,19 +1315,27 @@
mounted() {
if (window["WebSocket"]) {
let wsType = location.protocol !== 'https:' ? 'ws://' : 'wss://';
let conn = new WebSocket(wsType + document.location.host + "/ws");
this.app_ws = new WebSocket(wsType + document.location.host + "/ws");
conn.onclose = (evt) => {
console.log(evt)
this.app_ws.onopen = (evt) => {
this.app_ws.send(JSON.stringify({
"code": "FETCH_DEVICES",
"message": "List device"
}))
};
conn.onmessage = (evt) => {
console.log(evt)
this.app_ws.onmessage = (evt) => {
const message = JSON.parse(evt.data)
switch (message.code) {
case 'LOGIN_SUCCESS':
showSuccessInfo(message.message)
$('#modalLogin').modal('hide');
// fetch devices
this.app_ws.send(JSON.stringify({"code": "FETCH_DEVICES"}))
break;
case 'LIST_DEVICES':
this.connected_devices = message.result
break;
default:
console.log(message)