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

Only render things once - fixes #3103 #3107

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
23 changes: 17 additions & 6 deletions static/js/models/gateway-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GatewayModel extends Model {
this.groups = new Map();
this.onMessage = this.onMessage.bind(this);
this.queue = Promise.resolve(true);
this.connectWebSocket();
this.connectWebSockets();
return this;
}

Expand Down Expand Up @@ -137,16 +137,27 @@ class GatewayModel extends Model {
}
}

connectWebSocket() {
connectWebSockets() {
const thingsHref = `${window.location.origin}/things?jwt=${API.jwt}`;
const wsHref = thingsHref.replace(/^http/, 'ws');
this.ws = new ReopeningWebSocket(wsHref);
this.ws.addEventListener('open', this.refreshThings.bind(this));
this.ws.addEventListener('message', this.onMessage);
const groupsHref = `${window.location.origin}/groups?jwt=${API.jwt}`;
const groupsWsHref = groupsHref.replace(/^http/, 'ws');

this.ws = new ReopeningWebSocket(wsHref);
this.groupsWs = new ReopeningWebSocket(groupsWsHref);
this.groupsWs.addEventListener('open', this.refreshThings.bind(this));

// Wait for things and groups sockets to open before showing Things
const thingsReady = new Promise((resolve) => {
this.ws.addEventListener('open', resolve);
});
const groupsReady = new Promise((resolve) => {
this.groupsWs.addEventListener('open', resolve);
});
Promise.all([thingsReady, groupsReady]).then(() => {
this.refreshThings();
});

this.ws.addEventListener('message', this.onMessage);
this.groupsWs.addEventListener('message', this.onMessage);
}

Expand Down