This is an automated email from the git hooks/post-receive script.
meskio pushed a change to branch main in repository pluggable-transports/snowflake-webext.
from 169c3ea bump version to 0.6.0 new 97db970 refactor: rename `pollTimeout` -> `pollTimeoutId` new 78612d9 refactor: remove some unused `return`, add some JSDocs new 31deee3 refactor: simplify variable declarations new 17168c1 refactor: convert some comments to JSDoc, improve types new 277cfc7 refactor: replace some `function`s with arrow functions new 3c2215a refactor: remove some unused `return` new 3ae64d6 refactor: replace `void 0` with `undefined` new 9ef0843 Merge branch 'mr/31'
The 8 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: broker.js | 58 +++++++++++++------------ config.js | 2 +- init-badge.js | 10 ++--- init-node.js | 2 +- init-testing.js | 21 ++++----- init-webext.js | 16 +++---- proxypair.js | 79 ++++++++++++++++------------------ shims.js | 2 +- snowflake.js | 103 ++++++++++++++++++++++----------------------- spec/util.spec.js | 14 +++--- ui.js | 2 +- util.js | 124 ++++++++++++++++++++++++++++-------------------------- websocket.js | 12 +++--- 13 files changed, 224 insertions(+), 221 deletions(-)
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 97db970c3a757fadd995daad598f40e048a08f16 Author: WofWca wofwca@protonmail.com AuthorDate: Sat Jun 18 17:08:19 2022 +0300
refactor: rename `pollTimeout` -> `pollTimeoutId` --- snowflake.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/snowflake.js b/snowflake.js index 7370f01..a87d7bb 100644 --- a/snowflake.js +++ b/snowflake.js @@ -45,7 +45,7 @@ class Snowflake { // process. |pollBroker| automatically arranges signalling. beginWebRTC() { this.pollBroker(); - return this.pollTimeout = setTimeout((() => { + return this.pollTimeoutId = setTimeout((() => { return this.beginWebRTC(); }), this.pollInterval); } @@ -189,7 +189,7 @@ class Snowflake { disable() { var results; log('Disabling Snowflake.'); - clearTimeout(this.pollTimeout); + clearTimeout(this.pollTimeoutId); results = []; while (this.proxyPairs.length > 0) { results.push(this.proxyPairs.pop().close());
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 78612d975caf1e53c0cd62725bc1e78601028aa0 Author: WofWca wofwca@protonmail.com AuthorDate: Fri Jun 24 22:36:38 2022 +0300
refactor: remove some unused `return`, add some JSDocs
Co-authored-by: meskio meskio@torproject.org --- snowflake.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/snowflake.js b/snowflake.js index a87d7bb..301d4fd 100644 --- a/snowflake.js +++ b/snowflake.js @@ -38,15 +38,14 @@ class Snowflake { setRelayAddr(relayAddr) { this.relayAddr = relayAddr; log('Using ' + relayAddr.host + ':' + relayAddr.port + ' as Relay.'); - return true; }
// Initialize WebRTC PeerConnection, which requires beginning the signalling // process. |pollBroker| automatically arranges signalling. beginWebRTC() { this.pollBroker(); - return this.pollTimeoutId = setTimeout((() => { - return this.beginWebRTC(); + this.pollTimeoutId = setTimeout((() => { + this.beginWebRTC(); }), this.pollInterval); }
@@ -74,10 +73,11 @@ class Snowflake { recv.then((resp) => { var clientNAT = resp.NAT; if (!this.receiveOffer(pair, resp.Offer, resp.RelayURL)) { - return pair.close(); + pair.close(); + return; } //set a timeout for channel creation - return setTimeout((() => { + setTimeout((() => { if (!pair.webrtcIsReady()) { log('proxypair datachannel timed out waiting for open'); pair.close(); @@ -103,13 +103,12 @@ class Snowflake { this.config.defaultBrokerPollInterval); this.natFailures = 0; } - return; }), this.config.datachannelTimeout); }, function () { //on error, close proxy pair - return pair.close(); + pair.close(); }); - return this.retries++; + this.retries++; }
// Receive an SDP offer from some client assigned by the Broker, @@ -152,15 +151,18 @@ class Snowflake { var fail, next; next = function (sdp) { dbg('webrtc: Answer ready.'); - return pair.pc.setLocalDescription(sdp).catch(fail); + pair.pc.setLocalDescription(sdp).catch(fail); }; fail = function () { pair.close(); - return dbg('webrtc: Failed to create or set Answer'); + dbg('webrtc: Failed to create or set Answer'); }; - return pair.pc.createAnswer().then(next).catch(fail); + pair.pc.createAnswer().then(next).catch(fail); }
+ /** + * @returns {null | ProxyPair} + */ makeProxyPair() { if (this.proxyPairs.length >= this.config.maxNumClients) { return null; @@ -178,7 +180,7 @@ class Snowflake { // Delete from the list of proxy pairs. ind = this.proxyPairs.indexOf(pair); if (ind > -1) { - return this.proxyPairs.splice(ind, 1); + this.proxyPairs.splice(ind, 1); } }; pair.begin(); @@ -187,14 +189,11 @@ class Snowflake {
// Stop all proxypairs. disable() { - var results; log('Disabling Snowflake.'); clearTimeout(this.pollTimeoutId); - results = []; while (this.proxyPairs.length > 0) { - results.push(this.proxyPairs.pop().close()); + this.proxyPairs.pop().close(); } - return results; }
/**
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 31deee329a8b364067c0e57a7c780dee38290b75 Author: WofWca wofwca@protonmail.com AuthorDate: Sat Jun 18 18:49:27 2022 +0300
refactor: simplify variable declarations --- broker.js | 10 +++------- init-testing.js | 17 ++++++----------- proxypair.js | 22 +++++++++------------- snowflake.js | 33 +++++++++++++-------------------- util.js | 50 ++++++++++++++++++++------------------------------ 5 files changed, 51 insertions(+), 81 deletions(-)
diff --git a/broker.js b/broker.js index e993a48..8d084e0 100644 --- a/broker.js +++ b/broker.js @@ -41,8 +41,7 @@ class Broker { // TODO: Actually support multiple clients. getClientOffer(id, numClientsConnected) { return new Promise((fulfill, reject) => { - var xhr; - xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.DONE !== xhr.readyState) { return; @@ -81,10 +80,9 @@ class Broker { // Assumes getClientOffer happened, and a WebRTC SDP answer has been generated. // Sends it back to the broker, which passes it to back to the original client. sendAnswer(id, answer) { - var xhr; dbg(id + ' - Sending answer back to broker...\n'); dbg(answer.sdp); - xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.DONE !== xhr.readyState) { return; @@ -109,11 +107,9 @@ class Broker { // urlSuffix for the broker is different depending on what action // is desired. _postRequest(xhr, urlSuffix, payload) { - var err; try { xhr.open('POST', this.url + urlSuffix); - } catch (error) { - err = error; + } catch (err) { /* An exception happens here when, for example, NoScript allows the domain on which the proxy badge runs, but not the domain to which it's trying diff --git a/init-testing.js b/init-testing.js index 7724004..0905b80 100644 --- a/init-testing.js +++ b/init-testing.js @@ -16,8 +16,7 @@ class DebugUI extends UI {
// Status bar setStatus(msg) { - var txt; - txt = document.createTextNode('Status: ' + msg); + const txt = document.createTextNode('Status: ' + msg); while (this.$status.firstChild) { this.$status.removeChild(this.$status.firstChild); } @@ -83,18 +82,14 @@ var snowflake, query, debug, ui, silenceNotifications, log, dbg, init; };
init = function() { - var broker, config, ui; - config = new Config("testing"); + const config = new Config("testing"); if ('off' !== query['ratelimit']) { config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes); } - ui = null; - if (document.getElementById('status') !== null) { - ui = new DebugUI(); - } else { - ui = new UI(); - } - broker = new Broker(config); + const ui = document.getElementById('status') !== null + ? new DebugUI() + : new UI(); + const broker = new Broker(config); snowflake = new Snowflake(config, ui, broker); log('== snowflake proxy =='); if (Util.snowflakeIsDisabled(config.cookieName)) { diff --git a/proxypair.js b/proxypair.js index 1d9689e..e423b59 100644 --- a/proxypair.js +++ b/proxypair.js @@ -47,8 +47,7 @@ class ProxyPair { }; // OnDataChannel triggered remotely from the client when connection succeeds. return this.pc.ondatachannel = (dc) => { - var channel; - channel = dc.channel; + const channel = dc.channel; dbg('Data Channel established...'); this.prepareDataChannel(channel); return this.client = channel; @@ -99,7 +98,6 @@ class ProxyPair {
// Assumes WebRTC datachannel is connected. connectRelay() { - var params, peer_ip, ref; dbg('Connecting to relay...'); // Get a remote IP address from the PeerConnection, if possible. Add it to // the WebSocket URL's query string if available. @@ -108,8 +106,9 @@ class ProxyPair { // are not marked experimental, were undefined when I tried them in Firefox // 52.2.0. // https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/remoteDes... - peer_ip = Parse.ipFromSDP((ref = this.pc.remoteDescription) != null ? ref.sdp : void 0); - params = []; + const desc = this.pc.remoteDescription; + const peer_ip = Parse.ipFromSDP(desc!= null ? desc.sdp : undefined); + const params = []; if (peer_ip != null) { params.push(["client_ip", peer_ip]); } @@ -174,8 +173,7 @@ class ProxyPair { }
onError(event) { - var ws; - ws = event.target; + const ws = event.target; log(ws.label + ' error.'); return this.close(); } @@ -204,25 +202,23 @@ class ProxyPair {
// Send as much data in both directions as the rate limit currently allows. flush() { - var busy, checkChunks; if (this.flush_timeout_id) { clearTimeout(this.flush_timeout_id); } this.flush_timeout_id = null; - busy = true; - checkChunks = () => { - var chunk; + let busy = true; + const checkChunks = () => { busy = false; // WebRTC --> websocket if (this.relayIsReady() && this.relay.bufferedAmount < this.MAX_BUFFER && this.c2rSchedule.length > 0) { - chunk = this.c2rSchedule.shift(); + const chunk = this.c2rSchedule.shift(); this.rateLimit.update(chunk.byteLength); this.relay.send(chunk); busy = true; } // websocket --> WebRTC if (this.webrtcIsReady() && this.client.bufferedAmount < this.MAX_BUFFER && this.r2cSchedule.length > 0) { - chunk = this.r2cSchedule.shift(); + const chunk = this.r2cSchedule.shift(); this.rateLimit.update(chunk.byteLength); this.client.send(chunk); return busy = true; diff --git a/snowflake.js b/snowflake.js index 301d4fd..7354b97 100644 --- a/snowflake.js +++ b/snowflake.js @@ -52,16 +52,15 @@ class Snowflake { // Regularly poll Broker for clients to serve until this snowflake is // serving at capacity, at which point stop polling. pollBroker() { - var msg, pair, recv; // Poll broker for clients. - pair = this.makeProxyPair(); + const pair = this.makeProxyPair(); if (!pair) { log('At client capacity.'); return; } log('Polling broker..'); // Do nothing until a new proxyPair is available. - msg = 'Polling for client ... '; + let msg = 'Polling for client ... '; if (this.retries > 0) { msg += '[retries: ' + this.retries + ']'; } @@ -69,7 +68,7 @@ class Snowflake { //update NAT type console.log("NAT type: " + this.ui.natType); this.broker.setNATType(this.ui.natType); - recv = this.broker.getClientOffer(pair.id, this.proxyPairs.length); + const recv = this.broker.getClientOffer(pair.id, this.proxyPairs.length); recv.then((resp) => { var clientNAT = resp.NAT; if (!this.receiveOffer(pair, resp.Offer, resp.RelayURL)) { @@ -114,13 +113,11 @@ class Snowflake { // Receive an SDP offer from some client assigned by the Broker, // |pair| - an available ProxyPair. receiveOffer(pair, desc, relayURL) { - var e, offer, sdp; - try { if (relayURL !== undefined) { - let relayURLParsed = new URL(relayURL); - let hostname = relayURLParsed.hostname; - let protocol = relayURLParsed.protocol; + const relayURLParsed = new URL(relayURL); + const hostname = relayURLParsed.hostname; + const protocol = relayURLParsed.protocol; if (protocol !== "wss:") { log('incorrect relay url protocol'); return false; @@ -131,29 +128,27 @@ class Snowflake { } pair.setRelayURL(relayURL); } - offer = JSON.parse(desc); + const offer = JSON.parse(desc); dbg('Received:\n\n' + offer.sdp + '\n'); - sdp = new RTCSessionDescription(offer); + const sdp = new RTCSessionDescription(offer); if (pair.receiveWebRTCOffer(sdp)) { this.sendAnswer(pair); return true; } else { return false; } - } catch (error) { - e = error; + } catch (e) { log('ERROR: Unable to receive Offer: ' + e); return false; } }
sendAnswer(pair) { - var fail, next; - next = function (sdp) { + const next = function (sdp) { dbg('webrtc: Answer ready.'); pair.pc.setLocalDescription(sdp).catch(fail); }; - fail = function () { + const fail = function () { pair.close(); dbg('webrtc: Failed to create or set Answer'); }; @@ -167,8 +162,7 @@ class Snowflake { if (this.proxyPairs.length >= this.config.maxNumClients) { return null; } - var pair; - pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config); + const pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config); this.proxyPairs.push(pair);
log('Snowflake IDs: ' + (this.proxyPairs.map(function (p) { @@ -176,9 +170,8 @@ class Snowflake { })).join(' | '));
pair.onCleanup = () => { - var ind; // Delete from the list of proxy pairs. - ind = this.proxyPairs.indexOf(pair); + const ind = this.proxyPairs.indexOf(pair); if (ind > -1) { this.proxyPairs.splice(ind, 1); } diff --git a/util.js b/util.js index 710ad51..9a7673b 100644 --- a/util.js +++ b/util.js @@ -69,8 +69,7 @@ class Util { // Sends it back to the broker, which passes it back to the original client. static sendOffer(offer) { return new Promise((fulfill, reject) => { - var xhr; - xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); xhr.timeout = 30 * 1000; xhr.onreadystatechange = function() { if (xhr.DONE !== xhr.readyState) { @@ -104,20 +103,16 @@ class Parse { // object mapping cookies names to values. Returns null on error. // http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038 static cookie(cookies) { - var i, j, len, name, result, string, strings, value; - result = {}; - strings = []; - if (cookies) { - strings = cookies.split(';'); - } - for (i = 0, len = strings.length; i < len; i++) { - string = strings[i]; - j = string.indexOf('='); + const result = {}; + const strings = cookies ? cookies.split(';') : []; + for (let i = 0, len = strings.length; i < len; i++) { + const string = strings[i]; + const j = string.indexOf('='); if (-1 === j) { return null; } - name = decodeURIComponent(string.substr(0, j).trim()); - value = decodeURIComponent(string.substr(j + 1).trim()); + const name = decodeURIComponent(string.substr(0, j).trim()); + const value = decodeURIComponent(string.substr(j + 1).trim()); if (!(name in result)) { result[name] = value; } @@ -128,8 +123,7 @@ class Parse { // Parse an address in the form 'host:port'. Returns an Object with keys 'host' // (String) and 'port' (int). Returns null on error. static address(spec) { - var host, m, port; - m = null; + let m = null; if (!m) { // IPv6 syntax. m = spec.match(/^[([\0-9a-fA-F:.]+)]:([0-9]+)$/); @@ -142,8 +136,8 @@ class Parse { // TODO: Domain match return null; } - host = m[1]; - port = parseInt(m[2], 10); + const host = m[1]; + const port = parseInt(m[2], 10); if (isNaN(port) || port < 0 || port > 65535) { return null; } @@ -184,17 +178,16 @@ class Parse { // https://tools.ietf.org/html/rfc4566#section-5.7 // https://tools.ietf.org/html/rfc5245#section-15 static ipFromSDP(sdp) { - var i, len, m, pattern, ref; console.log(sdp); - ref = [ + const ref = [ /^a=candidate:[a-zA-Z0-9+/]+ \d+ udp \d+ ([\d.]+) /mg, /^a=candidate:[a-zA-Z0-9+/]+ \d+ udp \d+ ([0-9A-Fa-f:.]+) /mg, /^c=IN IP4 ([\d.]+)(?:(?:/\d+)?/\d+)?(:? |$)/mg, /^c=IN IP6 ([0-9A-Fa-f:.]+)(?:/\d+)?(:? |$)/mg ]; - for (i = 0, len = ref.length; i < len; i++) { - pattern = ref[i]; - m = pattern.exec(sdp); + for (let i = 0, len = ref.length; i < len; i++) { + const pattern = ref[i]; + let m = pattern.exec(sdp); while (m != null) { if(Parse.isRemoteIP(m[1])) return m[1]; m = pattern.exec(sdp); @@ -205,9 +198,8 @@ class Parse { // Parse the mapped port out of an ice candidate returned from the // onicecandidate callback static portFromCandidate(c) { - var m, pattern; - pattern = /(?:[\d.]+|[0-9A-Fa-f:.]+) (\d+) typ srflx/m; - m = pattern.exec(c); + const pattern = /(?:[\d.]+|[0-9A-Fa-f:.]+) (\d+) typ srflx/m; + const m = pattern.exec(c); if (m != null) { return m[1]; } @@ -247,8 +239,7 @@ class Params { if (!query.has(param)) { return defaultValue; } - var val; - val = query.get(param); + const val = query.get(param); if ('true' === val || '1' === val || '' === val) { return true; } @@ -279,9 +270,8 @@ class BucketRateLimit { }
age() { - var delta, now; - now = new Date(); - delta = (now - this.lastUpdate) / 1000.0; + const now = new Date(); + const delta = (now - this.lastUpdate) / 1000.0; this.lastUpdate = now; this.amount -= delta * this.capacity / this.time; if (this.amount < 0.0) {
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 17168c1f57c177e74ade038d1394476b2c740e3c Author: WofWca wofwca@protonmail.com AuthorDate: Sat Jun 18 18:23:12 2022 +0300
refactor: convert some comments to JSDoc, improve types --- broker.js | 36 +++++++++++++++++++------------ proxypair.js | 25 +++++++++++----------- snowflake.js | 31 +++++++++++++++++---------- ui.js | 2 +- util.js | 70 +++++++++++++++++++++++++++++++++++++----------------------- websocket.js | 6 ++++-- 6 files changed, 102 insertions(+), 68 deletions(-)
diff --git a/broker.js b/broker.js index 8d084e0..128eda7 100644 --- a/broker.js +++ b/broker.js @@ -1,6 +1,6 @@ /* global log, dbg, snowflake */
-/* +/** Communication with the snowflake broker.
Browser snowflakes must register with the broker in order @@ -10,10 +10,12 @@ to get assigned to clients. // Represents a broker running remotely. class Broker {
- // When interacting with the Broker, snowflake must generate a unique session - // ID so the Broker can keep track of each proxy's signalling channels. - // On construction, this Broker object does not do anything until - // |getClientOffer| is called. + /** + * When interacting with the Broker, snowflake must generate a unique session + * ID so the Broker can keep track of each proxy's signalling channels. + * On construction, this Broker object does not do anything until + * `getClientOffer` is called. + */ constructor(config) { this.getClientOffer = this.getClientOffer.bind(this); this._postRequest = this._postRequest.bind(this); @@ -34,11 +36,13 @@ class Broker { } }
- // Promises some client SDP Offer. - // Registers this Snowflake with the broker using an HTTP POST request, and - // waits for a response containing some client offer that the Broker chooses - // for this proxy.. - // TODO: Actually support multiple clients. + /** + * Promises some client SDP Offer. + * Registers this Snowflake with the broker using an HTTP POST request, and + * waits for a response containing some client offer that the Broker chooses + * for this proxy.. + * TODO: Actually support multiple clients. + */ getClientOffer(id, numClientsConnected) { return new Promise((fulfill, reject) => { const xhr = new XMLHttpRequest(); @@ -77,8 +81,10 @@ class Broker { }); }
- // Assumes getClientOffer happened, and a WebRTC SDP answer has been generated. - // Sends it back to the broker, which passes it to back to the original client. + /** + * Assumes getClientOffer happened, and a WebRTC SDP answer has been generated. + * Sends it back to the broker, which passes it to back to the original client. + */ sendAnswer(id, answer) { dbg(id + ' - Sending answer back to broker...\n'); dbg(answer.sdp); @@ -104,8 +110,10 @@ class Broker { this.natType = natType; }
- // urlSuffix for the broker is different depending on what action - // is desired. + /** + * urlSuffix for the broker is different depending on what action + * is desired. + */ _postRequest(xhr, urlSuffix, payload) { try { xhr.open('POST', this.url + urlSuffix); diff --git a/proxypair.js b/proxypair.js index e423b59..880f202 100644 --- a/proxypair.js +++ b/proxypair.js @@ -1,6 +1,6 @@ /* global snowflake, log, dbg, Util, Parse, WS */
-/* +/** Represents a single:
client <-- webrtc --> snowflake <-- websocket --> relay @@ -11,11 +11,10 @@ Broker with an WebRTC answer.
class ProxyPair {
- /* - Constructs a ProxyPair where: - - @relayAddr is the destination relay - - @rateLimit specifies a rate limit on traffic - */ + /** + * @param relayAddr the destination relay + * @param {*} rateLimit specifies a rate limit on traffic + */ constructor(relayAddr, rateLimit, config) { this.prepareDataChannel = this.prepareDataChannel.bind(this); this.connectRelay = this.connectRelay.bind(this); @@ -35,7 +34,7 @@ class ProxyPair { this.counted = false; }
- // Prepare a WebRTC PeerConnection and await for an SDP offer. + /** Prepare a WebRTC PeerConnection and await for an SDP offer. */ begin() { this.pc = new RTCPeerConnection(this.pcConfig); this.pc.onicecandidate = (evt) => { @@ -69,7 +68,7 @@ class ProxyPair { return true; }
- // Given a WebRTC DataChannel, prepare callbacks. + /** Given a WebRTC DataChannel, prepare callbacks. */ prepareDataChannel(channel) { channel.onopen = () => { log('WebRTC DataChannel opened!'); @@ -96,7 +95,7 @@ class ProxyPair { return channel.onmessage = this.onClientToRelayMessage; }
- // Assumes WebRTC datachannel is connected. + /** Assumes WebRTC datachannel is connected. */ connectRelay() { dbg('Connecting to relay...'); // Get a remote IP address from the PeerConnection, if possible. Add it to @@ -147,7 +146,7 @@ class ProxyPair { }), 5000); }
- // WebRTC --> websocket + /** WebRTC --> websocket */ onClientToRelayMessage(msg) { if (this.messageTimer) { clearTimeout(this.messageTimer); @@ -165,7 +164,7 @@ class ProxyPair { return this.flush(); }
- // websocket --> WebRTC + /** websocket --> WebRTC */ onRelayToClientMessage(event) { dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes'); this.r2cSchedule.push(event.data); @@ -178,7 +177,7 @@ class ProxyPair { return this.close(); }
- // Close both WebRTC and websocket. + /** Close both WebRTC and websocket. */ close() { if (this.timer) { clearTimeout(this.timer); @@ -200,7 +199,7 @@ class ProxyPair { this.onCleanup(); }
- // Send as much data in both directions as the rate limit currently allows. + /** Send as much data in both directions as the rate limit currently allows. */ flush() { if (this.flush_timeout_id) { clearTimeout(this.flush_timeout_id); diff --git a/snowflake.js b/snowflake.js index 7354b97..2c94cf8 100644 --- a/snowflake.js +++ b/snowflake.js @@ -1,6 +1,6 @@ /* global log, dbg, DummyRateLimit, BucketRateLimit, ProxyPair */
-/* +/** A JavaScript WebRTC snowflake proxy
Uses WebRTC from the client, and Websocket to the server. @@ -32,16 +32,20 @@ class Snowflake { this.retries = 0; }
- // Set the target relay address spec, which is expected to be websocket. - // TODO: Should potentially fetch the target from broker later, or modify - // entirely for the Tor-independent version. + /** + * Set the target relay address spec, which is expected to be websocket. + * TODO: Should potentially fetch the target from broker later, or modify + * entirely for the Tor-independent version. + */ setRelayAddr(relayAddr) { this.relayAddr = relayAddr; log('Using ' + relayAddr.host + ':' + relayAddr.port + ' as Relay.'); }
- // Initialize WebRTC PeerConnection, which requires beginning the signalling - // process. |pollBroker| automatically arranges signalling. + /** + * Initialize WebRTC PeerConnection, which requires beginning the signalling + * process. `pollBroker` automatically arranges signalling. + */ beginWebRTC() { this.pollBroker(); this.pollTimeoutId = setTimeout((() => { @@ -49,8 +53,10 @@ class Snowflake { }), this.pollInterval); }
- // Regularly poll Broker for clients to serve until this snowflake is - // serving at capacity, at which point stop polling. + /** + * Regularly poll Broker for clients to serve until this snowflake is + * serving at capacity, at which point stop polling. + */ pollBroker() { // Poll broker for clients. const pair = this.makeProxyPair(); @@ -110,8 +116,11 @@ class Snowflake { this.retries++; }
- // Receive an SDP offer from some client assigned by the Broker, - // |pair| - an available ProxyPair. + /** + * Receive an SDP offer from some client assigned by the Broker + * @param {ProxyPair} pair an available ProxyPair. + * @returns {boolean} `true` on success, `false` on fail. + */ receiveOffer(pair, desc, relayURL) { try { if (relayURL !== undefined) { @@ -180,7 +189,7 @@ class Snowflake { return pair; }
- // Stop all proxypairs. + /** Stop all proxypairs. */ disable() { log('Disabling Snowflake.'); clearTimeout(this.pollTimeoutId); diff --git a/ui.js b/ui.js index de8670d..6358758 100644 --- a/ui.js +++ b/ui.js @@ -1,4 +1,4 @@ -/* +/** All of Snowflake's DOM manipulation and inputs. */
diff --git a/util.js b/util.js index 9a7673b..bf73571 100644 --- a/util.js +++ b/util.js @@ -1,7 +1,7 @@ /* exported Util, Params, DummyRateLimit */ /* global Config */
-/* +/** A JavaScript WebRTC snowflake proxy
Contains helpers for parsing query strings and other utilities. @@ -21,10 +21,12 @@ class Util { return navigator.cookieEnabled; }
- // returns a promise that resolves to "restricted" if we - // fail to make a test connection to a known restricted - // NAT, "unrestricted" if the test connection succeeds, and - // "unknown" if we fail to reach the probe test server + /** + * returns a promise that resolves to "restricted" if we + * fail to make a test connection to a known restricted + * NAT, "unrestricted" if the test connection succeeds, and + * "unknown" if we fail to reach the probe test server + */ static checkNATType(timeout) { let pc = new RTCPeerConnection({iceServers: [ {urls: 'stun:stun1.l.google.com:19302'} @@ -65,8 +67,10 @@ class Util { })); }
- // Assumes getClientOffer happened, and a WebRTC SDP answer has been generated. - // Sends it back to the broker, which passes it back to the original client. + /** + * Assumes getClientOffer happened, and a WebRTC SDP answer has been generated. + * Sends it back to the broker, which passes it back to the original client. + */ static sendOffer(offer) { return new Promise((fulfill, reject) => { const xhr = new XMLHttpRequest(); @@ -99,9 +103,11 @@ class Util {
class Parse {
- // Parse a cookie data string (usually document.cookie). The return type is an - // object mapping cookies names to values. Returns null on error. - // http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038 + /** + * Parse a cookie data string (usually document.cookie). The return type is an + * object mapping cookies names to values. Returns null on error. + * http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-8747038 + */ static cookie(cookies) { const result = {}; const strings = cookies ? cookies.split(';') : []; @@ -120,8 +126,10 @@ class Parse { return result; }
- // Parse an address in the form 'host:port'. Returns an Object with keys 'host' - // (String) and 'port' (int). Returns null on error. + /** + * Parse an address in the form 'host:port'. Returns an Object with keys 'host' + * (String) and 'port' (int). Returns null on error. + */ static address(spec) { let m = null; if (!m) { @@ -147,8 +155,10 @@ class Parse { }; }
- // Parse a count of bytes. A suffix of 'k', 'm', or 'g' (or uppercase) - // does what you would think. Returns null on error. + /** + * Parse a count of bytes. A suffix of 'k', 'm', or 'g' (or uppercase) + * does what you would think. Returns null on error. + */ static byteCount(spec) { let matches = spec.match(/^(\d+(?:.\d*)?)(\w*)$/); if (matches === null) { @@ -172,11 +182,13 @@ class Parse { return count * multiplier; }
- //Parse a remote connection-address out of the "c=" Connection Data field - // or the "a=" attribute fields of the session description. - // Return undefined if none is found. - // https://tools.ietf.org/html/rfc4566#section-5.7 - // https://tools.ietf.org/html/rfc5245#section-15 + /** + * Parse a remote connection-address out of the "c=" Connection Data field + * or the "a=" attribute fields of the session description. + * Return undefined if none is found. + * https://tools.ietf.org/html/rfc4566#section-5.7 + * https://tools.ietf.org/html/rfc5245#section-15 + */ static ipFromSDP(sdp) { console.log(sdp); const ref = [ @@ -195,8 +207,10 @@ class Parse { } }
- // Parse the mapped port out of an ice candidate returned from the - // onicecandidate callback + /** + * Parse the mapped port out of an ice candidate returned from the + * onicecandidate callback + */ static portFromCandidate(c) { const pattern = /(?:[\d.]+|[0-9A-Fa-f:.]+) (\d+) typ srflx/m; const m = pattern.exec(c); @@ -206,7 +220,7 @@ class Parse { return null; }
- // Determine whether an IP address is a local, unspecified, or loopback address + /** Determine whether an IP address is a local, unspecified, or loopback address */ static isRemoteIP(ip) { if (ip.includes(":")) { var ip6 = ip.split(':'); @@ -249,9 +263,11 @@ class Params { return null; }
- // Get an object value and parse it as a byte count. Example byte counts are - // '100' and '1.3m'. Returns |defaultValue| if param is not a key. Return null - // on a parsing error. + /** + * Get an object value and parse it as a byte count. Example byte counts are + * '100' and '1.3m'. Returns |defaultValue| if param is not a key. Return null + * on a parsing error. + */ static getByteCount(query, param, defaultValue) { if (!query.has(param)) { return defaultValue; @@ -285,7 +301,7 @@ class BucketRateLimit { return this.amount <= this.capacity; }
- // How many seconds in the future will the limit expire? + /** How many seconds in the future will the limit expire? */ when() { this.age(); return (this.amount - this.capacity) / (this.capacity / this.time); @@ -303,7 +319,7 @@ BucketRateLimit.prototype.amount = 0.0; BucketRateLimit.prototype.lastUpdate = new Date();
-// A rate limiter that never limits. +/** A rate limiter that never limits. */ class DummyRateLimit {
constructor(capacity, time) { diff --git a/websocket.js b/websocket.js index fdf470c..b2d509a 100644 --- a/websocket.js +++ b/websocket.js @@ -4,8 +4,10 @@ Only websocket-specific stuff.
class WS {
- // Build an escaped URL string from unescaped components. Only scheme and host - // are required. See RFC 3986, section 3. + /** + * Build an escaped URL string from unescaped components. Only scheme and host + * are required. See RFC 3986, section 3. + */ static buildUrl(scheme, host, port, path, params) { var parts; parts = [];
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 277cfc75e2ac6d2d2af28f4496d66c01f7f9db75 Author: WofWca wofwca@protonmail.com AuthorDate: Sat Jun 18 19:04:35 2022 +0300
refactor: replace some `function`s with arrow functions --- init-badge.js | 4 +--- init-webext.js | 4 +--- snowflake.js | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/init-badge.js b/init-badge.js index f4dd7ff..c74038c 100644 --- a/init-badge.js +++ b/init-badge.js @@ -67,9 +67,7 @@ class BadgeUI extends UI { } else { this.setIcon('on'); } - const total = this.stats.reduce((function(t, c) { - return t + c; - }), 0); + const total = this.stats.reduce((t, c) => t + c, 0); this.popup.turnOn(this.clients, total); }
diff --git a/init-webext.js b/init-webext.js index 6c13e7f..dd67b98 100644 --- a/init-webext.js +++ b/init-webext.js @@ -77,9 +77,7 @@ class WebExtUI extends UI { if (!this.port) { return; } this.port.postMessage({ clients: this.clients, - total: this.stats.reduce((function(t, c) { - return t + c; - }), 0), + total: this.stats.reduce((t, c) => t + c, 0), enabled: this.enabled, missingFeature: this.missingFeature, }); diff --git a/snowflake.js b/snowflake.js index 2c94cf8..fcd91c5 100644 --- a/snowflake.js +++ b/snowflake.js @@ -174,9 +174,7 @@ class Snowflake { const pair = new ProxyPair(this.relayAddr, this.rateLimit, this.config); this.proxyPairs.push(pair);
- log('Snowflake IDs: ' + (this.proxyPairs.map(function (p) { - return p.id; - })).join(' | ')); + log('Snowflake IDs: ' + (this.proxyPairs.map(p => p.id)).join(' | '));
pair.onCleanup = () => { // Delete from the list of proxy pairs.
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 3c2215a8039db91837235ff51897a82299095d17 Author: WofWca wofwca@protonmail.com AuthorDate: Sat Jun 18 19:28:38 2022 +0300
refactor: remove some unused `return` --- broker.js | 12 +++++++----- init-badge.js | 6 ++++-- init-node.js | 2 +- init-webext.js | 10 ++++++---- proxypair.js | 30 +++++++++++++++--------------- util.js | 4 ++-- 6 files changed, 35 insertions(+), 29 deletions(-)
diff --git a/broker.js b/broker.js index 128eda7..2431630 100644 --- a/broker.js +++ b/broker.js @@ -77,7 +77,7 @@ class Broker { Clients: clients, AcceptedRelayPattern: this.config.allowedRelayPattern, }; - return this._postRequest(xhr, 'proxy', JSON.stringify(data)); + this._postRequest(xhr, 'proxy', JSON.stringify(data)); }); }
@@ -96,14 +96,16 @@ class Broker { switch (xhr.status) { case Broker.CODE.OK: dbg('Broker: Successfully replied with answer.'); - return dbg(xhr.responseText); + dbg(xhr.responseText); + break; default: dbg('Broker ERROR: Unexpected ' + xhr.status + ' - ' + xhr.statusText); - return snowflake.ui.setStatus(' failure. Please refresh.'); + snowflake.ui.setStatus(' failure. Please refresh.'); + break; } }; var data = {"Version": "1.0", "Sid": id, "Answer": JSON.stringify(answer)}; - return this._postRequest(xhr, 'answer', JSON.stringify(data)); + this._postRequest(xhr, 'answer', JSON.stringify(data)); }
setNATType(natType) { @@ -127,7 +129,7 @@ class Broker { log('Broker: exception while connecting: ' + err.message); return; } - return xhr.send(payload); + xhr.send(payload); }
} diff --git a/init-badge.js b/init-badge.js index c74038c..ec62b5d 100644 --- a/init-badge.js +++ b/init-badge.js @@ -50,7 +50,7 @@ class BadgeUI extends UI { initNATType() { this.natType = "unknown"; this.checkNAT(); - return setInterval(() => {this.checkNAT();}, config.natCheckInterval); + setInterval(() => {this.checkNAT();}, config.natCheckInterval); }
setStatus() {} @@ -139,7 +139,9 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific // log to console. log = function(msg) { console.log('Snowflake: ' + msg); - return snowflake != null ? snowflake.ui.log(msg) : void 0; + if (snowflake != null) { + snowflake.ui.log(msg); + } };
dbg = function(msg) { diff --git a/init-node.js b/init-node.js index b5a60d8..e5c2e32 100644 --- a/init-node.js +++ b/init-node.js @@ -13,7 +13,7 @@ var broker = new Broker(config); var snowflake = new Snowflake(config, ui, broker);
var log = function(msg) { - return console.log('Snowflake: ' + msg); + console.log('Snowflake: ' + msg); };
var dbg = log; diff --git a/init-webext.js b/init-webext.js index dd67b98..dfd776a 100644 --- a/init-webext.js +++ b/init-webext.js @@ -27,7 +27,7 @@ class WebExtUI extends UI { initNATType() { this.natType = "unknown"; this.checkNAT(); - return setInterval(() => {this.checkNAT();}, config.natCheckInterval); + setInterval(() => {this.checkNAT();}, config.natCheckInterval); }
tryProbe() { @@ -164,12 +164,14 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific // log to console. log = function(msg) { console.log('Snowflake: ' + msg); - return snowflake != null ? snowflake.ui.log(msg) : void 0; + if (snowflake != null) { + snowflake.ui.log(msg); + } };
dbg = function(msg) { if (debug) { - return log(msg); + log(msg); } };
@@ -194,7 +196,7 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific dbg('Contacting Broker at ' + broker.url); log('Starting snowflake'); snowflake.setRelayAddr(config.relayAddr); - return snowflake.beginWebRTC(); + snowflake.beginWebRTC(); };
window.onunload = function() { diff --git a/proxypair.js b/proxypair.js index 880f202..d230e76 100644 --- a/proxypair.js +++ b/proxypair.js @@ -45,11 +45,11 @@ class ProxyPair { } }; // OnDataChannel triggered remotely from the client when connection succeeds. - return this.pc.ondatachannel = (dc) => { + this.pc.ondatachannel = (dc) => { const channel = dc.channel; dbg('Data Channel established...'); this.prepareDataChannel(channel); - return this.client = channel; + this.client = channel; }; }
@@ -76,7 +76,7 @@ class ProxyPair { 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(); + this.connectRelay(); }; channel.onclose = () => { log('WebRTC DataChannel closed.'); @@ -86,13 +86,13 @@ class ProxyPair { this.counted = false; } this.flush(); - return this.close(); + this.close(); }; channel.onerror = function () { - return log('Data channel error!'); + log('Data channel error!'); }; channel.binaryType = "arraybuffer"; - return channel.onmessage = this.onClientToRelayMessage; + channel.onmessage = this.onClientToRelayMessage; }
/** Assumes WebRTC datachannel is connected. */ @@ -122,7 +122,7 @@ class ProxyPair { this.timer = 0; } log(relay.label + ' connected!'); - return snowflake.ui.setStatus('connected'); + snowflake.ui.setStatus('connected'); }; this.relay.onclose = () => { log(relay.label + ' closed.'); @@ -132,17 +132,17 @@ class ProxyPair { this.counted = false; } this.flush(); - return this.close(); + this.close(); }; this.relay.onerror = this.onError; this.relay.onmessage = this.onRelayToClientMessage; // TODO: Better websocket timeout handling. - return this.timer = setTimeout((() => { + this.timer = setTimeout((() => { if (0 === this.timer) { return; } log(relay.label + ' timed out connecting.'); - return relay.onclose(); + relay.onclose(); }), 5000); }
@@ -161,20 +161,20 @@ class ProxyPair { this.flush(); this.close(); }), this.config.messageTimeout); - return this.flush(); + this.flush(); }
/** websocket --> WebRTC */ onRelayToClientMessage(event) { dbg('websocket --> WebRTC data: ' + event.data.byteLength + ' bytes'); this.r2cSchedule.push(event.data); - return this.flush(); + this.flush(); }
onError(event) { const ws = event.target; log(ws.label + ' error.'); - return this.close(); + this.close(); }
/** Close both WebRTC and websocket. */ @@ -220,14 +220,14 @@ class ProxyPair { const chunk = this.r2cSchedule.shift(); this.rateLimit.update(chunk.byteLength); this.client.send(chunk); - return busy = true; + busy = true; } }; while (busy && !this.rateLimit.isLimited()) { checkChunks(); } if (this.r2cSchedule.length > 0 || this.c2rSchedule.length > 0 || (this.relayIsReady() && this.relay.bufferedAmount > 0) || (this.webrtcIsReady() && this.client.bufferedAmount > 0)) { - return this.flush_timeout_id = setTimeout(this.flush, this.rateLimit.when() * 1000); + this.flush_timeout_id = setTimeout(this.flush, this.rateLimit.when() * 1000); } }
diff --git a/util.js b/util.js index bf73571..58d6512 100644 --- a/util.js +++ b/util.js @@ -95,7 +95,7 @@ class Util { console.log('Signaling Server: exception while connecting: ' + error.message); return reject('unable to connect to signaling server'); } - return xhr.send(JSON.stringify(data)); + xhr.send(JSON.stringify(data)); }); } } @@ -291,7 +291,7 @@ class BucketRateLimit { this.lastUpdate = now; this.amount -= delta * this.capacity / this.time; if (this.amount < 0.0) { - return this.amount = 0.0; + this.amount = 0.0; } }
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 3ae64d6242d70fa32a9b639647d8c13b5a7c5785 Author: WofWca wofwca@protonmail.com AuthorDate: Fri Jun 24 21:12:42 2022 +0300
refactor: replace `void 0` with `undefined` --- config.js | 2 +- init-testing.js | 4 ++-- init-webext.js | 2 +- proxypair.js | 2 +- shims.js | 2 +- snowflake.js | 2 +- spec/util.spec.js | 14 +++++++------- websocket.js | 6 +++--- 8 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/config.js b/config.js index cac8506..3142f5f 100644 --- a/config.js +++ b/config.js @@ -18,7 +18,7 @@ Config.prototype.relayAddr = { Config.prototype.cookieName = "snowflake-allow";
// Bytes per second. Set to undefined to disable limit. -Config.prototype.rateLimitBytes = void 0; +Config.prototype.rateLimitBytes = undefined;
Config.prototype.minRateLimit = 10 * 1024;
diff --git a/init-testing.js b/init-testing.js index 0905b80..6bc86ef 100644 --- a/init-testing.js +++ b/init-testing.js @@ -72,11 +72,11 @@ var snowflake, query, debug, ui, silenceNotifications, log, dbg, init; // log to console. log = function(msg) { console.log('Snowflake: ' + msg); - return snowflake != null ? snowflake.ui.log(msg) : void 0; + return snowflake != null ? snowflake.ui.log(msg) : undefined; };
dbg = function(msg) { - if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) { + if (debug || ((snowflake != null ? snowflake.ui : undefined) instanceof DebugUI)) { return log(msg); } }; diff --git a/init-webext.js b/init-webext.js index dfd776a..0bba740 100644 --- a/init-webext.js +++ b/init-webext.js @@ -52,7 +52,7 @@ class WebExtUI extends UI { })) .then((result) => { let enabled = this.enabled; - if (result['snowflake-enabled'] !== void 0) { + if (result['snowflake-enabled'] !== undefined) { enabled = result['snowflake-enabled']; } else { log("Toggle state not yet saved"); diff --git a/proxypair.js b/proxypair.js index d230e76..94d792a 100644 --- a/proxypair.js +++ b/proxypair.js @@ -240,7 +240,7 @@ class ProxyPair { }
isClosed(ws) { - return void 0 === ws || WebSocket.CLOSED === ws.readyState; + return undefined === ws || WebSocket.CLOSED === ws.readyState; }
peerConnOpen() { diff --git a/shims.js b/shims.js index 5009084..19b865b 100644 --- a/shims.js +++ b/shims.js @@ -4,7 +4,7 @@ WebRTC shims for multiple browsers. */
-if (typeof module !== "undefined" && module !== null ? module.exports : void 0) { +if (typeof module !== "undefined" && module !== null ? module.exports : undefined) { window = {}; document = { getElementById: function() { diff --git a/snowflake.js b/snowflake.js index fcd91c5..bfa89c0 100644 --- a/snowflake.js +++ b/snowflake.js @@ -24,7 +24,7 @@ class Snowflake { this.proxyPairs = []; this.natFailures = 0; this.pollInterval = this.config.defaultBrokerPollInterval; - if (void 0 === this.config.rateLimitBytes) { + if (undefined === this.config.rateLimitBytes) { this.rateLimit = new DummyRateLimit(); } else { this.rateLimit = new BucketRateLimit(this.config.rateLimitBytes * this.config.rateLimitHistory, this.config.rateLimitHistory); diff --git a/spec/util.spec.js b/spec/util.spec.js index 687ae98..0789f9e 100644 --- a/spec/util.spec.js +++ b/spec/util.spec.js @@ -139,7 +139,7 @@ describe('Parse', function() { { // local addresses only sdp: "v=0\no=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\ns=SDP Seminar\ni=A Seminar on the session description protocol\nu=http://www.example.com/seminars/sdp.pdf%5Cne=j.doe@example.com (Jane Doe)\nc=IN IP4 10.47.16.5\nt=2873397496 2873404696\na=recvonly\nm=audio 49170 RTP/AVP 0\nm=video 51372 RTP/AVP 99\na=rtpmap:99 h263-1998/90000", - expected: void 0 + expected: undefined }, { sdp: "v=0\no=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\ns=SDP Seminar\ni=A Seminar on the session description protocol\nu=http://www.example.com/seminars/sdp.pdf%5Cne=j.doe@example.com (Jane Doe)\nc=IN IP4 10.47.16.5\na=candidate:3581707038 1 udp 2122260223 192.168.0.1 54653 typ host generation 0 network-id 1 network-cost 50\na=candidate:2617212910 1 tcp 1518280447 192.168.0.1 59673 typ host tcptype passive generation 0 network-id 1 network-cost 50\na=candidate:2082671819 1 udp [...] @@ -148,7 +148,7 @@ describe('Parse', function() { { // Missing c= line sdp: "v=0\no=jdoe 2890844526 2890842807 IN IP4 10.47.16.5\ns=SDP Seminar\ni=A Seminar on the session description protocol\nu=http://www.example.com/seminars/sdp.pdf%5Cne=j.doe@example.com (Jane Doe)\nt=2873397496 2873404696\na=recvonly\nm=audio 49170 RTP/AVP 0\nm=video 51372 RTP/AVP 99\na=rtpmap:99 h263-1998/90000", - expected: void 0 + expected: undefined }, { // Single line, IP address only @@ -188,17 +188,17 @@ describe('Parse', function() { { // Improper character within IPv4 sdp: "c=IN IP4 224.2z.1.1", - expected: void 0 + expected: undefined }, { // Improper character within IPv6 sdp: "c=IN IP6 ff15:g::101", - expected: void 0 + expected: undefined }, { // Bogus "IP7" addrtype sdp: "c=IN IP7 1.2.3.4\n", - expected: void 0 + expected: undefined } ];
@@ -212,8 +212,8 @@ describe('Parse', function() { // and also accept records terminated with a single newline character." // We represent the test cases with LF line endings for convenience, and // test them both that way and with CRLF line endings. - expect((ref = Parse.ipFromSDP(test.sdp)) != null ? ref.toLowerCase() : void 0).toEqual(test.expected); - results.push(expect((ref1 = Parse.ipFromSDP(test.sdp.replace(/\n/, "\r\n"))) != null ? ref1.toLowerCase() : void 0).toEqual(test.expected)); + expect((ref = Parse.ipFromSDP(test.sdp)) != null ? ref.toLowerCase() : undefined).toEqual(test.expected); + results.push(expect((ref1 = Parse.ipFromSDP(test.sdp.replace(/\n/, "\r\n"))) != null ? ref1.toLowerCase() : undefined).toEqual(test.expected)); } return results; }); diff --git a/websocket.js b/websocket.js index b2d509a..7164577 100644 --- a/websocket.js +++ b/websocket.js @@ -21,11 +21,11 @@ class WS { } else { parts.push(encodeURIComponent(host)); } - if (void 0 !== port && this.DEFAULT_PORTS[scheme] !== port) { + if (undefined !== port && this.DEFAULT_PORTS[scheme] !== port) { parts.push(':'); parts.push(encodeURIComponent(port.toString())); } - if (void 0 !== path && '' !== path) { + if (undefined !== path && '' !== path) { if (!path.match(/^//)) { path = '/' + path; } @@ -34,7 +34,7 @@ class WS { }); parts.push(path); } - if (void 0 !== params) { + if (undefined !== params) { parts.push('?'); parts.push(new URLSearchParams(params).toString()); }
This is an automated email from the git hooks/post-receive script.
meskio pushed a commit to branch main in repository pluggable-transports/snowflake-webext.
commit 9ef0843951acd5ba0ce07116fa1bdf3dc3977342 Merge: 169c3ea 3ae64d6 Author: meskio meskio@torproject.org AuthorDate: Wed Jul 6 11:01:05 2022 +0200
Merge branch 'mr/31'
broker.js | 58 +++++++++++++------------ config.js | 2 +- init-badge.js | 10 ++--- init-node.js | 2 +- init-testing.js | 21 ++++----- init-webext.js | 16 +++---- proxypair.js | 79 ++++++++++++++++------------------ shims.js | 2 +- snowflake.js | 103 ++++++++++++++++++++++----------------------- spec/util.spec.js | 14 +++--- ui.js | 2 +- util.js | 124 ++++++++++++++++++++++++++++-------------------------- websocket.js | 12 +++--- 13 files changed, 224 insertions(+), 221 deletions(-)
tor-commits@lists.torproject.org