Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mobile and sockets (v3) #293

Merged
merged 6 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ server {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
}
```
Expand Down
23 changes: 16 additions & 7 deletions client/src/components/navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export default function Navbar(props) {
HomeService.unfreezeQueue();
};

const [notificationPermission, setNotificationPermission] = useState(Notification.permission);
const defaultNotificationPermission = ('Notification' in window) ? Notification.permission : 'denied';
const [notificationPermission, setNotificationPermission] = useState(defaultNotificationPermission);

const unfreezeButton = <Button color="secondary" variant="contained" sx={{mx: 2}} onClick={unfreezeQueue}>Unfreeze</Button>;
const freezeButton = <Button color="secondary" variant="contained" sx={{mx: 2}} onClick={freezeQueue}>Freeze</Button>;
Expand Down Expand Up @@ -152,9 +153,13 @@ export default function Navbar(props) {
}
{
notificationPermission !== 'granted' && (
<MenuItem onClick={() => Notification.requestPermission((permission) => {
setNotificationPermission(permission);
})}>
<MenuItem onClick={() => {
if ('Notification' in window) {
Notification.requestPermission((permission) => {
setNotificationPermission(permission);
});
}
}}>
<Typography variant='subtitle2' sx={{mx: 2}}>
Enable Notifications
</Typography>
Expand Down Expand Up @@ -210,9 +215,13 @@ export default function Navbar(props) {
}
{
notificationPermission !== 'granted' && (
<IconButton color="secondary" onClick={() => Notification.requestPermission((permission) => {
setNotificationPermission(permission);
})}>
<IconButton color="secondary" onClick={() => {
if ('Notification' in window) {
Notification.requestPermission((permission) => {
setNotificationPermission(permission);
});
}
}}>
<NotificationsActive />
</IconButton>
)
Expand Down
19 changes: 11 additions & 8 deletions client/src/services/SocketsService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ export const initiateSocket = () => {
}

socket.on('disconnect', (reason, details) => {
console.log('Client disconnected', reason, details);
console.log('Client disconnected, reconnecting', reason, details);

if (!socket.active) {
console.log('Inactive socket connection');
setTimeout(() => {
socket.connect();
}
}, 1000);
});

socket.on('connect_error', (error) => {
console.log('Connection error', error.message);
if (!socket.active) {
console.log('Inactive socket connection');
console.log('Connection error, reconnecting', error.message);
setTimeout(() => {
socket.connect();
}
}, 1000);
});

// dumbass brute force so nginx doesn't kill us
setInterval(() => {
socket.emit('ping');
}, 5000);
};

export const socketSubscribeTo = (emission, callback) => {
Expand Down
3 changes: 3 additions & 0 deletions server/controllers/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ let student_room = crypto.randomBytes(72).toString('base64');
*/
exports.init = function (server) {
sio = require("socket.io")(server, {
pingTimeout: 45000,
pingInterval: 2000,
maxHttpBufferSize: 1e7,
cors: {
origin: config.PROTOCOL + "://" + config.DOMAIN + ":" + config.CLIENT_PORT,
methods: ["GET", "POST"]
Expand Down