Skip to content

Commit

Permalink
fix: add on scoket message an requestId
Browse files Browse the repository at this point in the history
  • Loading branch information
guimroque committed Apr 24, 2024
1 parent 38d5691 commit 401f898
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/modules/dApps/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class DappController {

async connect({ body }: ICreateRequest) {
try {
const { vaultId, sessionId, name, origin, userAddress } = body;
const { vaultId, sessionId, name, origin, userAddress, request_id } = body;
const predicate = await new PredicateService().findById(vaultId);
let dapp = await new DAppsService().findBySessionID(sessionId, origin);
const user = await User.findOne({ where: { address: userAddress } });
Expand All @@ -50,11 +50,12 @@ export class DappController {
}
dapp.currentVault = predicate;
await dapp.save();

//console.log('[api]: ', dapp, sessionId, request_id);
const socket = new SocketClient(sessionId, origin);
socket.sendMessage({
room: sessionId,
sessionId,
to: '[CONNECTOR]',
request_id,
type: '[AUTH_CONFIRMED]',
data: {
connected: true,
Expand Down
1 change: 1 addition & 0 deletions src/modules/dApps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ICreateRequestSchema extends ValidatedRequestSchema {
> & {
vaultId: string;
userAddress: string;
request_id: string;
};
[ContainerTypes.Headers]: {
origin: string;
Expand Down
3 changes: 2 additions & 1 deletion src/socket/client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { io, Socket } from 'socket.io-client';

interface IMessage {
room: string; // sessionId
sessionId: string; // sessionId
to: string; // username -> recebe a mensagem '[UI]' por exemplo
type: string; // tipo da mensagem/evento
data: { [key: string]: any };
request_id: string;
}

export class SocketClient {
Expand Down

0 comments on commit 401f898

Please sign in to comment.