Snowflake proxy successfully reset and bootstrap a new client (#15)

This commit is contained in:
Serene Han 2016-01-22 12:22:09 -08:00
parent 133f657928
commit 77fbfe0e66
4 changed files with 33 additions and 25 deletions

View file

@ -19,7 +19,8 @@ class ProxyPair
constructor: (@clientAddr, @relayAddr, @rateLimit) ->
connectClient: =>
# Prepare a WebRTC PeerConnection and await for an SDP offer.
begin: ->
@pc = new PeerConnection config, {
optional: [
{ DtlsSrtpKeyAgreement: true }
@ -44,6 +45,16 @@ class ProxyPair
@prepareDataChannel channel
@client = channel
receiveWebRTCOffer: (offer) ->
console.assert 'offer' == offer.type
try
err = @pc.setRemoteDescription offer
catch e
log 'Invalid SDP message.'
return false
log 'SDP ' + offer.type + ' successfully received.'
true
prepareDataChannel: (channel) =>
channel.onopen = =>
log 'Data channel opened!'
@ -56,8 +67,9 @@ class ProxyPair
log 'Data channel closed.'
snowflake.state = MODE.INIT
$msglog.className = ''
channel.onerror = ->
log 'Data channel error!'
# Change this for multiplexing.
snowflake.reset()
channel.onerror = -> log 'Data channel error!'
channel.onmessage = @onClientToRelayMessage
# Assumes WebRTC datachannel is connected.