Skip to content

Commit

Permalink
fix: ws
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-ko committed Oct 25, 2023
1 parent 3603bde commit 6e07662
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ services:
SIGNING_PUBLIC_KEY: ${SIGNING_PUBLIC_KEY}
SIGNING_PRIVATE_KEY: ${SIGNING_PRIVATE_KEY}
ENCRYPTION_PUBLIC_KEY: ${ENCRYPTION_PUBLIC_KEY}
ENCRYPTION_PRIVATE_KEY: ${ENCRYPTION_PUBLIC_KEY}
ENCRYPTION_PRIVATE_KEY: ${ENCRYPTION_PRIVATE_KEY}
RPC: ${RPC}
PORT: 8081
LOG_LEVEL: 'debug'
Expand Down
4 changes: 3 additions & 1 deletion docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ http {
}

location /socket.io {
proxy_pass http://backend:8081/socket.io/;
proxy_pass http://backend:8081/socket.io;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
Expand All @@ -69,5 +69,7 @@ http {
proxy_redirect off;
proxy_set_header Host $host;
}


}
}
4 changes: 4 additions & 0 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ global.logger = winston.createLogger({
app.locals.io = io;

app.locals.keys = readKeysFromEnv(process.env);
logInfo({
text: 'keys',
keys: app.locals.keys,
});

app.locals.deliveryServiceProperties = getDeliveryServiceProperties();

Expand Down
23 changes: 14 additions & 9 deletions packages/backend/src/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const pendingMessageSchema = {
export function onConnection(app: express.Application & WithLocals) {
return (socket: Socket) => {
socket.on('disconnect', () => {
app.locals.logger.info({
global.logger.info({
method: 'WS DISCONNECT',
socketId: socket.id,
});
Expand All @@ -36,7 +36,7 @@ export function onConnection(app: express.Application & WithLocals) {
callback,
) => {
try {
app.locals.logger.info({
global.logger.info({
method: 'WS INCOMING MESSAGE',
});

Expand All @@ -48,13 +48,18 @@ export function onConnection(app: express.Application & WithLocals) {
if (!isSchemaValid) {
const error = 'invalid schema';

app.locals.logger.warn({
global.logger.warn({
method: 'WS SUBMIT MESSAGE',
error,
});
return callback({ error });
}

global.logger.info({
method: 'WS INCOMING MESSAGE',
keys: app.locals.keys.encryption,
});

await incomingMessage(
data,
app.locals.keys.signing,
Expand All @@ -75,7 +80,7 @@ export function onConnection(app: express.Application & WithLocals) {
),
callback({ response: 'success' });
} catch (error: any) {
app.locals.logger.warn({
global.logger.warn({
method: 'WS SUBMIT MESSAGE',
error: (error as Error).toString(),
});
Expand All @@ -90,7 +95,7 @@ export function onConnection(app: express.Application & WithLocals) {
if (!isSchemaValid) {
const error = 'invalid schema';

app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});
Expand All @@ -109,15 +114,15 @@ export function onConnection(app: express.Application & WithLocals) {
contactEnsName,
);
} catch (error) {
app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});

return callback({ error });
}

app.locals.logger.info({
global.logger.info({
method: 'WS PENDING MESSAGE',
ensName,
contactEnsName,
Expand All @@ -132,7 +137,7 @@ export function onConnection(app: express.Application & WithLocals) {
))
) {
const error = 'Token check failed';
app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error,
});
Expand All @@ -143,7 +148,7 @@ export function onConnection(app: express.Application & WithLocals) {

callback({ response: 'success' });
} catch (error) {
app.locals.logger.warn({
global.logger.warn({
method: 'WS PENDING MESSAGE',
error: (error as Error).toString(),
});
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function socketAuth(app: Express & WithLocals) {
socket.handshake.auth.account.ensName,
);

app.locals.logger.info({
global.logger.info({
method: 'WS CONNECT',
ensName,
socketId: socket.id,
Expand Down
7 changes: 6 additions & 1 deletion packages/lib/delivery/src/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ export async function incomingMessage(
getIdEnsName: (name: string) => Promise<string>,
getUsersNotificationChannels: GetNotificationChannels,
): Promise<void> {
logDebug({ text: 'incomingMessage', token });
logDebug({
text: 'incomingMessage',
token,
encryptionKeyPair,
envelop: JSON.stringify(envelop),
});
//Checks the size of the incoming message
if (messageIsToLarge(envelop, sizeLimit)) {
throw Error('Message is too large');
Expand Down
3 changes: 3 additions & 0 deletions packages/messenger-widget/src/adapters/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export async function submitMessage(
sendDependencies,
);

console.log('### send');

Check failure on line 93 in packages/messenger-widget/src/adapters/messages.ts

View workflow job for this annotation

GitHub Actions / code-quality

Unexpected console statement
console.log(envelop, sendDependencies);

Check failure on line 94 in packages/messenger-widget/src/adapters/messages.ts

View workflow job for this annotation

GitHub Actions / code-quality

Unexpected console statement

const allOnSuccess = () => {
if (onSuccess) {
onSuccess(envelop);
Expand Down
4 changes: 3 additions & 1 deletion packages/messenger-widget/src/components/DM3/DM3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ function DM3(props: Dm3Props) {
throw Error('Could not get account profile');
}

const socket = socketIOClient(deliveryServiceUrl, {


const socket = socketIOClient(deliveryServiceUrl.replace('/api', ''), {
autoConnect: false,
transports: ['websocket'],
});
Expand Down

0 comments on commit 6e07662

Please sign in to comment.