const store = require("./utils/store");
const { postLogin } = require("./api");
-const { ipcEmit } = require("./utils/emitter");
const { launchSession, endSession } = require("./session");
+const { backgroundMitt, ipcEmit } = require("./utils/emitter");
-store.set("account", "smith12@gmail.com");
-store.set("account", "adgundersen@gmail.com");
+store.set("account", "0000");
async function login(_e, email, password)
{
const res = await postLogin(email, password);
if (res)
{
- const account = res.crimataId;
+ const account = res.token;
store.set("account", account);
ipcEmit("set-account", account);
+
launchSession(account);
+
return true;
}
else
}
};
-function logout()
+function logout(reason)
{
store.delete("account");
- ipcEmit("set-account", false);
+ ipcEmit("set-account", false, reason);
endSession();
};
if (account) launchSession(account);
}
+backgroundMitt.on("logout", (reason) => logout(reason));
+
exports.initAccount = initAccount;
const config = require("./config");
-const baseUrl = config.BUSINESS_URL + config.BUSINESS_PREFIX;
-
async function postLogin(email, password)
{
try {
- const res = await axios.post(baseUrl + "/account/login", {
+ const res = await axios.post(config.API + "/login", {
email: email, password: password
});
return res.data;
const { app } = require("electron");
-const env = process.env;
+const DOMAIN = "crimata.com";
+const PORT = 8760;
-const PLATFORM_PORT = env.PLATFORM_PORT || 8760;
-const PLATFORM_IP = env.PLATFORM_IP || 'http://127.0.0.1';
+module.exports = {
-const BUSINESS_PORT = env.BUSINESS_PORT || 3000;
-const BUSINESS_IP = env.BUSINESS_IP || 'http://127.0.0.1';
+PLATFORM: app.isPackaged ? `http://app.${DOMAIN}` : `http://localhost:${PORT}`,
+API: `https://${DOMAIN}/api`
-module.exports = {
- PLATFORM_URL: `${PLATFORM_IP}:${PLATFORM_PORT}`,
- BUSINESS_URL: `${BUSINESS_IP}:${BUSINESS_PORT}`,
- BUSINESS_PREFIX: '/api',
- configPath: app.getPath('userData'),
-}
\ No newline at end of file
+}
{
if (pingId) clearInterval(pingId);
- connection = new WebSocket(`${config.PLATFORM_URL}/${account}`)
+ connection = new WebSocket(`${config.PLATFORM}/${account}`)
.on("open", () => pingId = setInterval(() => connection.ping(null, true), 1000))
.on("message", (payload) => backgroundMitt.emit("message", JSON.parse(payload)))
- .on("close", (code, reason) => {
+ .on("close", (_code, reason) => {
+
setConnectionStatus(1);
- if (reason !== "logout") {
- reconnectId = setTimeout(() => connectToPlatform(account), 500);
+
+ if (reason)
+ {
+ if (reason == "unauthorized")
+ {
+ backgroundMitt.emit("logout", reason);
+ }
+
+ return;
}
+
+ reconnectId = setTimeout(() => connectToPlatform(account), 500);
+
});
}
function disconnectFromPlatform()
{
clearTimeout(reconnectId);
- connection.close(1000, "logout");
+ if (connection.open) connection.close(1000, "logout");
}
function setConnectionStatus(status)
const { initAccount } = require("./account");
const { terminateAudio } = require("./audio");
-app.commandLine.appendSwitch("enable-transparent-visuals");
-
// Assert a light theme
nativeTheme.themeSource = "light";
<Splash v-else />`
}
-window.mainApi.on("set-account", (account_) => {
- account.value = account_;
+window.mainApi.on("set-account", (value, reason) => {
+ if (reason) alert(reason);
+ account.value = value;
});
export default App;
export { account };
// Is called when window is about to close or reload
-window.onbeforeunload = () => console.log("beforeunload");
\ No newline at end of file
+window.onbeforeunload = () => console.log("beforeunload");
});
}
-export default onDrop;
\ No newline at end of file
+export default onDrop;
}
.login-input {
- background-color: #B9B9B9;
+ background-color: #D3D3D3;
border: none;
outline: none;
padding: 16px;
const { connectToPlatform, disconnectFromPlatform } = require("./io");
const { initAudio, terminateAudio, playback, streamState } = require("./audio");
+const util = require('util');
let ui;
const messageQueue = [];
{
const update = messageQueue.shift();
+ console.log(util.inspect(update, false, null, true /* enable colors */));
+
if (update)
{
if (update.person)