Skip to content

Commit

Permalink
Merge pull request #215 from dvbern/disable-websocket-in-static-mode
Browse files Browse the repository at this point in the history
Disable viewer websocket connection if mode is static
  • Loading branch information
th0r committed Oct 16, 2018
2 parents aad11d1 + 256f55f commit 5be7049
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion client/viewer.jsx
Expand Up @@ -9,7 +9,9 @@ import styles from './viewer.css';
// Initializing WebSocket for live treemap updates
let ws;
try {
ws = new WebSocket(`ws://${location.host}`);
if (window.enableWebSocket) {
ws = new WebSocket(`ws://${location.host}`);
}
} catch (err) {
console.warn(
"Couldn't connect to analyzer websocket server so you'll have to reload page manually to see updates in the treemap"
Expand Down
6 changes: 4 additions & 2 deletions src/viewer.js
Expand Up @@ -52,7 +52,8 @@ async function startServer(bundleStats, opts) {
res.render('viewer', {
mode: 'server',
get chartData() { return JSON.stringify(chartData) },
defaultSizes: JSON.stringify(defaultSizes)
defaultSizes: JSON.stringify(defaultSizes),
enableWebSocket: true
});
});

Expand Down Expand Up @@ -130,7 +131,8 @@ function generateReport(bundleStats, opts) {
mode: 'static',
chartData: JSON.stringify(chartData),
assetContent: getAssetContent,
defaultSizes: JSON.stringify(defaultSizes)
defaultSizes: JSON.stringify(defaultSizes),
enableWebSocket: false
},
(err, reportHtml) => {
if (err) return logger.error(err);
Expand Down
1 change: 1 addition & 0 deletions views/viewer.ejs
Expand Up @@ -13,6 +13,7 @@
<script>
window.chartData = <%- chartData %>;
window.defaultSizes = <%- defaultSizes %>;
window.enableWebSocket = <%- enableWebSocket %>;
</script>
</body>
</html>

0 comments on commit 5be7049

Please sign in to comment.