feat: add auth route, update machine status
Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
parent
4578a43197
commit
60424ebe5a
11 changed files with 107 additions and 20 deletions
|
|
@ -236,6 +236,11 @@ async function connectToAndroidServer() {
|
|||
addNotification('INFO:Enable Brewing Mode T on machine');
|
||||
} else {
|
||||
addNotification('WARN:Brewing Mode T unavailable');
|
||||
|
||||
setTimeout(async () => {
|
||||
console.log('reconnecting android server');
|
||||
await connectToAndroidServer();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,13 @@ async function handleAdbPayload(raw_payload: string) {
|
|||
}
|
||||
})
|
||||
);
|
||||
} else if (raw_payload.startsWith('state')) {
|
||||
let res = raw_payload.split('/');
|
||||
let new_machine_state = res[1] ?? '';
|
||||
|
||||
if (new_machine_state != '') {
|
||||
updateMachineStatus(new_machine_state.replace('MACHINE_STATE_', ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -68,6 +75,7 @@ async function handleAdbPayload(raw_payload: string) {
|
|||
let total_time = plist[1] ?? '';
|
||||
|
||||
// update recipe data store
|
||||
console.log('brewing finish', pd, 'total time', total_time);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ async function sendToAndroid(message: any) {
|
|||
let writer: any = get(adbWriter);
|
||||
console.log('writer', writer);
|
||||
if (!writer) {
|
||||
addNotification('ERR:No active connection');
|
||||
// addNotification('ERR:No active connection');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const encoder = new TextEncoder();
|
||||
console.log(writer);
|
||||
// console.log(writer);
|
||||
await writer.write(encoder.encode(JSON.stringify(message) + '\n'));
|
||||
console.log('sent! ', JSON.stringify(message));
|
||||
console.log('sent! ', JSON.stringify(message).length);
|
||||
} catch (error) {
|
||||
console.error('write failed', error);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export const socketConnectionOfflineCount = writable<number>(0);
|
|||
export const socketAlreadySendHeartbeat = writable<number>(0);
|
||||
export const socketStore = writable<WebSocket | null>(null);
|
||||
|
||||
export function connectToWebsocket() {
|
||||
export function connectToWebsocket(id_token?: string) {
|
||||
if (browser) {
|
||||
// console.log('connecting to ', env.PUBLIC_WSS);
|
||||
try {
|
||||
|
|
@ -24,7 +24,10 @@ export function connectToWebsocket() {
|
|||
return;
|
||||
}
|
||||
|
||||
socket = new WebSocket(`${env.PUBLIC_WSS}`);
|
||||
let productionMode = env.PUBLIC_WSS.startsWith('wss');
|
||||
|
||||
let ws_url = productionMode ? `${env.PUBLIC_WSS}?token=${id_token}` : `${env.PUBLIC_WSS}`;
|
||||
socket = new WebSocket(ws_url);
|
||||
|
||||
socket.addEventListener('open', () => {
|
||||
socketStore.set(socket);
|
||||
|
|
@ -64,7 +67,7 @@ export function connectToWebsocket() {
|
|||
socketConnectionOfflineCount.set(0);
|
||||
socketAlreadySendHeartbeat.set(0);
|
||||
|
||||
connectToWebsocket();
|
||||
connectToWebsocket(id_token);
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -87,7 +90,7 @@ export function connectToWebsocket() {
|
|||
console.log('try reconnect websocket ...');
|
||||
// retry again
|
||||
reconnectTimeout = setTimeout(() => {
|
||||
connectToWebsocket();
|
||||
connectToWebsocket(id_token);
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
|
@ -103,7 +106,7 @@ export function connectToWebsocket() {
|
|||
if (auth.currentUser && !socket) {
|
||||
console.log('try reconnect websocket ...');
|
||||
// retry again
|
||||
reconnectTimeout = setTimeout(() => connectToWebsocket(), 5000);
|
||||
reconnectTimeout = setTimeout(() => connectToWebsocket(id_token), 5000);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue