Skip to content

Commit

Permalink
fix: remove commented codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuzhy-Deriv committed Oct 21, 2024
1 parent 1957b64 commit 12192ba
Showing 1 changed file with 2 additions and 136 deletions.
138 changes: 2 additions & 136 deletions public/scripts/freshchat-temp.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,3 @@
// const getJWT = async (hostname, appID, uuid, getTokenForWS, callDerivWS) => {
// let extra_fields = {};
// if (uuid) {
// extra_fields.freshchat_uuid = uuid;
// }
// const token = await getTokenForWS();
// let jwt;
// const result = await callDerivWS(
// hostname,
// appID,
// {
// service_token: 1,
// extra_fields: extra_fields,
// service: "freshworks_user_jwt",
// },
// token
// );
// jwt = result?.service_token?.freshworks_user_jwt?.token;

// return jwt;
// };

const parseJwt = (jwt) => {
if (!jwt) return {};
var base64Url = jwt.split(".")[1];
var base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
var jsonPayload = decodeURIComponent(
window
.atob(base64)
.split("")
.map(function (c) {
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
})
.join("")
);

return JSON.parse(jsonPayload);
};

// const callDerivWS = async (hostname, appId, params, token) => {
// return new Promise((resolve, reject) => {
// const wsUri = `wss://${hostname}/websockets/v3?app_id=${appId}&l=EN&brand=deriv`;
// const ws = new WebSocket(wsUri);
// let next_id = 1;
// let requests = {};
// let isAuthorized = false;

// ws.addEventListener("error", (e) => {
// ws.close();
// reject("Error connecting to deriv WS " + hostname);
// });

// const send = (msg) => {
// if (!msg.req_id) {
// msg.req_id = next_id++;
// }
// requests[msg.req_id] = { start: new Date().getTime(), msg: msg };
// ws.send(JSON.stringify(msg));
// };

// ws.addEventListener("close", function close() {
// reject("Deriv WS unexpected close" + hostname);
// });

// ws.addEventListener("open", function open() {
// send({ authorize: token });
// });

// ws.addEventListener("message", function message(data) {
// if (typeof data === "object") {
// let jsonStr = data.data;
// let json = JSON.parse(jsonStr);
// if (typeof json === "object" && "authorize" in json && !isAuthorized) {
// isAuthorized = true; // Prevents reauthorization
// send(params); // Send params after first authorization
// } else {
// resolve(json);
// ws.close();
// }
// } else {
// reject("Unexpected message from deriv WS " + hostname);
// }
// });
// });
// };

class FreshChat {
tokenForWS = undefined;
hostname = localStorage.getItem("config.server_url");
Expand All @@ -104,17 +18,10 @@ class FreshChat {

let jwt = null;
if (this.authToken) {
// jwt = await getJWT(
// this.hostname,
// this.appId,
// null,
// this.getTokenForWS,
// this.callDerivWS
// );
jwt = await this.fetchJWTToken({
token: this.authToken,
// appId: this.appId,
// server: this.hostname,
appId: this.appId,
server: this.hostname,
});
}

Expand Down Expand Up @@ -177,47 +84,6 @@ class FreshChat {
return null;
}
};

// getTokenForWS = async () => {
// return new Promise((resolve, reject) => {
// if (this.tokenForWS) {
// resolve(this.tokenForWS.token);
// return;
// }

// if (/^a1-.{29,29}$/.test(this.authToken)) {
// this.tokenForWS = { token: this.authToken };
// resolve(this.authToken);
// } else if (/./.test(this.authToken)) {
// console.log("Invalid token: ", this.authToken);
// }
// });
// };

// clearCookies = () => {
// const cookies = document.cookie.split(";");

// for (let i = 0; i < cookies.length; i++) {
// const cookie = cookies[i];
// const eqPos = cookie.indexOf("=");
// const name = eqPos > -1 ? cookie.substr(0, eqPos).trim() : cookie.trim();

// // Delete cookies for the current path
// document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`;

// // Delete cookies for all possible subdomain paths
// const domainParts = window.location.hostname.split(".");
// while (domainParts.length > 0) {
// const domain = domainParts.join(".");
// document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;domain=.${domain}`;
// domainParts.shift();
// }
// }
// };

// callDerivWS = async (hostname, appId, params, token) => {
// return callDerivWS(hostname, appId, params, token);
// };
}

window.FreshChat = FreshChat;
Expand Down

0 comments on commit 12192ba

Please sign in to comment.