From e433af26f8fbf6d689fc169ca5b3d144ac14c31b Mon Sep 17 00:00:00 2001 From: Serene Han Date: Thu, 14 Jan 2016 15:38:46 -0800 Subject: [PATCH] snowflake terminal turns green when connected --- .gitignore | 2 ++ README.md | 3 ++- proxy/snowflake.coffee | 32 ++++++++++++++++++-------------- proxy/snowflake.html | 6 +++--- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 0f9da9c..c87c52a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ client/client server/server snowflake.log proxy/test +proxy/build +ignore/ diff --git a/README.md b/README.md index b76efa9..7e8effd 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,8 @@ snowflake to use a default relay. Look for the offer in terminal C; copy and paste it into the browser. Copy and paste the answer generated in the browser back to terminal B. -At this point the tor client should bootstrap to 100%. +Once WebRTC successfully connects, the browser terminal should turn green. +Shortly after, the tor client should bootstrap to 100%. ### More diff --git a/proxy/snowflake.coffee b/proxy/snowflake.coffee index d040cbc..67dc02a 100644 --- a/proxy/snowflake.coffee +++ b/proxy/snowflake.coffee @@ -148,6 +148,12 @@ RATE_LIMIT_HISTORY = 5.0 DEFAULT_PORTS = http: 80 https: 443 + +# DOM elements. +$msglog = null +$send = null +$input = null + # Build an escaped URL string from unescaped components. Only scheme and host # are required. See RFC 3986, section 3. buildUrl = (scheme, host, port, path, params) -> @@ -243,10 +249,6 @@ config = { ] } -# DOM elements -$chatlog = null -$send = null -$input = null # TODO: Implement class Badge @@ -411,13 +413,14 @@ class ProxyPair channel.onopen = => log 'Data channel opened!' snowflake.state = MODE.WEBRTC_READY + $msglog.className = 'active'; # This is the point when the WebRTC datachannel is done, so the next step # is to establish websocket to the server. @connectRelay() channel.onclose = => log 'Data channel closed.' - @state = MODE.INIT; - $chatlog.className = '' + snowflake.state = MODE.INIT; + $msglog.className = '' channel.onerror = => log 'Data channel error!' channel.onmessage = @onClientToRelayMessage @@ -471,11 +474,12 @@ class ProxyPair relayIsReady: -> (null != @relay) && (WebSocket.OPEN == @relay.readyState) isClosed: (ws) -> undefined == ws || WebSocket.CLOSED == ws.readyState close: -> - @client.close() if !(isClosed @client) - @relay.close() if !(isClosed @relay) + @client.close() if @webrtcIsReady() + @relay.close() if @relayIsReady() + relay = null maybeCleanup: => - if @running && @isClosed @relay + if @running @running = false # TODO: Call external callback true @@ -518,9 +522,9 @@ welcome = -> log = (msg) -> console.log msg # Scroll to latest - if $chatlog - $chatlog.value += msg + '\n' - $chatlog.scrollTop = $chatlog.scrollHeight + if $msglog + $msglog.value += msg + '\n' + $msglog.scrollTop = $msglog.scrollHeight Interface = # Local input from keyboard into message window. @@ -564,8 +568,8 @@ Signalling = init = -> - $chatlog = document.getElementById('chatlog') - $chatlog.value = '' + $msglog = document.getElementById('msglog') + $msglog.value = '' $send = document.getElementById('send') $send.onclick = Interface.acceptInput diff --git a/proxy/snowflake.html b/proxy/snowflake.html index 55adc42..f1f5f90 100644 --- a/proxy/snowflake.html +++ b/proxy/snowflake.html @@ -31,8 +31,8 @@ width: 50%; min-width: 40em; padding: 0.5em; margin: auto; } - .active { background-color: #252; } - #chatlog { + .active { background-color: rgba(0,50,0,0.8); } + #msglog { display: block; width: 100%; min-height: 40em; @@ -67,7 +67,7 @@
-