Skip to content

Commit

Permalink
fix: ws
Browse files Browse the repository at this point in the history
  • Loading branch information
hai-ko committed Nov 9, 2023
1 parent e5c282b commit 6e313f1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
13 changes: 13 additions & 0 deletions docker/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ http {
proxy_set_header Host $host;
}

location /bb-client/socket.io {
rewrite ^/bb-client(.*)$ $1 break;
proxy_pass http://billboard-client:8083/socket.io;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
proxy_set_header Host $host;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Message } from 'dm3-lib-messaging';
import http from 'http';
import { Server, Socket } from 'socket.io';
import { IViewerService } from './IViewerService';
import { logDebug } from 'dm3-lib-shared';

/**
* Creates and returns an instance of a viewer service that manages viewer connections and message broadcasting.
Expand All @@ -20,6 +21,12 @@ export function ViewerService(httpServer: http.Server): IViewerService {
const connections: Map<string, Socket> = new Map();

const addConnection = (connection: Socket) => {
logDebug({
text: '[ViewerService] connect',
id: connection.id,
connectionsSize: connections.size,
});

//When the socket disconnects we wan't them no longer in our viewers List
connection.on('disconnect', () => {
removeConnection(connection);
Expand All @@ -28,10 +35,19 @@ export function ViewerService(httpServer: http.Server): IViewerService {
};

const removeConnection = (connection: Socket) => {
logDebug({
text: '[ViewerService] disconnect',
id: connection.id,
connectionsSize: connections.size,
});
connections.delete(connection.id);
};

const getViewerCount = () => {
logDebug({
text: '[ViewerService] getViewerCount',
connectionsSize: connections.size,
});
return connections.size;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/billboard-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dm3-billboard-widget",
"version": "0.3.0",
"version": "0.3.1",
"files": [
"dist"
],
Expand Down
7 changes: 1 addition & 6 deletions packages/lib/delivery/src/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ export async function submitUserProfile(
send: (socketId: string) => void,
): Promise<string> {
const account = normalizeEnsName(ensName);
console.log('1', account, signedUserProfile);

if (!(await checkUserProfile(provider, signedUserProfile, account))) {
throw Error('Signature invalid.');
}
console.log('2', process.env.DISABLE_SESSION_CHECK);
//TODO: remvoe DISABLE_SESSION_CHECK
// DISABLE_SESSION_CHECK is a special solution for ETH Prague
if (
Expand All @@ -52,25 +50,22 @@ export async function submitUserProfile(
) {
throw Error('Profile exists already');
}
console.log('3');
const session: Session = {
account,
signedUserProfile,
token: uuidv4(),
createdAt: new Date().getTime(),
profileExtension: getDefaultProfileExtension(),
};
console.log('4', session);

await setSession(account.toLocaleLowerCase(), session);
console.log('5');
await handlePendingConversations(
account,
getSession,
getPendingConversations,
send,
);
console.log('6');

return session.token;
}

Expand Down

0 comments on commit 6e313f1

Please sign in to comment.