mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 14:11:23 -04:00
Separate build per use
This commit is contained in:
parent
2d8a1690ba
commit
4d40f17487
6 changed files with 94 additions and 25 deletions
58
proxy/init-badge.coffee
Normal file
58
proxy/init-badge.coffee
Normal file
|
@ -0,0 +1,58 @@
|
|||
###
|
||||
Entry point.
|
||||
###
|
||||
|
||||
snowflake = null
|
||||
|
||||
query = Query.parse(location)
|
||||
debug = Params.getBool(query, 'debug', 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.
|
||||
log = (msg) ->
|
||||
console.log 'Snowflake: ' + msg
|
||||
snowflake?.ui.log msg
|
||||
|
||||
dbg = (msg) -> log msg if debug or (snowflake?.ui instanceof DebugUI)
|
||||
|
||||
init = () ->
|
||||
config = new Config
|
||||
|
||||
if 'off' != query['ratelimit']
|
||||
config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes)
|
||||
|
||||
ui = null
|
||||
if (document.getElementById('badge') != null)
|
||||
ui = new BadgeUI()
|
||||
else if (document.getElementById('status') != null)
|
||||
ui = new DebugUI()
|
||||
else
|
||||
ui = new UI()
|
||||
|
||||
broker = new Broker config.brokerUrl
|
||||
snowflake = new Snowflake config, ui, broker
|
||||
|
||||
log '== snowflake proxy =='
|
||||
if Util.snowflakeIsDisabled(config.cookieName)
|
||||
# Do not activate the proxy if any number of conditions are true.
|
||||
log 'Currently not active.'
|
||||
return
|
||||
|
||||
# Otherwise, begin setting up WebRTC and acting as a proxy.
|
||||
dbg 'Contacting Broker at ' + broker.url
|
||||
snowflake.setRelayAddr config.relayAddr
|
||||
snowflake.beginWebRTC()
|
||||
|
||||
# Notification of closing tab with active proxy.
|
||||
window.onbeforeunload = ->
|
||||
if !silenceNotifications && Snowflake.MODE.WEBRTC_READY == snowflake.state
|
||||
return Snowflake.MESSAGE.CONFIRMATION
|
||||
null
|
||||
|
||||
window.onunload = ->
|
||||
pair.close() for pair in snowflake.proxyPairs
|
||||
null
|
||||
|
||||
window.onload = init
|
Loading…
Add table
Add a link
Reference in a new issue