This is an automated email from the git hooks/post-receive script.
cohosh pushed a change to branch main in repository pluggable-transports/snowflake-webext.
from 225a7d2 fix for #41 ui shows disabled correctly when disabling active snowflake badge new b3636e5 allow multiple clients new 07742be removed obsolete comments
The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference.
Summary of changes: init-badge.js | 8 +++----- init-testing.js | 11 ++++++++--- init-webext.js | 7 +------ proxypair.js | 16 +++++++++++----- snowflake.js | 1 - spec/init.spec.js | 6 +++--- spec/ui.spec.js | 4 ++-- ui.js | 24 +++++++++++++++++++----- webext/embed.js | 4 +--- 9 files changed, 48 insertions(+), 33 deletions(-)
This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit b3636e5a6af43d2543917e1c1f299377b61fac52 Author: 5eba 5eba@untiy-mail.de AuthorDate: Sat Mar 19 11:08:32 2022 +0100
allow multiple clients --- init-badge.js | 8 +++----- init-testing.js | 11 ++++++++--- init-webext.js | 7 +------ proxypair.js | 14 +++++++++++--- spec/init.spec.js | 6 +++--- spec/ui.spec.js | 4 ++-- ui.js | 24 +++++++++++++++++++----- webext/embed.js | 4 +--- 8 files changed, 48 insertions(+), 30 deletions(-)
diff --git a/init-badge.js b/init-badge.js index da50045..f4dd7ff 100644 --- a/init-badge.js +++ b/init-badge.js @@ -62,8 +62,7 @@ class BadgeUI extends UI {
turnOn() { this.enabled = true; - const clients = this.active ? 1 : 0; - if (clients > 0) { + if (this.clients > 0) { this.setIcon('running'); } else { this.setIcon('on'); @@ -71,7 +70,7 @@ class BadgeUI extends UI { const total = this.stats.reduce((function(t, c) { return t + c; }), 0); - this.popup.turnOn(clients, total); + this.popup.turnOn(this.clients, total); }
turnOff() { @@ -80,8 +79,7 @@ class BadgeUI extends UI { this.popup.turnOff(); }
- setActive(connected) { - super.setActive(connected); + postActive() { if(this.enabled) { this.turnOn(); } diff --git a/init-testing.js b/init-testing.js index 01b6147..7724004 100644 --- a/init-testing.js +++ b/init-testing.js @@ -24,9 +24,14 @@ class DebugUI extends UI { return this.$status.appendChild(txt); }
- setActive(connected) { - super.setActive(connected); - return this.$msglog.className = connected ? 'active' : ''; + increaseClients() { + super.increaseClients(); + return this.$msglog.className = this.active ? 'active' : ''; + } + + decreaseClients() { + super.decreaseClients(); + return this.$msglog.className = this.active ? 'active' : ''; }
log(msg) { diff --git a/init-webext.js b/init-webext.js index d527bb8..6c13e7f 100644 --- a/init-webext.js +++ b/init-webext.js @@ -76,7 +76,7 @@ class WebExtUI extends UI { this.setIcon(); if (!this.port) { return; } this.port.postMessage({ - active: this.active, + clients: this.clients, total: this.stats.reduce((function(t, c) { return t + c; }), 0), @@ -111,11 +111,6 @@ class WebExtUI extends UI { this.port = null; }
- setActive(connected) { - super.setActive(connected); - this.postActive(); - } - setEnabled(enabled) { this.enabled = enabled; this.postActive(); diff --git a/proxypair.js b/proxypair.js index 93efd5a..4066c02 100644 --- a/proxypair.js +++ b/proxypair.js @@ -31,6 +31,7 @@ class ProxyPair { this.id = Util.genSnowflakeID(); this.c2rSchedule = []; this.r2cSchedule = []; + this.counted = false; }
// Prepare a WebRTC PeerConnection and await for an SDP offer. @@ -74,7 +75,8 @@ class ProxyPair { prepareDataChannel(channel) { channel.onopen = () => { log('WebRTC DataChannel opened!'); - snowflake.ui.setActive(true); + snowflake.ui.increaseClients(); + this.counted = true; // This is the point when the WebRTC datachannel is done, so the next step // is to establish websocket to the server. return this.connectRelay(); @@ -82,7 +84,10 @@ class ProxyPair { channel.onclose = () => { log('WebRTC DataChannel closed.'); snowflake.ui.setStatus('disconnected by webrtc.'); - snowflake.ui.setActive(false); + if(this.counted) { + snowflake.ui.decreaseClients(); + this.counted = false; + } this.flush(); return this.close(); }; @@ -122,7 +127,10 @@ class ProxyPair { this.relay.onclose = () => { log(relay.label + ' closed.'); snowflake.ui.setStatus('disconnected.'); - snowflake.ui.setActive(false); + if(this.counted) { + snowflake.ui.decreaseClients(); + this.counted = false; + } this.flush(); return this.close(); }; diff --git a/spec/init.spec.js b/spec/init.spec.js index 593add9..77d4bad 100644 --- a/spec/init.spec.js +++ b/spec/init.spec.js @@ -13,11 +13,11 @@ describe('Init', function() {
it('gives a dialog when closing, only while active', function() { silenceNotifications = false; - ui.setActive(true); + ui.increaseClients(); var msg = window.onbeforeunload(); expect(ui.active).toBe(true); expect(msg).toBe(Snowflake.MESSAGE.CONFIRMATION); - ui.setActive(false); + ui.decreaseClients(); msg = window.onbeforeunload(); expect(ui.active).toBe(false); expect(msg).toBe(null); @@ -25,7 +25,7 @@ describe('Init', function() {
it('does not give a dialog when silent flag is on', function() { silenceNotifications = true; - ui.setActive(true); + ui.increaseClients(); var msg = window.onbeforeunload(); expect(ui.active).toBe(true); expect(msg).toBe(null); diff --git a/spec/ui.spec.js b/spec/ui.spec.js index dc9aa35..e860a17 100644 --- a/spec/ui.spec.js +++ b/spec/ui.spec.js @@ -46,9 +46,9 @@ describe('UI', function() { it('sets message log css correctly for debug mode', function() { var u; u = new DebugUI(); - u.setActive(true); + u.increaseClients(); expect(u.$msglog.className).toEqual('active'); - u.setActive(false); + u.decreaseClients(); expect(u.$msglog.className).toEqual(''); });
diff --git a/ui.js b/ui.js index f1d846a..de8670d 100644 --- a/ui.js +++ b/ui.js @@ -19,16 +19,30 @@ class UI {
setStatus() {}
- setActive(connected) { - if (connected) { - this.stats[0] += 1; + get active() { + return this.clients > 0; + } + + postActive() {} + + increaseClients() { + this.clients += 1; + this.postActive(); + return this.clients; + } + + decreaseClients() { + this.clients -= 1; + if(this.clients < 0) { + this.clients = 0; } - return this.active = connected; + this.postActive(); + return this.clients; }
log() {}
}
-UI.prototype.active = false; +UI.prototype.clients = 0; UI.prototype.stats = null; diff --git a/webext/embed.js b/webext/embed.js index c17f602..c108f82 100644 --- a/webext/embed.js +++ b/webext/embed.js @@ -12,7 +12,7 @@ const port = chrome.runtime.connect({ });
port.onMessage.addListener((m) => { - const { active, enabled, total, missingFeature } = m; + const { clients, enabled, total, missingFeature } = m; const popup = new Popup( (...args) => chrome.i18n.getMessage(...args), (event) => port.postMessage({ enabled: event.target.checked }), @@ -24,8 +24,6 @@ port.onMessage.addListener((m) => { return; }
- const clients = active ? 1 : 0; - if (enabled) { popup.turnOn(clients, total); } else {
This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 07742beb2779d9d05646f1849495a14bda724664 Author: 5eba 5eba@untiy-mail.de AuthorDate: Tue Mar 22 17:39:00 2022 +0100
removed obsolete comments --- proxypair.js | 2 -- snowflake.js | 1 - 2 files changed, 3 deletions(-)
diff --git a/proxypair.js b/proxypair.js index 4066c02..169511b 100644 --- a/proxypair.js +++ b/proxypair.js @@ -40,8 +40,6 @@ class ProxyPair { this.pc.onicecandidate = (evt) => { // Browser sends a null candidate once the ICE gathering completes. if (null === evt.candidate && this.pc.connectionState !== 'closed') { - // TODO: Use a promise.all to tell Snowflake about all offers at once, - // once multiple proxypairs are supported. dbg('Finished gathering ICE candidates.'); snowflake.broker.sendAnswer(this.id, this.pc.localDescription); } diff --git a/snowflake.js b/snowflake.js index 4e9396e..03b0229 100644 --- a/snowflake.js +++ b/snowflake.js @@ -11,7 +11,6 @@ this proxy must always act as the answerer. TODO: More documentation */
-// Minimum viable snowflake for now - just 1 client. class Snowflake {
// Prepare the Snowflake with a Broker (to find clients) and optional UI.
tor-commits@lists.torproject.org