[
1,
1,
"room:v1:whats_app:auth:77",
"phx_reply",
{
"response": {},
"status": "ok"
}
]
[
1,
null,
"room:v1:whats_app:auth:77",
"auth_state",
{
"auth": false,
"qr_code": null
}
]
[
1,
null,
"room:v1:whats_app:auth:77",
"auth_state",
{
"auth": false,
"qr_code":
"2@NqUcv7om4BWqrgF5D6jn51M1hptMR/lK+QmZAxm9aLCKEq9NMgH08slb1Ydmu1ywEWu8CFc
Uil8uGw==,XRJHShEHeWrVRFIyJys2I8WWjlml7m6hKL53oXH0bDA=,3wkQDqsvB0hT19CWs1O
juBD5sp/IFhT+qQmpTlHFYhE=,iDrOCe/r5/NzI+N3bZkjBX6GbIKW4EhTuplW9jb+/mY="
}
]
[
1,
null,
"room:v1:whats_app:auth:5390",
"auth_state",
{
"auth": true
}
]
class WhatsAppSocket {
constructor() {}
change_auth_status(status, qr_code) {
if (status == false && qr_code == null) {
return;
}
if (status == true) {
console.log("WhatsApp подключен");
} else {
console.log("WhatsApp не подключен");
}
}
show_qr_code(status, qr_code) {
if (status == false && qr_code == null) {
return;
}
if (status == true) {
// когда отсканировали
store.dispatch("getWhatsappStatus");
return;
}
if (qr_code) {
// создание qr кода
qrValue.value = qr_code;
}
}
show_in_progress(status) {
if (status == true) {
console.log('status' + true);
}
}
show_reboot_page() {
let auth_state = $("#auth").data().state;
if (auth_state == false) {
console.log(auth_state);
}
console.log(auth_state);
}
init_connect(customer_id, api_key) {
let socket = new Socket("wss://msg-farmer.pushsms.ru/socket", {
params: { token: api_key },
logger: (kind, msg, data) => {
console.log(`${kind}: ${msg}`, data);
},
});
socket.connect();
socket.onOpen((ev) => console.log("OPEN", ev));
socket.onError((ev) => console.log("ERROR", ev));
socket.onClose((e) => console.log("CLOSE", e));
var chan = socket.channel(`room:v1:whats_app:auth:${customer_id}`, {});
chan.on("auth_state", (msg) => {
console.log("get state");
console.log(msg);
let auth = msg.auth;
let qr_code = msg.qr_code;
let in_progress = msg.in_progress;
this.change_auth_status(auth, qr_code);
this.show_qr_code(auth, qr_code);
this.show_in_progress(in_progress);
});
chan
.join()
.receive("ignore", () => console.log("auth error"))
.receive("ok", () => console.log("join ok"));
chan.onError((e) => console.log("something went wrong", e));
chan.onClose((e) => {
this.show_reboot_page(e);
console.log("channel closed", e);
});
}
}