Replace InitMessage with HandshaleMessage
This commit is contained in:
parent
ca3125b5d1
commit
128a588c9b
@ -3,7 +3,7 @@ import { INotification } from '~/models/notification.model';
|
||||
import { IProcess } from '~/models/process.model';
|
||||
// import Database from './database';
|
||||
import { initWebsocket, sendMessage } from '../websockets';
|
||||
import { ApiReturn, Device, InitMessage, Member, Process, RoleDefinition, SecretsStore, UserDiff } from '../../pkg/sdk_client';
|
||||
import { ApiReturn, Device, HandshakeMessage, Member, Process, RoleDefinition, SecretsStore, UserDiff } from '../../pkg/sdk_client';
|
||||
import ModalService from './modal.service';
|
||||
import Database from './database.service';
|
||||
import { storeData, retrieveData } from './storage.service';
|
||||
@ -30,6 +30,7 @@ export default class Services {
|
||||
private database: any;
|
||||
private routingInstance!: ModalService;
|
||||
private relayAddresses: { [wsurl: string]: string } = {};
|
||||
private membersList: Record<any, Process> = {};
|
||||
// Private constructor to prevent direct instantiation from outside
|
||||
private constructor() {}
|
||||
|
||||
@ -898,18 +899,16 @@ export default class Services {
|
||||
this.device2Ready = false;
|
||||
}
|
||||
|
||||
public async handleInitMsg(url: string, parsedMsg: any) {
|
||||
public async handleHandshakeMsg(url: string, parsedMsg: any) {
|
||||
try {
|
||||
const initMsg: InitMessage = JSON.parse(parsedMsg);
|
||||
this.updateRelay(url, initMsg.sp_address);
|
||||
const processes: [string, Process][] = JSON.parse(initMsg.processes_list!);
|
||||
const handshakeMsg: HandshakeMessage = JSON.parse(parsedMsg);
|
||||
this.updateRelay(url, handshakeMsg.sp_address);
|
||||
const processes = handshakeMsg.processes_list;
|
||||
this.membersList = handshakeMsg.peers_list;
|
||||
|
||||
// Write processes to db
|
||||
const record = processes.reduce((record, [outPoint, process]) => {
|
||||
record[outPoint] = process;
|
||||
return record;
|
||||
}, {} as Record<string, Process>);
|
||||
setTimeout(async () => {
|
||||
await this.restoreProcessesFromBackUp(record);
|
||||
await this.restoreProcessesFromBackUp(processes);
|
||||
}, 500)
|
||||
} catch (e) {
|
||||
console.error('Failed to parse init message:', e);
|
||||
|
@ -29,8 +29,8 @@ export async function initWebsocket(url: string) {
|
||||
const parsedMessage = JSON.parse(msgData);
|
||||
const services = await Services.getInstance();
|
||||
switch (parsedMessage.flag) {
|
||||
case 'Init':
|
||||
await services.handleInitMsg(url, parsedMessage.content);
|
||||
case 'Handshake':
|
||||
await services.handleHandshakeMsg(url, parsedMessage.content);
|
||||
break;
|
||||
case 'NewTx':
|
||||
await services.parseNewTx(parsedMessage.content);
|
||||
|
Loading…
x
Reference in New Issue
Block a user