mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Close over init so that we can return if a feature isn't detected
I guess alternatively, just use an if/else block.
This commit is contained in:
parent
f97c37fe5d
commit
27a92ab03a
2 changed files with 130 additions and 121 deletions
|
@ -2,34 +2,38 @@
|
|||
Entry point.
|
||||
*/
|
||||
|
||||
if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
|
||||
var snowflake, query, debug, silenceNotifications, log, dbg, init;
|
||||
|
||||
;(function() {
|
||||
|
||||
if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
|
||||
console.log('webrtc feature not detected. shutting down');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var snowflake = null;
|
||||
snowflake = null;
|
||||
|
||||
var query = Query.parse(location);
|
||||
query = Query.parse(location);
|
||||
|
||||
var debug = Params.getBool(query, 'debug', false);
|
||||
debug = Params.getBool(query, 'debug', false);
|
||||
|
||||
var silenceNotifications = Params.getBool(query, 'silent', false);
|
||||
silenceNotifications = Params.getBool(query, 'silent', false);
|
||||
|
||||
// Log to both console and UI if applicable.
|
||||
// Requires that the snowflake and UI objects are hooked up in order to
|
||||
// log to console.
|
||||
var log = function(msg) {
|
||||
// Log to both console and UI if applicable.
|
||||
// Requires that the snowflake and UI objects are hooked up in order to
|
||||
// log to console.
|
||||
log = function(msg) {
|
||||
console.log('Snowflake: ' + msg);
|
||||
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
||||
};
|
||||
};
|
||||
|
||||
var dbg = function(msg) {
|
||||
dbg = function(msg) {
|
||||
if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) {
|
||||
return log(msg);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
var init = function() {
|
||||
init = function() {
|
||||
var broker, config, ui;
|
||||
config = new Config;
|
||||
if ('off' !== query['ratelimit']) {
|
||||
|
@ -55,19 +59,21 @@ var init = function() {
|
|||
dbg('Contacting Broker at ' + broker.url);
|
||||
snowflake.setRelayAddr(config.relayAddr);
|
||||
return snowflake.beginWebRTC();
|
||||
};
|
||||
};
|
||||
|
||||
// Notification of closing tab with active proxy.
|
||||
window.onbeforeunload = function() {
|
||||
// Notification of closing tab with active proxy.
|
||||
window.onbeforeunload = function() {
|
||||
if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) {
|
||||
return Snowflake.MESSAGE.CONFIRMATION;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
window.onunload = function() {
|
||||
window.onunload = function() {
|
||||
snowflake.disable();
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
window.onload = init;
|
||||
window.onload = init;
|
||||
|
||||
}());
|
||||
|
|
|
@ -2,49 +2,50 @@
|
|||
Entry point.
|
||||
*/
|
||||
|
||||
var debug = false;
|
||||
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications;
|
||||
|
||||
var snowflake = null;
|
||||
;(function () {
|
||||
|
||||
var config = null;
|
||||
silenceNotifications = false;
|
||||
debug = false;
|
||||
snowflake = null;
|
||||
config = null;
|
||||
broker = null;
|
||||
ui = null;
|
||||
|
||||
var broker = null;
|
||||
|
||||
var ui = null;
|
||||
|
||||
// Log to both console and UI if applicable.
|
||||
// Requires that the snowflake and UI objects are hooked up in order to
|
||||
// log to console.
|
||||
var log = function(msg) {
|
||||
// Log to both console and UI if applicable.
|
||||
// Requires that the snowflake and UI objects are hooked up in order to
|
||||
// log to console.
|
||||
log = function(msg) {
|
||||
console.log('Snowflake: ' + msg);
|
||||
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
||||
};
|
||||
};
|
||||
|
||||
var dbg = function(msg) {
|
||||
dbg = function(msg) {
|
||||
if (debug) {
|
||||
return log(msg);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
if (!Util.featureDetect()) {
|
||||
if (!Util.featureDetect()) {
|
||||
chrome.runtime.onConnect.addListener(function(port) {
|
||||
return port.postMessage({
|
||||
missingFeature: true
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var init = function() {
|
||||
init = function() {
|
||||
config = new Config;
|
||||
ui = new WebExtUI();
|
||||
broker = new Broker(config.brokerUrl);
|
||||
snowflake = new Snowflake(config, ui, broker);
|
||||
log('== snowflake proxy ==');
|
||||
return ui.initToggle();
|
||||
};
|
||||
};
|
||||
|
||||
var update = function() {
|
||||
update = function() {
|
||||
if (!ui.enabled) {
|
||||
// Do not activate the proxy if any number of conditions are true.
|
||||
snowflake.disable();
|
||||
|
@ -56,19 +57,21 @@ var update = function() {
|
|||
log('Starting snowflake');
|
||||
snowflake.setRelayAddr(config.relayAddr);
|
||||
return snowflake.beginWebRTC();
|
||||
};
|
||||
};
|
||||
|
||||
// Notification of closing tab with active proxy.
|
||||
window.onbeforeunload = function() {
|
||||
// Notification of closing tab with active proxy.
|
||||
window.onbeforeunload = function() {
|
||||
if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) {
|
||||
return Snowflake.MESSAGE.CONFIRMATION;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
window.onunload = function() {
|
||||
window.onunload = function() {
|
||||
snowflake.disable();
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
window.onload = init;
|
||||
window.onload = init;
|
||||
|
||||
}());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue