Skip to content

Commit

Permalink
fix duplicated IDs from list() #23
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Sep 16, 2021
1 parent 2a2eeea commit fbf5755
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
23 changes: 14 additions & 9 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
message('just got empty notification');
}
});
function list() {
sysend.list().then(list => {
target.innerHTML = '';
list.forEach(function(uuid) {
var option = document.createElement('option');
option.innerHTML = uuid;
option.value = uuid;
target.appendChild(option);
});
});
}
var a = document.getElementById('a');
var b = document.getElementById('b');
var c = document.getElementById('c');
Expand Down Expand Up @@ -60,17 +71,10 @@
track('send: Welcome');
sysend.post(data.id, 'Welcome');
}
sysend.list().then(list => {
list.forEach(function(uuid) {
var option = document.createElement('option');
option.innerHTML = uuid;
option.value = uuid;
target.appendChild(option);
});
});
list();
});
sysend.track('message', function(data) {
track('message: ' + data.message + ' from ' + data.origin);
track('message: ' + data.data + ' from ' + data.origin);
});
sysend.track('message', function once(data) {
if (!sysend.isPrimary()) {
Expand All @@ -85,6 +89,7 @@
} else {
track('close: ' + id(data.id));
}
list();
});
sysend.track('primary', function() {
track('track: primary');
Expand Down
10 changes: 6 additions & 4 deletions sysend.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@
return new Promise(function(resolve) {
var ids = [];
sysend.on('__window_ack__', function(data) {
ids.push(data.id);
if (data.origin === target_id) {
ids.push(data.id);
}
});
sysend.broadcast('__window__');
sysend.broadcast('__window__', { id: target_id });
setTimeout(function() {
sysend.off('__window_ack__');
resolve(ids);
Expand Down Expand Up @@ -387,8 +389,8 @@
}
});

sysend.on('__window__', function() {
sysend.broadcast('__window_ack__', { id: target_id });
sysend.on('__window__', function(data) {
sysend.broadcast('__window_ack__', { id: target_id, origin: data.id });
});

sysend.on('__message__', function(data) {
Expand Down

0 comments on commit fbf5755

Please sign in to comment.