mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
parent
c8c5d56b73
commit
e295556254
7 changed files with 52 additions and 23 deletions
|
@ -35,7 +35,8 @@ task 'test', 'snowflake unit tests', ->
|
|||
# Simply concat all the files because we're not using node exports.
|
||||
jasmineFiles = FILES_ALL
|
||||
outFile = 'test/bundle.spec.coffee'
|
||||
exec 'cat ' + jasmineFiles.join(' ') + ' | cat > ' + outFile
|
||||
exec 'echo "TESTING = true" > ' + outFile
|
||||
exec 'cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile
|
||||
execSync 'coffee -cb ' + outFile
|
||||
spawn 'jasmine', ['test/bundle.spec.js'], {
|
||||
stdio: 'inherit'
|
||||
|
|
|
@ -11,14 +11,24 @@
|
|||
"lint": "cake lint",
|
||||
"build": "cake build",
|
||||
"clean": "cake clean",
|
||||
"modern": "modernizr -c modernizr-config.json -d static/"
|
||||
"modern": "modernizr -c modernizr-config.json -d static/",
|
||||
"prepublish": "npm run build",
|
||||
"start": "node build/snowflake.js"
|
||||
},
|
||||
"bin": {
|
||||
"snowflake": "build/snowflake.js"
|
||||
},
|
||||
"author": "Serene Han",
|
||||
"license": "BSD-3-Clause",
|
||||
"devDependencies": {
|
||||
"coffee-script": "^1.10.0",
|
||||
"coffeelint": "^1.15.0",
|
||||
"jasmine": "^2.4.1",
|
||||
"coffeelint": "^1.16.0",
|
||||
"jasmine": "^2.5.2",
|
||||
"modernizr": "^3.3.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"coffee-script": "^1.12.2",
|
||||
"wrtc": "^0.0.61",
|
||||
"ws": "^1.1.1",
|
||||
"xmlhttprequest": "^1.8.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,14 +69,14 @@ class ProxyPair
|
|||
channel.onopen = =>
|
||||
log 'WebRTC DataChannel opened!'
|
||||
snowflake.state = MODE.WEBRTC_READY
|
||||
snowflake.ui.setActive true
|
||||
snowflake.ui?.setActive true
|
||||
# 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 'WebRTC DataChannel closed.'
|
||||
snowflake.ui.setStatus 'disconnected by webrtc.'
|
||||
snowflake.ui.setActive false
|
||||
snowflake.ui?.setStatus 'disconnected by webrtc.'
|
||||
snowflake.ui?.setActive false
|
||||
snowflake.state = MODE.INIT
|
||||
@flush()
|
||||
@close()
|
||||
|
@ -95,11 +95,11 @@ class ProxyPair
|
|||
clearTimeout @timer
|
||||
@timer = 0
|
||||
log @relay.label + ' connected!'
|
||||
snowflake.ui.setStatus 'connected'
|
||||
snowflake.ui?.setStatus 'connected'
|
||||
@relay.onclose = =>
|
||||
log @relay.label + ' closed.'
|
||||
snowflake.ui.setStatus 'disconnected.'
|
||||
snowflake.ui.setActive false
|
||||
snowflake.ui?.setStatus 'disconnected.'
|
||||
snowflake.ui?.setActive false
|
||||
snowflake.state = MODE.INIT
|
||||
@flush()
|
||||
@close()
|
||||
|
|
|
@ -1,11 +1,27 @@
|
|||
###
|
||||
WebrTC shims for multiple browsers.
|
||||
WebRTC shims for multiple browsers.
|
||||
###
|
||||
|
||||
if typeof module isnt 'undefined' and module.exports
|
||||
if module?.exports
|
||||
window = {}
|
||||
location = ''
|
||||
|
||||
if not TESTING? or not TESTING
|
||||
webrtc = require 'wrtc'
|
||||
|
||||
PeerConnection = webrtc.RTCPeerConnection
|
||||
IceCandidate = webrtc.RTCIceCandidate
|
||||
SessionDescription = webrtc.RTCSessionDescription
|
||||
|
||||
WebSocket = require 'ws'
|
||||
{ XMLHttpRequest } = require 'xmlhttprequest'
|
||||
|
||||
process.nextTick () -> init true
|
||||
|
||||
else
|
||||
window = this
|
||||
location = window.location.search.substr(1)
|
||||
|
||||
prop = Modernizr.prefixed 'RTCPeerConnection', window, false
|
||||
if not prop
|
||||
console.log 'webrtc feature not detected. shutting down'
|
||||
|
@ -18,4 +34,5 @@ else
|
|||
SessionDescription = window.RTCSessionDescription ||
|
||||
window.mozRTCSessionDescription
|
||||
|
||||
location = if window.location then window.location.search.substr(1) else ""
|
||||
WebSocket = window.WebSocket
|
||||
XMLHttpRequest = window.XMLHttpRequest
|
||||
|
|
|
@ -13,7 +13,6 @@ DEFAULT_RELAY =
|
|||
port: 9902
|
||||
COPY_PASTE_ENABLED = false
|
||||
|
||||
DEBUG = false
|
||||
silenceNotifications = false
|
||||
query = Query.parse(location)
|
||||
DEBUG = Params.getBool(query, 'debug', false)
|
||||
|
@ -88,7 +87,8 @@ class Snowflake
|
|||
pollBroker: ->
|
||||
# Temporary countdown. TODO: Simplify
|
||||
countdown = (msg, sec) =>
|
||||
@ui.setStatus msg + ' (Polling in ' + sec + ' seconds...)'
|
||||
dbg msg
|
||||
@ui?.setStatus msg + ' (Polling in ' + sec + ' seconds...)'
|
||||
sec--
|
||||
if sec >= 0
|
||||
setTimeout((-> countdown(msg, sec)), 1000)
|
||||
|
@ -103,7 +103,7 @@ class Snowflake
|
|||
return
|
||||
msg = 'polling for client... '
|
||||
msg += '[retries: ' + @retries + ']' if @retries > 0
|
||||
@ui.setStatus msg
|
||||
@ui?.setStatus msg
|
||||
recv = @broker.getClientOffer pair.id
|
||||
recv.then (desc) =>
|
||||
@receiveOffer pair, desc
|
||||
|
@ -199,12 +199,12 @@ Signalling =
|
|||
# Log to both console and UI if applicable.
|
||||
log = (msg) ->
|
||||
console.log 'Snowflake: ' + msg
|
||||
snowflake.ui.log msg
|
||||
snowflake.ui?.log msg
|
||||
|
||||
dbg = (msg) -> log msg if true == snowflake.ui.debug
|
||||
dbg = (msg) -> log msg if DEBUG or snowflake.ui?.debug
|
||||
|
||||
init = ->
|
||||
ui = new UI()
|
||||
init = (isNode) ->
|
||||
ui = if isNode then null else new UI()
|
||||
silenceNotifications = Params.getBool(query, 'silent', false)
|
||||
brokerUrl = Params.getString(query, 'broker', DEFAULT_BROKER)
|
||||
broker = new Broker brokerUrl
|
||||
|
@ -229,4 +229,4 @@ window.onunload = ->
|
|||
pair.close() for pair in snowflake.proxyPairs
|
||||
null
|
||||
|
||||
window.onload = init
|
||||
window.onload = init.bind null, false
|
||||
|
|
|
@ -3,7 +3,7 @@ All of Snowflake's DOM manipulation and inputs.
|
|||
###
|
||||
|
||||
class UI
|
||||
debug = false # True when there's no badge
|
||||
debug: false # True when there's no badge
|
||||
|
||||
# DOM elements references.
|
||||
$msglog: null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue